-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathApp.tsx
124 lines (115 loc) · 2.72 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
import React, { useState } from 'react'
import { StyleSheet, Text, View, Button} from 'react-native'
import MapView from 'react-native-maps'
import { Map, Modals, Panel, Input, List } from './components'
import { SafeAreaView } from 'react-native-safe-area-context'
type point = {
latitude: number
longitude: number
}
export type inputPoints = {
coordinate: point,
name: string
}[]
interface StateApp {
inputPoints: inputPoints
namePoint: string
tempPoint: point
modal: boolean
filter: string
visibilityPoints: boolean
}
const DEFAULT_POINT: point = {
latitude: 0,
longitude: 0
}
export default function App() {
const [points,setPoints]= useState<StateApp['inputPoints']>([])
const [temPoints,setTempPoints]= useState<StateApp['tempPoint']>(DEFAULT_POINT)
const [namePoint,setNamePoint]= useState<StateApp['namePoint']>("")
const [filterVisibility,setFilterVisibility]= useState<StateApp['filter']>("") //new_point or all_point
const [toggleModal,setToggleModal]= useState<StateApp['modal']>(false)
const [visibilityPoints,setVisibilityPoints]= useState<StateApp['visibilityPoints']>(true)
function handleLongPress(point: any) {
setFilterVisibility("new_point")
setTempPoints(point.coordinate)
setToggleModal(true)
}
const handleSubmit = () => {
const newPoints = [...points, {coordinate: temPoints, name: namePoint}]
setPoints(newPoints)
setToggleModal(false)
}
const handleList = () => {
setFilterVisibility("all_point")
setToggleModal(true)
}
const handClose = () => {
setToggleModal(false)
}
const handleShowPoints = () => {
setVisibilityPoints(!visibilityPoints)
}
return (
<SafeAreaView
edges={['top']}
style={styles.containerApp}
>
<View style={styles.container}>
<Map
onLongPress={handleLongPress}
points={points}
showPoints={visibilityPoints}
/>
<Panel
titleLeft='List'
onLeftPress={handleList}
titleRight="Show / Hide"
onRightPress={handleShowPoints}
/>
<Modals
visibility={toggleModal}
>
{filterVisibility === "new_point" ?
<View style={styles.form}>
<Input
title="Name"
placeholder="Write name point"
onChangeText={(name) => setNamePoint(name)}
style={styles.input}
/>
<Button
title="Add"
onPress={handleSubmit}
/>
</View>
:
<List
points={points}
handleClose={handClose}
/>
}
</Modals>
</View>
</SafeAreaView>
)
}
const styles = StyleSheet.create({
containerApp:{
flex: 1,
backgroundColor: '#fff',
},
container: {
flex: 1,
backgroundColor: '#fff',
// alignItems: 'center',
},
input:{
backgroundColor: "#cccc",
flex: 1,
padding: 5,
},
form:{
padding: 20,
}
})