-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathpencil_kit.ios.tsx
72 lines (56 loc) · 1.58 KB
/
pencil_kit.ios.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
import React, { ReactElement } from 'react'
import ReactNative, { NativeModules, requireNativeComponent, StyleSheet } from 'react-native'
// Load Native iOS Components
const RNPencilKit = requireNativeComponent('RNPencilKit')
const RNPencilKitManager = NativeModules.RNPencilKitManager
const styles = StyleSheet.create({
container: {
flex: 1,
},
})
interface Props {
style?: 'light' | 'dark'
onFinished: (uri: string) => void
}
export class PencilKit extends React.Component<Props> {
private pencilKit: React.RefObject<PencilKit>
static isAvailable(): boolean {
return RNPencilKitManager.available
}
constructor(props: Props) {
super(props)
this.pencilKit = React.createRef()
}
componentDidMount(): void {
this.setToolPicker()
}
getTag(): number {
return ReactNative.findNodeHandle(this.pencilKit.current)
}
getDrawing(callback: (data: { uri: string }) => void): void {
RNPencilKitManager.getDrawing(this.getTag(), callback)
}
setToolPicker(): void {
RNPencilKitManager.setToolPicker(this.getTag())
}
setDarkMode(): void {
RNPencilKitManager.setDarkMode(this.getTag())
}
setLightMode(): void {
RNPencilKitManager.setLightMode(this.getTag())
}
save = (): void => {
this.getDrawing((data: { uri: string }): void => {
this.props.onFinished(data.uri)
})
}
undo = (): void => {
RNPencilKitManager.undo(this.getTag())
}
redo = (): void => {
RNPencilKitManager.redo(this.getTag())
}
render(): ReactElement {
return <RNPencilKit ref={this.pencilKit} style={styles.container} />
}
}