Repository navigation
Expand file tree
/
Copy pathLensCameraButtons.tsx
More file actions
92 lines (85 loc) · 2.8 KB
/
Copy pathLensCameraButtons.tsx
File metadata and controls
92 lines (85 loc) · 2.8 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
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
import { BoltFillIcon, ImageSetIcon } from "@artsy/icons/native"
import { DEFAULT_HIT_SLOP, Flex, FlexProps, Touchable, useSpace } from "@artsy/palette-mobile"
import { LensCapturePhotoButton } from "app/Scenes/Lens/Components/LensCapturePhotoButton"
export const LENS_CAMERA_BUTTONS_HEIGHT = 120
const SMALL_BUTTON_SIZE = 40
interface LensCameraButtonsProps extends FlexProps {
/** "libraryOnly" drops the shutter and torch, so the flow stays completable without camera
* access. */
mode: "camera" | "libraryOnly"
isCameraInitialized: boolean
deviceHasTorch: boolean
isTorchEnabled: boolean
onTakePhoto: () => void
onToggleTorch: () => void
onSelectFromLibrary: () => void
}
export const LensCameraButtons: React.FC<LensCameraButtonsProps> = (props) => {
const {
mode,
isCameraInitialized,
deviceHasTorch,
isTorchEnabled,
onTakePhoto,
onToggleTorch,
onSelectFromLibrary,
...rest
} = props
const space = useSpace()
return (
<Flex height={LENS_CAMERA_BUTTONS_HEIGHT} justifyContent="center" alignItems="center" {...rest}>
{mode === "camera" && (
<LensCapturePhotoButton
testID="lens-shutter-button"
onPress={onTakePhoto}
disabled={!isCameraInitialized}
/>
)}
{mode === "camera" && !!deviceHasTorch && (
<Touchable
testID="lens-torch-button"
accessibilityRole="button"
accessibilityLabel={isTorchEnabled ? "Turn off torch" : "Turn on torch"}
onPress={onToggleTorch}
disabled={!isCameraInitialized}
hitSlop={DEFAULT_HIT_SLOP}
style={{ position: "absolute", right: space(2) }}
>
<Flex
width={SMALL_BUTTON_SIZE}
height={SMALL_BUTTON_SIZE}
borderRadius={SMALL_BUTTON_SIZE / 2}
bg={isTorchEnabled ? "mono0" : "mono100"}
borderWidth={1}
borderColor="mono0"
justifyContent="center"
alignItems="center"
>
<BoltFillIcon fill={isTorchEnabled ? "mono100" : "mono0"} width={18} height={18} />
</Flex>
</Touchable>
)}
<Touchable
testID="lens-library-button"
accessibilityRole="button"
accessibilityLabel="Choose from library"
onPress={onSelectFromLibrary}
hitSlop={DEFAULT_HIT_SLOP}
style={
mode === "camera" ? { position: "absolute", left: space(2) } : { position: "absolute" }
}
>
<Flex
width={SMALL_BUTTON_SIZE}
height={SMALL_BUTTON_SIZE}
borderRadius={SMALL_BUTTON_SIZE / 2}
justifyContent="center"
alignItems="center"
bg="mono0"
>
<ImageSetIcon fill="mono100" width={18} height={18} />
</Flex>
</Touchable>
</Flex>
)
}