-
Notifications
You must be signed in to change notification settings - Fork 41
/
Grid.js
120 lines (115 loc) · 3.39 KB
/
Grid.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
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
import React, {useContext, useState} from 'react';
import {Platform, StyleSheet, ScrollView, View, TouchableHighlight, Text} from 'react-native';
import {NavigationContext} from 'navigation-react';
import {SharedElement, NavigationBar, SearchBar} from 'navigation-react-native';
const Container = (props) => (
Platform.OS === 'ios' ? <ScrollView {...props}/> : <View {...props} />
);
const SearchResults = ({colors, text}) => {
const {stateNavigator} = useContext(NavigationContext);
return (
<ScrollView
style={styles.scene}
contentInsetAdjustmentBehavior="automatic">
<View>
{colors
.filter(color => (
!text || color.indexOf(text.toLowerCase()) !== -1
))
.map(color => (
<TouchableHighlight
key={color}
style={styles.result}
underlayColor="white"
onPress={() => {
stateNavigator.navigate('detail', {color, search: true});
}}>
<>
<View style={{backgroundColor: color, width: 100, height: 50}} />
<Text style={{fontSize: 25, marginLeft: 10}}>{color}</Text>
</>
</TouchableHighlight>
))}
</View>
</ScrollView>
)
}
const Grid = ({colors}) => {
const [text, setText] = useState('');
const {stateNavigator} = useContext(NavigationContext);
return (
<Container
style={styles.scene}
collapsable={false}
contentInsetAdjustmentBehavior="automatic">
<NavigationBar
largeTitle={true}
title="Colors"
navigationImage={require('./search.png')}
barTintColor={Platform.OS === 'android' ? '#fff' : null}>
<SearchBar
toolbar
text={text}
autoCapitalize="none"
obscureBackground={false}
barTintColor={Platform.OS === 'android' ? '#dcdcdc' : null}
placeholder={(toolbar) => toolbar ? 'Search' : ''}
onChangeText={text => setText(text)}>
<SearchResults colors={colors} text={text} />
</SearchBar>
</NavigationBar>
<ScrollView
style={styles.scene}
contentInsetAdjustmentBehavior="automatic">
<View style={styles.colors}>
{colors.map(color => (
<TouchableHighlight
key={color}
style={styles.color}
underlayColor="transparent"
onPress={() => {
stateNavigator.navigate('detail', {color});
}}>
<SharedElement name={color} style={{flex: 1}} duration={250}>
<View style={{backgroundColor: color, flex: 1}} />
<Text style={styles.text}>{color}</Text>
</SharedElement>
</TouchableHighlight>
))}
</View>
</ScrollView>
</Container>
);
};
export default Grid;
const styles = StyleSheet.create({
scene: {
backgroundColor: '#fff',
flex: 1,
},
colors: {
flexDirection: 'row',
flexWrap: 'wrap',
justifyContent: 'center',
marginTop: 10,
},
color: {
width: 100,
height: 150,
marginLeft: 10,
marginRight: 10,
marginBottom: 20,
},
text: {
fontSize: 25,
textAlign: 'center',
fontWeight: 'bold',
backgroundColor: 'white'
},
result: {
flex: 1,
flexDirection: 'row',
margin: 10,
alignItems: 'center'
}
});