-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathPlaylist.js
70 lines (61 loc) · 2.38 KB
/
Playlist.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
61
62
63
64
65
66
67
68
69
70
import React, { Component } from 'react';
import { Text, View, ImageBackground, List, ListItem, FlatList, TouchableOpacity, Button } from 'react-native';
import styles from './Styles';
import { observer } from "mobx-react";
import { observable } from "mobx";
import IconEntypo from 'react-native-vector-icons/Entypo';
const state = observable({
tracks:[],
playingIndex:0,
});
function Item({ id, title, album, callBack$Playlist }) {
let pIndex = state.playingIndex;
return (
<TouchableOpacity
onPress={() => {callBack$Playlist(id); state.playingIndex = id}}
>
<View style={{ flexDirection: 'row', margin:2 }}>
{ pIndex === id
?<IconEntypo name={'controller-play'} size={30} color="#fcfaff" style={{margin: 10}}/>:
<IconEntypo name={'music'} size={30} color="#fcfaff" style={{margin: 10}}/>
}
<Text style={{ fontSize: 22, marginLeft:5, color:'#e6e5ff', fontFamily:'sans-serif-medium' }}>{title?title:'Unavailable'}
{"\n"}
<Text style={{ fontSize:20, marginLeft:5, color:'#575462', fontFamily:'Roboto' }} numberOfLines={1}>{album?album:'unavailable'}</Text>
</Text>
</View>
</TouchableOpacity>
);
}
class Playlist extends Component {
componentDidMount(){
const { tracks } = this.props.record;
state.tracks = tracks;
}
componentWillReceiveProps(nextProps){
const { tracks } = nextProps.record;
const { id } = nextProps.pIndex;
if(JSON.stringify(state.tracks)!==JSON.stringify(tracks)){
state.tracks = tracks;
}
if(state.playingIndex!==id){
state.playingIndex = id;
}
}
render(){
const { tracks, playingIndex } = state;
const { navigation, callBack$Playlist, pIndex } = this.props;
return(
<View style={{flex: 1, backgroundColor: '#161b27'}}>
<FlatList
data={ tracks }
renderItem={({item, index}) => {
return <Item key={index} id={index} title={item.title} album={item.album} callBack$Playlist={callBack$Playlist}/>
}}
keyExtractor={item => item.id}
/>
</View>
);
}
}
export default observer(Playlist);