-
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
18 changed files
with
1,132 additions
and
84 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
// | ||
// noop.swift | ||
// PencilKitExample | ||
// | ||
// Created by mj on 5/3/24. | ||
// | ||
|
||
import Foundation |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,23 +1,64 @@ | ||
import { StyleSheet, View } from 'react-native'; | ||
import PencilKitView from 'react-native-pencil-kit'; | ||
import { useRef } from 'react'; | ||
import { Text, TouchableOpacity, View } from 'react-native'; | ||
import PencilKitView, { type PencilKitRef } from 'react-native-pencil-kit'; | ||
import { DocumentDirectoryPath } from '@dr.pogodin/react-native-fs'; | ||
|
||
export default function App() { | ||
const ref = useRef<PencilKitRef>(null); | ||
|
||
const path = `${DocumentDirectoryPath}/drawing.dat`; | ||
|
||
return ( | ||
<View style={styles.container}> | ||
<PencilKitView style={styles.box} /> | ||
<View style={{ width: '100%', height: '100%' }}> | ||
<PencilKitView | ||
ref={ref} | ||
style={{ flex: 1 }} | ||
alwaysBounceVertical={false} | ||
alwaysBounceHorizontal={false} | ||
drawingPolicy={'anyinput'} | ||
backgroundColor={'blue'} | ||
/> | ||
<View | ||
style={{ | ||
height: 300, | ||
flexDirection: 'row', | ||
alignItems: 'center', | ||
flexWrap: 'wrap', | ||
gap: 4, | ||
padding: 8, | ||
}} | ||
> | ||
<Btn onPress={() => ref.current?.showToolPicker()} text={'show'} /> | ||
<Btn onPress={() => ref.current?.hideToolPicker()} text={'hide'} /> | ||
<Btn onPress={() => ref.current?.clear()} text={'clear'} /> | ||
<Btn onPress={() => ref.current?.undo()} text={'undo'} /> | ||
<Btn onPress={() => ref.current?.redo()} text={'redo'} /> | ||
<Btn onPress={() => ref.current?.saveDrawing(path)} text={'save'} /> | ||
<Btn onPress={() => ref.current?.loadDrawing(path)} text={'load'} /> | ||
<Btn onPress={() => ref.current?.getBase64Data()} text={'get base64'} /> | ||
<Btn onPress={() => ref.current?.loadBase64Data('')} text={'load base64'} /> | ||
<Btn | ||
onPress={() => | ||
ref.current?.setTool({ | ||
toolType: 'pen', | ||
width: 2, | ||
color: 'red', | ||
}) | ||
} | ||
text={'pen'} | ||
/> | ||
</View> | ||
</View> | ||
); | ||
} | ||
|
||
const styles = StyleSheet.create({ | ||
container: { | ||
flex: 1, | ||
alignItems: 'center', | ||
justifyContent: 'center', | ||
}, | ||
box: { | ||
width: 60, | ||
height: 60, | ||
marginVertical: 20, | ||
}, | ||
}); | ||
const Btn = ({ onPress, text }: { onPress: () => void; text: string }) => { | ||
return ( | ||
<TouchableOpacity | ||
onPress={onPress} | ||
style={{ padding: 8, backgroundColor: 'black', borderRadius: 4 }} | ||
> | ||
<Text style={{ color: 'white', fontWeight: 'bold' }}>{text.toUpperCase()}</Text> | ||
</TouchableOpacity> | ||
); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.