Skip to content

Commit

Permalink
feat: add onLoadEnd prop
Browse files Browse the repository at this point in the history
  • Loading branch information
YanYuanFE committed Sep 23, 2023
1 parent ab34178 commit 49a8664
Show file tree
Hide file tree
Showing 5 changed files with 52 additions and 21 deletions.
25 changes: 13 additions & 12 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -51,37 +51,38 @@ import SignatureScreen from 'react-native-signature-canvas';
---

| Prop | Type | Description |
| :---------------------------------- | :--------: | :---------------------------------------------------------------------------------------------------------------------------------------------------- |
|:------------------------------------| :--------: |:------------------------------------------------------------------------------------------------------------------------------------------------------|
| androidHardwareAccelerationDisabled | `boolean` | androidHardwareAccelerationDisabled for react-native-webview. Default is false |
| autoClear | `boolean` | should auto clear the signature after clicking the Confirm button |
| backgroundColor | `string` | default is "rgba(255,255,255,0)" (_transparent_), background color of the canvas |
| backgroundColor | `string` | default is "rgba(255,255,255,0)" (_transparent_), background color of the canvas |
| bgHeight | `number` | height of the background image |
| bgWidth | `number` | width of the background image |
| bgSrc | `string` | background image source uri (_url_) |
| bgSrc | `string` | background image source uri (_url_) |
| clearText | `string` | clear button text |
| confirmText | `string` | save button text |
| customHtml | `(injectedJavaScript: string) => string` | html string that lets you modify things like the layout or elements |
| dataURL | `string` | default is "", Base64 string, draws saved signature from dataURL. |
| descriptionText | `string` | description text for signature |
| dotSize | `number` | radius of a single dot _(not stroke width)_ |
| imageType | `string` | "image/png" (_default_), "image/jpeg"、"image/svg+xml", imageType of exported signature |
| imageType | `string` | "image/png" (_default_), "image/jpeg"、"image/svg+xml", imageType of exported signature |
| minWidth | `number` | minimum width of a line. Defaults to 0.5 |
| maxWidth | `number` | maximum width of a line. Defaults to 2.5 |
| onOK | `function` | callback function after saving non-empty signature |
| onEmpty | `function` | callback function after trying to save an empty signature |
| onClear | `function` | callback function after clearing the signature |
|onGetData|`function`|callback function when getData() is called
| onGetData |`function`| callback function when getData() is called
| onBegin | `function` | callback function when a new stroke is started |
| onEnd | `function` | callback function when the stroke has ended |
| onUndo | `function` | callback function when undo() is called |
| onRedo | `function` | callback function when redo() is called |
| onLoadEnd | `function` | callback function when the webview canvas load ended |
| onUndo | `function` | callback function when undo() is called |
| onRedo | `function` | callback function when redo() is called |
| onDraw | `function` | callback function when drawing is enabled |
| onErase | `function` | callback function when erasing is enabled |
| onChangePenColor | `function` | callback function after changing the pen color |
| onChangePenSize | `function` | callback function after changing the pen size
|overlayHeight|`number`|height of the overlay image|
|overlayWidth|`number`|width of the overlay image|
|overlaySrc|`string`|overlay image source uri (url) _must be .png with a transparent background_
| onChangePenColor | `function` | callback function after changing the pen color |
| onChangePenSize | `function` | callback function after changing the pen size
| overlayHeight |`number`| height of the overlay image |
| overlayWidth |`number`| width of the overlay image |
| overlaySrc |`string`| overlay image source uri (url) _must be .png with a transparent background_
| penColor | `string` | default is "black", color of pen |
| rotated | `boolean` | rotate signature pad 90 degrees |
| style | `object` | style of wrapper view |
Expand Down
37 changes: 30 additions & 7 deletions example/sign-app/App.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { StyleSheet, View, ScrollView, Image, Text } from 'react-native';
import { StyleSheet, View, ScrollView, Image, Text, ImageBackground } from 'react-native';
import SignatureScreen from "react-native-signature-canvas";
import {useEffect, useRef, useState} from "react";
import {MySignatureCanvas} from "./ScrollSign";
Expand All @@ -7,9 +7,11 @@ import ViewShot from "react-native-view-shot";
const url = "data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABwAAAAcCAYAAAByDd+UAAAACXBIWXMAAAsTAAALEwEAmpwYAAAKTWlDQ1BQaG90b3Nob3AgSUNDIHByb2ZpbGUAAHjanVN3WJP3Fj7f92UPVkLY8LGXbIEAIiOsCMgQWaIQkgBhhBASQMWFiApWFBURnEhVxILVCkidiOKgKLhnQYqIWotVXDjuH9yntX167+3t+9f7vOec5/zOec8PgBESJpHmomoAOVKFPDrYH49PSMTJvYACFUjgBCAQ5svCZwXFAADwA3l4fnSwP/wBr28AAgBw1S4kEsfh/4O6UCZXAC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ONNlSNPeaEPY1DAGBe5EY/jHFOGmaa6irtmYNdqiqGPmI0xDzjyncW2NtQJGlIY2l3QC+vhCL8dXHyYX5Al+dcPHWwac2ba9ggpMHyuk+6WZ72vD29YXQY+j18Aegpd3t4Pxre9eVp8uaPC3EIJGgyr6dxl02jnvKqNXJkzZx3vn6N75ba2evIkut6wnwCGD7PwT4TF+IrqFpgAVgnybAT2TF+Mg/wTepFeOQIks/Z71EeZtraHM5Mt5WTawRxNcX0gQ3CjTrwXJaE/eIFkqTs/H+Ypzx8BKDkxH8QYU7uayJacDvJZW6YQuLcLciS2c3HAylnf3ZFNKv+s8D2moQTo7GAeBaNqv+vwMApOmkagtYWsAAAAAASUVORK5CYII="

