This repository has been archived by the owner on May 8, 2020. It is now read-only.
-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
status-list.js
78 lines (66 loc) · 1.99 KB
/
status-list.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
71
72
73
74
75
76
77
78
import React from 'react'
import ReactNative, {
View,
ListView,
RecyclerViewBackedScrollView
} from 'react-native-macos'
import * as actions from "../actions"
import { connect } from "react-redux"
import { bindActionCreators } from "redux"
import Status from "./status"
import StatusStreamReader from "../utilities/status-stream-reader"
class StatusListView extends React.Component {
constructor(props) {
super(props)
const ds = new ListView.DataSource({
rowHasChanged: (r1, r2) => r1 !== r2
})
this.state = {
dataSource: ds.cloneWithRows(props.statuses),
}
}
componentWillReceiveProps(newProps) {
this.setState({
dataSource: this.state.dataSource.cloneWithRows(newProps.statuses)
})
}
_renderSeparator(sectionID: number, rowID: number, adjacentRowHighlighted: bool) {
return (
<View
key={`${sectionID}-${rowID}`}
style={{
height: adjacentRowHighlighted ? 4 : 1,
backgroundColor: '#d6d7da'
}}
/>
);
}
render() {
return <ListView
renderScrollComponent={props => <RecyclerViewBackedScrollView {...props} />}
renderSeparator={this._renderSeparator}
enableEmptySections={true}
dataSource={this.state.dataSource}
renderRow={(rowData) => <Status status={rowData} {...this.props} />}
/>
}
}
const bind = (thing, stateFunc) => {
return connect(
stateFunc,
(dispatch) => ({ actions: bindActionCreators(actions, dispatch) })
)(thing)
}
const UserTimelineListView = bind(
class UserTimelineListView extends StatusListView {},
(state) => ({ statuses: state.statuses.home })
)
const LocalTimelineListView = bind(
class LocalTimelineListView extends StatusListView {},
(state) => ({ statuses: state.statuses.local })
)
const FederatedTimelineListView = bind(
class FederatedTimelineListView extends StatusListView {},
(state) => ({ statuses: state.statuses.federated })
)
export { UserTimelineListView, LocalTimelineListView, FederatedTimelineListView }