-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.android.js
More file actions
98 lines (85 loc) · 2.13 KB
/
Copy pathindex.android.js
File metadata and controls
98 lines (85 loc) · 2.13 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
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
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
'use strict';
import React, {
AppRegistry,
Component,
StyleSheet,
Text,
TextInput,
ListView,
View
} from 'react-native';
import { createStore, combineReducers } from 'redux';
import { Provider, connect } from 'react-redux'
const FILTER_UPDATE = 'FILTER_UPDATE';
const mapDispatchToProps = (dispatch) => {
return {
onFilterChange: (filter) => {
dispatch(appUpdate({}, {filter, type: FILTER_UPDATE}))
}
}
}
function appUpdate(state = {filter: ''}, action) {
switch (action.type) {
case FILTER_UPDATE:
return {filter: action.filter, type: action.type};
default:
return state;
}
}
let reducer = combineReducers({appUpdate});
let store = createStore(reducer);
const mapStateToProps = (state) => {
return {
filter: state.appUpdate.filter
}
}
class Pwidget extends Component {
render() {
return (
<Provider store={store}>
<AConnectedWidget filter={store.getState().filter}/>
</Provider>
);
}
}
connect(
mapStateToProps,
mapDispatchToProps
)(Pwidget);
class Awidget extends Component {
render() {
let { filter } = store.getState().appUpdate;
let filteredResults = this.filterResults_(filter);
let renderRow = (row) => { return <Text>{row}</Text> };
let ds = new ListView.DataSource({rowHasChanged: (r1, r2) => r1 !== r2});
let dataSource = ds.cloneWithRows(filteredResults);
return (
<View>
<Text> input your search </Text>
<TextInput onChangeText={this.onFilterChange_} />
<Text> Here are the results: </Text>
<ListView dataSource={dataSource}
renderRow={renderRow}/>
</View>
);
}
onFilterChange_(filter) {
store.dispatch(appUpdate({}, {filter, type: FILTER_UPDATE}));
}
filterResults_(filter) {
let result = this.data();
if(filter) {
return result.filter(x => x.contains(filter));
} else {
return result;
}
}
data() {
return ['a', 'b', 'bar', 'baz', 'foo', 'waldo', 'fred', 'quux', 'x', 'y']
}
}
let AConnectedWidget = connect(
mapStateToProps,
mapDispatchToProps
)(Awidget);
AppRegistry.registerComponent('awidget', () => Pwidget);