-
Notifications
You must be signed in to change notification settings - Fork 16
/
FavoritesListScreen.js
66 lines (52 loc) · 1.45 KB
/
FavoritesListScreen.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
'use strict';
var AlbumsRow = require('./AlbumsRow');
var AlbumDetailScreen = require('./AlbumDetailScreen');
var FavoritesStore = require('./FavoritesStore');
var React = require('react');
import {
ListView
} from 'react-native';
var FavoritesListScreen = React.createClass({
getInitialState() {
var dataSource = new ListView.DataSource({rowHasChanged: (r1, r2) => r1 !== r2});
return {
dataSource: dataSource.cloneWithRows(FavoritesStore.getAll())
};
},
componentDidMount() {
FavoritesStore.on(FavoritesStore.CHANGE_EVENT, this.onFavoritesChange);
FavoritesStore.loadPersistedFavorites();
},
componentWillUnmount() {
FavoritesStore.removeListener(FavoritesStore.CHANGE_EVENT, this.onFavoritesChange);
},
onFavoritesChange() {
this.setState({
dataSource: this.state.dataSource.cloneWithRows(FavoritesStore.getAll())
});
},
onRowPress(rowID) {
var album = FavoritesStore.getAll()[rowID];
this.props.navigator.push({
title: album.collectionName,
component: AlbumDetailScreen,
passProps: {album: album}
});
},
renderRow(rowData, sectionID, rowID) {
return (
<AlbumsRow
onPress={() => this.onRowPress(rowID)}
rowData={rowData} />
);
},
render() {
return (
<ListView
enableEmptySections={true}
dataSource={this.state.dataSource}
renderRow={this.renderRow} />
);
}
});
module.exports = FavoritesListScreen;