-
Notifications
You must be signed in to change notification settings - Fork 8
/
Copy pathTrackList.js
60 lines (50 loc) · 1.32 KB
/
TrackList.js
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
53
54
55
56
57
58
59
60
/* @flow */
import React, { Component, Fragment } from 'react';
import { Keyboard, FlatList, StyleSheet } from 'react-native';
import type { TrackType } from './api/types';
import TrackItem from './TrackItem';
import Player from './Player';
type Props = {
tracks: Array<TrackType>,
};
type State = {
selectedTrack: ?TrackType,
};
class TrackList extends Component<Props, State> {
state = {
selectedTrack: null,
};
onTrackSelected = (track: TrackType) => {
this.setState({ selectedTrack: track }, () => Keyboard.dismiss());
};
render() {
const { tracks } = this.props;
const { selectedTrack } = this.state;
return (
<Fragment>
<FlatList
keyExtractor={item => item.id}
data={tracks}
keyboardShouldPersistTaps="always"
extraData={this.state.selectedTrack}
renderItem={({ item }) => (
<TrackItem
track={item}
selectedId={selectedTrack ? selectedTrack.id : null}
onTrackSelected={this.onTrackSelected}
/>
)}
contentContainerStyle={styles.listContainer}
/>
<Player track={selectedTrack} />
</Fragment>
);
}
}
const styles = StyleSheet.create({
listContainer: {
paddingTop: 8,
paddingBottom: 16,
},
});
export default TrackList;