-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathApp.js
More file actions
52 lines (41 loc) · 1.33 KB
/
Copy pathApp.js
File metadata and controls
52 lines (41 loc) · 1.33 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
import { Text, SafeAreaView, StyleSheet, FlatList, View } from 'react-native';
import React, {useState} from 'react';
import music_data from "./src/music-data.json";
import SongCard from './src/components/SongCard/SongCard';
import SearchBar from './src/components/SearchBar/SearchBar';
function App() {
const renderSong = ({item}) => <SongCard song={item}>{item.title}</SongCard>
const renderSeperator = () => <View style={styles.seperator}/>;
const [list, setList] = useState(music_data);
const handleSearch = text => {
const filteredList = music_data.filter(song => {
const searchedText = text.toLowerCase();
const currentTitle = song.title.toLowerCase();
return currentTitle.indexOf(searchedText) > -1;
});
setList(filteredList);
};
return (
<SafeAreaView style={styles.container}>
<View style={styles.container}>
<SearchBar onSearch={handleSearch}/>
<FlatList
keyExtractor={(item) => item.id}
data={music_data}
renderItem={renderSong}
ItemSeperatorComponent={renderSeperator}
/>
</View>
</SafeAreaView>
);
}
export default App;
const styles = StyleSheet.create({
container: {
flex: 1
},
seperator: {
borderWidth:1,
borderColor: "#e0e0e0",
}
});