-
Notifications
You must be signed in to change notification settings - Fork 16
/
Copy pathRNMLKitImageView.tsx
91 lines (86 loc) · 2.43 KB
/
RNMLKitImageView.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
import * as React from "react"
import { StyleProp, ViewStyle, Pressable, ImageStyle, TextStyle, View } from "react-native"
import { observer } from "mobx-react-lite"
import { Text } from "app/components/Text"
import { ImageWithBoundingBoxes, BoundingBox } from "@infinitered/react-native-mlkit-core"
import { Icon } from "./Icon"
const $image: ViewStyle = { width: "100%", aspectRatio: "16/9", marginVertical: 8 }
const $imagePlaceholder: ViewStyle = {
borderWidth: 1,
borderTopWidth: 1,
borderLeftWidth: 1,
borderColor: "rgba(0,0,0,0.2)",
borderTopColor: "rgba(0,0,0,0.4)",
borderLeftColor: "rgba(0,0,0,0.4)",
display: "flex",
justifyContent: "center",
alignItems: "center",
padding: 8,
backgroundColor: "rgba(255,255,255,0.9)",
}
const $caption: TextStyle = {
marginLeft: 2,
fontSize: 8,
textAlign: "right",
fontWeight: "bold",
color: "rgba(0,0,0,0.6)",
}
const $captionContainer: ViewStyle = {
position: "absolute",
bottom: 0,
right: 8,
backgroundColor: "rgba(255,255,255,0.6)",
paddingHorizontal: 4,
display: "flex",
flexDirection: "row",
justifyContent: "space-between",
alignItems: "center",
}
export interface RNMLKitImageViewProps {
/**
* An optional style override useful for padding & margin.
*/
style?: StyleProp<ViewStyle>
imageStyle?: ImageStyle
image?: { localUri?: string; uri?: string; width?: number; height?: number; caption?: string }
onPress?: () => void
boxes?: BoundingBox[]
}
const $takePhotoText: { color: string } = { color: "rgba(0,0,0,0.2)" }
/**
* Describe your component here
*/
export const RNMLKitImageView = observer(function RNMLKitImageView({
image,
onPress,
boxes,
style,
imageStyle,
}: RNMLKitImageViewProps) {
return (
<Pressable onPress={onPress} style={[$image, $imagePlaceholder, style]}>
{image ? (
<>
<ImageWithBoundingBoxes
image={image}
boundingBoxes={boxes}
style={$image}
imageStyle={imageStyle}
contentFit={"contain"}
/>
<View style={$captionContainer}>
<Icon icon={"camera"} size={10} color={"rgba(0,0,0,0.9)"} />
<Text style={$caption} text={image.caption} />
</View>
</>
) : (
<>
<Icon icon={"camera"} size={80} color={"rgba(0,0,0,0.1)"} />
<Text style={$takePhotoText} size={"lg"}>
Take Photo
</Text>
</>
)}
</Pressable>
)
})