const dataURL = 'data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAADMAAAAzCAYAAAA6oTAqAAAAEXRFWHRTb2Z0d2FyZQBwbmdjcnVzaEB1SfMAAABQSURBVGje7dSxCQBACARB+2/ab8BEeQNhFi6WSYzYLYudDQYGBgYGBgYGBgYGBgYGBgZmcvDqYGBgmhivGQYGBgYGBgYGBgYGBgYGBgbmQw+P/eMrC5UTVAAAAABJRU5ErkJggg=='

const bgUrl = 'https://legacy.reactjs.org/logo-og.png';
const Sign = ({ text, onOK }) => {
const ref = useRef();
const [bg, setBg] = useState(dataURL);
const [bg, setBg] = useState(bgUrl);

// Called after ref.current.readSignature() reads a non-empty base64 string
const handleOK = (signature) => {
Expand Down Expand Up @@ -49,6 +51,18 @@ const Sign = ({ text, onOK }) => {
backgroundColor={'transparent'}
style={{ flex: 1, height: 300 }}
androidHardwareAccelerationDisabled={false}
webStyle={`
.m-signature-pad canvas {
background-image: url('${bg}');
background-size: 100% 100%;
background-repeat: no-repeat;
}
.m-signature-pad {
flex: 1;
box-shadow: none;
border-radius: 10px;
}
`}
/>
);
};
Expand Down Expand Up @@ -93,6 +107,7 @@ export default function App() {
const [img, setImg] = useState(null);
const [sign, setSign] = useState(null);
const ref = useRef();
const [bg, setBg] = useState(bgUrl);

const onCapture = () => {
ref.current.capture().then(uri => {
Expand All @@ -112,22 +127,24 @@ export default function App() {
return (
<View style={styles.container}>
<ViewShot ref={ref} options={{ fileName: "Your-File-Name", format: "png", quality: 0.9, result: 'data-uri' }}>
<ImageBackground source={{uri: bg}} style={styles.image}>
<View style={{
width: 400,
height: 300
}}>
{sign ? (
<Image
resizeMode={"contain"}
style={{ width: 400, height: 114 }}
source={{ uri: sign }}
/>
<Image
resizeMode={"contain"}
style={{ width: 400, height: 300 }}
source={{ uri: sign }}
/>
) : <Sign text="Test" onOK={(img) => {
console.log('ok')
setSign(img);
onCapture();
}} />}
</View>
</ImageBackground>
<Text>...Something to rasterize...</Text>
</ViewShot>
<View style={styles.preview}>
Expand All @@ -150,6 +167,12 @@ const styles = StyleSheet.create({
// alignItems: 'center',
// justifyContent: 'center',
},
image: {
// flex: 1,
resizeMode: 'cover',
justifyContent: 'center',
height: 300,
},
preview: {
height: 114,
backgroundColor: "green",
Expand Down
1 change: 1 addition & 0 deletions index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ declare module "react-native-signature-canvas" {
onChangePenSize?: () => void;
onBegin?: () => void;
onEnd?: () => void;
onLoadEnd?: () => void;
overlayHeight?: number;
overlayWidth?: number;
overlaySrc?: string;
Expand Down
8 changes: 7 additions & 1 deletion index.js
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ const SignatureView = forwardRef(
onChangePenSize = () => {},
onBegin = () => {},
onEnd = () => {},
onLoadEnd = () => {},
overlayHeight = 0,
overlayWidth = 0,
overlaySrc = null,
Expand Down Expand Up @@ -253,6 +254,11 @@ const SignatureView = forwardRef(
const renderError = ({ nativeEvent }) =>
console.warn("WebView error: ", nativeEvent);

const handleLoadEnd = () => {
setLoading(false);
onLoadEnd();
}

return (
<View style={[styles.webBg, style]}>
<WebView
Expand All @@ -269,7 +275,7 @@ const SignatureView = forwardRef(
onMessage={getSignature}
javaScriptEnabled={true}
onError={renderError}
onLoadEnd={() => setLoading(false)}
onLoadEnd={handleLoadEnd}
/>
{loading && (
<View style={styles.loadingOverlayContainer}>
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "react-native-signature-canvas",
"version": "4.6.1",
"version": "4.7.0",
"description": "React Native Signature Component based Canvas for Android && IOS && expo",
"main": "index.js",
"scripts": {
Expand Down

0 comments on commit 49a8664

Please sign in to comment.