-
Notifications
You must be signed in to change notification settings - Fork 36
/
App.tsx
142 lines (132 loc) · 3.53 KB
/
App.tsx
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
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
import * as React from 'react';
import {
StyleSheet,
View,
Text,
SafeAreaView,
Button,
Platform,
Dimensions,
} from 'react-native';
import BubbleSelect, { Bubble, BubbleNode } from 'react-native-bubble-select';
import randomCity, { randomCities } from './randomCity';
const { width, height } = Dimensions.get('window');
export default function App() {
const [cities, setCities] = React.useState<any[]>([]);
const [force, setForce] = React.useState(false);
const [selectedCites, setSelectedCities] = React.useState<BubbleNode[]>([]);
const [removedCities, setRemovedCities] = React.useState<BubbleNode[]>([]);
React.useEffect(() => {
if (force) {
setCities(randomCities());
}
}, [force]);
React.useEffect(() => {
if (Platform.OS === 'ios') {
setForce(true);
} else {
setCities(randomCities());
}
}, []);
const addCity = () => {
setCities([...cities, randomCity()]);
};
const handleSelect = (bubble: BubbleNode) => {
setSelectedCities([...selectedCites, bubble]);
};
const handleDeselect = (bubble: BubbleNode) => {
setSelectedCities(selectedCites.filter(({ id }) => id !== bubble.id));
};
const handleRemove = (bubble: BubbleNode) => {
console.log(bubble);
setRemovedCities([...removedCities, bubble]);
};
return (
<SafeAreaView style={styles.safeArea}>
<View style={styles.container}>
<View style={styles.header}>
<Text style={styles.title}>Discover New Cities</Text>
<Text style={styles.message}>
Tap on the places you love, hold on the places you don't.
</Text>
{selectedCites.length > 0 ? (
<Text style={styles.selectedCity}>
Selected: {selectedCites.map(city => city.text).join(', ')}
</Text>
) : null}
{removedCities.length > 0 ? (
<Text style={styles.selectedCity}>
Removed: {removedCities.map(city => city.text).join(', ')}
</Text>
) : null}
</View>
<BubbleSelect
onSelect={handleSelect}
onDeselect={handleDeselect}
onRemove={handleRemove}
width={width}
height={height}
fontName={Platform.select({
ios: 'SinhalaSangamMN-Bold',
android: 'sans-serif-medium',
})}
fontSize={16}
bubbleSize={30}
>
{cities.map(city => (
<Bubble
key={city.id}
id={city.id}
text={city.text}
color={city.color}
selectedColor={city.selectedColor}
selectedScale={city.selectedScale}
gradient={city.gradient}
/>
))}
</BubbleSelect>
<View style={styles.footer}>
<Button title="Add" onPress={addCity} />
</View>
</View>
</SafeAreaView>
);
}
const styles = StyleSheet.create({
safeArea: {
flex: 1,
},
container: {
flex: 1,
backgroundColor: 'white',
},
header: {
flexDirection: 'column',
alignItems: 'center',
justifyContent: 'space-between',
paddingTop: 45,
},
title: {
fontSize: 30,
fontWeight: 'bold',
textAlign: 'center',
marginBottom: 10,
},
footer: {
flexDirection: 'row',
width: '100%',
paddingLeft: 50,
paddingRight: 50,
marginBottom: Platform.select({
android: 50,
}),
alignItems: 'center',
},
message: {},
selectedCity: {
marginTop: 15,
fontSize: 12,
maxWidth: '80%',
textAlign: 'center',
},
});