forked from jesster2k10/react-native-bubble-select
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathApp.tsx
123 lines (114 loc) · 3.13 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
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(randomCities());
const [selectedCites, setSelectedCities] = React.useState<BubbleNode[]>([]);
const [removedCities, setRemovedCities] = React.useState<BubbleNode[]>([]);
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) => {
setRemovedCities([...removedCities, bubble]);
};
const handleReset = () => {
setCities([]);
};
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',
})}
fontSize={16}
>
{cities.map(city => (
<Bubble
key={city.id}
id={city.id}
text={city.text}
color={city.color}
selectedColor={city.selectedColor}
selectedScale={city.selectedScale}
/>
))}
</BubbleSelect>
<View style={styles.footer}>
<Button title="Reset" onPress={handleReset} />
<Button title="Add" onPress={addCity} />
</View>
</View>
</SafeAreaView>
);
}
const styles = StyleSheet.create({
safeArea: {
flex: 1,
},
container: {
flex: 1,
},
header: {
flexDirection: 'column',
alignItems: 'center',
justifyContent: 'space-between',
paddingTop: 45,
},
title: {
fontSize: 30,
fontWeight: 'bold',
textAlign: 'center',
marginBottom: 10,
},
footer: {
flexDirection: 'row',
justifyContent: 'space-between',
paddingLeft: 50,
paddingRight: 50,
},
message: {},
selectedCity: {
marginTop: 15,
fontSize: 12,
maxWidth: '80%',
textAlign: 'center',
},
});