-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCreatePinView.js
More file actions
67 lines (56 loc) · 1.72 KB
/
Copy pathCreatePinView.js
File metadata and controls
67 lines (56 loc) · 1.72 KB
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
import React, { useState } from 'react';
import PinPlacementOverlay from './PinPlacementOverlay';
import PinFormOverlay from './PinFormOverlay';
const CreatePinView = (props) => {
const {
shouldShow,
isDraggingMap,
currentRegion,
onConfirmLocation,
onRepositionPin,
onPressCancelButton,
onPressConfirmButton
} = props;
const region = currentRegion ?? { latitude: 0, longitude: 0 };
// toggle overlay components for positioning new pin
const [isLocationConfirmed, setIsLocationConfirmed] = useState(false);
const submitPinForm = (pinForm) => {
setIsLocationConfirmed(false);
onPressConfirmButton(pinForm);
}
// hide pin form overlay and show pin placement overlay
const repositionPin = () => {
setIsLocationConfirmed(false);
onRepositionPin();
}
// hide pin placement overlay and show pin form overlay
const confirmLocation = () => {
setIsLocationConfirmed(true);
onConfirmLocation();
}
const shouldShowPlacementOverlay = () => {
return shouldShow && !isLocationConfirmed;
}
const shouldShowFormOverlay = () => {
return shouldShow && isLocationConfirmed;
}
return (
<>
<PinPlacementOverlay
shouldShow={shouldShowPlacementOverlay()}
isDraggingMap={isDraggingMap}
onConfirmLocation={() => confirmLocation()}
onPressCancelButton={() => onPressCancelButton()}
/>
<PinFormOverlay
shouldShowPin={shouldShow}
shouldShowOverlays={shouldShowFormOverlay()}
isDraggingMap={isDraggingMap}
currentRegion={region}
onRepositionPin={() => repositionPin()}
onPressConfirmButton={(pinForm) => submitPinForm(pinForm)}
/>
</>
);
}
export default CreatePinView;