Skip to content

Commit b54b8cc

Browse files
committed
mobile components
1 parent b73e3a4 commit b54b8cc

14 files changed

+284
-46
lines changed
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
import React from 'react';
2+
3+
import {
4+
StyleSheet,
5+
View,
6+
TextInput,
7+
ListView,
8+
Text
9+
} from 'react-native';
10+
11+
import MobileSearchBox from './MobileSearchBox';
12+
13+
const styles = StyleSheet.create({
14+
row: {
15+
flexDirection: 'row',
16+
justifyContent: 'center',
17+
padding: 10
18+
},
19+
text: {
20+
flex: 1,
21+
}
22+
});
23+
24+
const ColorListItem = ({result})=>{
25+
return (
26+
<View style={[styles.row, {backgroundColor: result.hex}]}>
27+
<Text style={styles.text}>{result.name}</Text>
28+
</View>
29+
)
30+
};
31+
const ColorSearchBox = MobileSearchBox(ColorListItem);
32+
export default ColorSearchBox;

color-mobile/MobileSearchBox.js

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
import React from 'react';
2+
3+
import {
4+
StyleSheet,
5+
View,
6+
} from 'react-native';
7+
8+
9+
const styles = StyleSheet.create({
10+
container: {
11+
flex: 1,
12+
backgroundColor: '#eeeeee',
13+
marginTop: 25
14+
}
15+
});
16+
17+
import MobileSearchInput from './MobileSearchInput';
18+
import MobileSearchResults from './MobileSearchResults';
19+
20+
import SearchBox from './SearchBox'
21+
22+
const MobileSearchFrame = ({children}) => {
23+
return (
24+
<View style={styles.container}>
25+
{children}
26+
</View>
27+
);
28+
};
29+
30+
const MobileSearchBox = ListItem => SearchBox(MobileSearchFrame, MobileSearchInput, MobileSearchResults(ListItem));
31+
32+
export default MobileSearchBox

color-mobile/MobileSearchInput.js

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
import React from 'react';
2+
import {TextInput} from 'react-native';
3+
4+
const MobileSearchInput = ({query, onSubmit, onQueryUpdate}) => {
5+
6+
return (
7+
<TextInput
8+
style={{height: 40, paddingLeft: 8, borderColor: 'gray', borderWidth: 1}}
9+
onChangeText={(text) => onQueryUpdate(text)}
10+
value={query}
11+
returnKeyType={'search'}
12+
onSubmitEditing={() => onSubmit()}
13+
/>
14+
);
15+
};
16+
17+
MobileSearchInput.propTypes = {
18+
query: React.PropTypes.string.isRequired,
19+
onSubmit: React.PropTypes.func.isRequired,
20+
onQueryUpdate: React.PropTypes.func.isRequired
21+
};
22+
23+
export default MobileSearchInput;
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
import React, {Component} from 'react';
2+
import {
3+
StyleSheet,
4+
View,
5+
TextInput,
6+
ListView,
7+
Text
8+
} from 'react-native';
9+
const styles = StyleSheet.create({
10+
separator: {
11+
flex: 1,
12+
height: 1,
13+
backgroundColor: '#8E8E8E',
14+
}
15+
});
16+
const dataSource = new ListView.DataSource({rowHasChanged: (r1, r2) => r1.name !== r2.name});
17+
const MobileSearchResults = ListItem => {
18+
return class extends Component {
19+
// constructor(props) {
20+
// super(props);
21+
// this.dataSource = new ListView.DataSource({rowHasChanged: (r1, r2) => r1.name !== r2.name});
22+
// }
23+
24+
static propTypes = {
25+
results: React.PropTypes.array.isRequired
26+
};
27+
28+
renderRow = (rowData, sectionId, rowID) => {
29+
return (
30+
<ListItem result={rowData}/>
31+
);
32+
};
33+
34+
render() {
35+
return (
36+
<ListView enableEmptySections={true}
37+
dataSource={ dataSource.cloneWithRows(this.props.results)}
38+
renderRow={this.renderRow}
39+
renderSeparator={(sectionId, rowId) => <View key={rowId} style={styles.separator}/>}
40+
/>
41+
);
42+
}
43+
};
44+
};
45+
46+
export default MobileSearchResults;

color-mobile/SearchBox.js

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
import React, {Component} from 'react';
2+
3+
import {observer} from 'mobx-react';
4+
5+
const SearchBox = (SearchFrame, SearchInput, SearchResults) => {
6+
return observer(class extends Component {
7+
static propTypes = {
8+
searchStore: React.PropTypes.object.isRequired
9+
};
10+
11+
render() {
12+
return (
13+
<SearchFrame>
14+
<SearchInput query={this.props.searchStore.query}
15+
onQueryUpdate={value => this.props.searchStore.updateQuery(value)}
16+
onSubmit={() => this.props.searchStore.search()}
17+
/>
18+
<SearchResults results={this.props.searchStore.results.slice()}/>
19+
</SearchFrame>
20+
);
21+
}
22+
});
23+
};
24+
25+
26+
export default SearchBox

color-mobile/__tests__/SearchView.js

Lines changed: 0 additions & 36 deletions
This file was deleted.

color-mobile/colors.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import {extendObservable, runInAction} from 'mobx';
2-
import crayola from './resources/crayola.json'
2+
import crayola from './crayola.json'
33

44
export default class Colors {
55
constructor() {

color-mobile/index.ios.js

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,17 +6,17 @@
66

77
import React, {Component} from 'react';
88
import {AppRegistry} from 'react-native';
9-
import SearchView from './SearchView'
109

1110
import Colors from './colors';
12-
const colors = new Colors();
1311

14-
export default class SearchBoxMobile extends Component {
12+
import ColorMobileSearchBox from './ColorMobileSearchBox';
13+
14+
export default class App extends Component {
1515

1616
render() {
1717
return (
18-
<SearchView colors={colors}/>
18+
<ColorMobileSearchBox searchStore={new Colors()}/>
1919
);
2020
}
2121
}
22-
AppRegistry.registerComponent('SearchBoxMobile', () => SearchBoxMobile);
22+
AppRegistry.registerComponent('SearchBoxMobile', () => App);

common/MobileSearchBox.js

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
import React from 'react';
2+
3+
import {
4+
StyleSheet,
5+
View,
6+
} from 'react-native';
7+
8+
9+
const styles = StyleSheet.create({
10+
container: {
11+
flex: 1,
12+
backgroundColor: '#eeeeee',
13+
marginTop: 25
14+
}
15+
});
16+
17+
import MobileSearchInput from './MobileSearchInput';
18+
import MobileSearchResults from './MobileSearchResults';
19+
20+
import SearchBox from './SearchBox'
21+
22+
const MobileSearchFrame = ({children}) => {
23+
return (
24+
<View style={styles.container}>
25+
{children}
26+
</View>
27+
);
28+
};
29+
30+
const MobileSearchBox = ListItem => SearchBox(MobileSearchFrame, MobileSearchInput, MobileSearchResults(ListItem));
31+
32+
export default MobileSearchBox

0 commit comments

Comments
 (0)