react-native-signature-canvas 4.7.4 → 5.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +51 -0
- package/CLAUDE.md +88 -0
- package/QUICK_START.md +219 -0
- package/README.md +259 -14
- package/WEBVIEW_PROPS.md +166 -0
- package/h5/js/app.js +126 -39
- package/index.d.ts +38 -17
- package/index.js +240 -161
- package/package.json +11 -4
package/CHANGELOG.md
CHANGED
|
@@ -1,3 +1,54 @@
|
|
|
1
|
+
# [5.0.0](https://github.com/YanYuanFE/react-native-signature-canvas/compare/v4.5.1...v5.0.0) (2025-06-28)
|
|
2
|
+
|
|
3
|
+
|
|
4
|
+
### Bug Fixes
|
|
5
|
+
|
|
6
|
+
* add originWhitelist prop ([068c646](https://github.com/YanYuanFE/react-native-signature-canvas/commit/068c6467d1e9910c4911e727b2144e065a9a7322))
|
|
7
|
+
* backgorund color to transparent and loader color to transparent ([3001d4e](https://github.com/YanYuanFE/react-native-signature-canvas/commit/3001d4edfdcf1806e2f16a518d25f1690b80557e))
|
|
8
|
+
* fix canvas not display for android api 28 ([835669b](https://github.com/YanYuanFE/react-native-signature-canvas/commit/835669bb65ab5c88c43830b7a783eed105f3910d))
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
### Features
|
|
12
|
+
|
|
13
|
+
* add onLoadEnd prop ([49a8664](https://github.com/YanYuanFE/react-native-signature-canvas/commit/49a866408b6356ce9e71b1c794993a3f2fe85337))
|
|
14
|
+
* add showsVerticalScrollIndicator prop ([a4d64c5](https://github.com/YanYuanFE/react-native-signature-canvas/commit/a4d64c5754a9da4ecb9d531a1585a38994d18d6d))
|
|
15
|
+
* export SignatureViewProps ([8f0c321](https://github.com/YanYuanFE/react-native-signature-canvas/commit/8f0c3211b20782cd8f35a43083f39d5ea351f932))
|
|
16
|
+
|
|
17
|
+
|
|
18
|
+
|
|
19
|
+
## [4.5.1](https://github.com/YanYuanFE/react-native-signature-canvas/compare/v4.3.0...v4.5.1) (2023-05-04)
|
|
20
|
+
|
|
21
|
+
|
|
22
|
+
### Bug Fixes
|
|
23
|
+
|
|
24
|
+
* **android:** sigsegv crash on android ([49644b8](https://github.com/YanYuanFE/react-native-signature-canvas/commit/49644b802a7cb80443292972b1fbd3d4dbdfd9c4))
|
|
25
|
+
* fix bgSrc props ([bef3ab2](https://github.com/YanYuanFE/react-native-signature-canvas/commit/bef3ab27ebb990a94dd74517ab67754d557307ae))
|
|
26
|
+
* fix webview version ([1b55f45](https://github.com/YanYuanFE/react-native-signature-canvas/commit/1b55f45e27560cd8b0bdf62504a7d27b412687c2))
|
|
27
|
+
|
|
28
|
+
|
|
29
|
+
### Features
|
|
30
|
+
|
|
31
|
+
* update rn latest example ([f9a568f](https://github.com/YanYuanFE/react-native-signature-canvas/commit/f9a568f68c966690ee2ec1b300b2e2fb6f18ee56))
|
|
32
|
+
|
|
33
|
+
|
|
34
|
+
|
|
35
|
+
# [4.3.0](https://github.com/YanYuanFE/react-native-signature-canvas/compare/v4.2.1...v4.3.0) (2021-08-11)
|
|
36
|
+
|
|
37
|
+
|
|
38
|
+
|
|
39
|
+
## [4.2.1](https://github.com/YanYuanFE/react-native-signature-canvas/compare/v4.2.0...v4.2.1) (2021-08-04)
|
|
40
|
+
|
|
41
|
+
|
|
42
|
+
### Bug Fixes
|
|
43
|
+
|
|
44
|
+
* ts imageType ([d50d227](https://github.com/YanYuanFE/react-native-signature-canvas/commit/d50d22747278f860152ff1c8a87be6e335236724))
|
|
45
|
+
|
|
46
|
+
|
|
47
|
+
|
|
48
|
+
# [4.2.0](https://github.com/YanYuanFE/react-native-signature-canvas/compare/v4.1.0...v4.2.0) (2021-07-24)
|
|
49
|
+
|
|
50
|
+
|
|
51
|
+
|
|
1
52
|
# [4.1.0](https://github.com/YanYuanFE/react-native-signature-canvas/compare/v4.0.0...v4.1.0) (2021-07-14)
|
|
2
53
|
|
|
3
54
|
|
package/CLAUDE.md
ADDED
|
@@ -0,0 +1,88 @@
|
|
|
1
|
+
# CLAUDE.md
|
|
2
|
+
|
|
3
|
+
This file provides guidance to Claude Code (claude.ai/code) when working with code in this repository.
|
|
4
|
+
|
|
5
|
+
## Project Overview
|
|
6
|
+
|
|
7
|
+
This is `react-native-signature-canvas`, a React Native library for capturing signatures and drawing on a canvas. The library provides a WebView-based signature pad component with smooth drawing capabilities across iOS, Android, and Expo.
|
|
8
|
+
|
|
9
|
+
## Core Architecture
|
|
10
|
+
|
|
11
|
+
The library uses a hybrid architecture combining React Native and web technologies:
|
|
12
|
+
|
|
13
|
+
- **Main Component** (`index.js`): The React Native component that wraps a WebView
|
|
14
|
+
- **WebView Content** (`h5/`): HTML, CSS, and JavaScript that runs inside the WebView
|
|
15
|
+
- `html.js`: HTML template with placeholder variables for configuration
|
|
16
|
+
- `js/signature_pad.js`: Core signature pad functionality
|
|
17
|
+
- `js/app.js`: Application logic for handling signature interactions
|
|
18
|
+
- `css/signature-pad.css`: Styling for the signature pad interface
|
|
19
|
+
- **TypeScript Definitions** (`index.d.ts`): Type definitions for props and ref methods
|
|
20
|
+
|
|
21
|
+
### Key Technical Details
|
|
22
|
+
|
|
23
|
+
1. **Communication**: React Native communicates with the WebView through:
|
|
24
|
+
- `injectedJavaScript`: JavaScript code injected into the WebView
|
|
25
|
+
- `onMessage`: Messages sent from WebView to React Native
|
|
26
|
+
- Template variables in HTML (e.g., `<%penColor%>`, `<%bgSrc%>`)
|
|
27
|
+
|
|
28
|
+
2. **Signature Export**: Signatures are captured as base64 data URLs and passed back to React Native via the WebView message bridge
|
|
29
|
+
|
|
30
|
+
3. **Customization**: The component supports extensive customization through props that modify the injected HTML/CSS/JS
|
|
31
|
+
|
|
32
|
+
## Common Development Commands
|
|
33
|
+
|
|
34
|
+
### Example Apps
|
|
35
|
+
The repository contains multiple example applications for different use cases:
|
|
36
|
+
|
|
37
|
+
```bash
|
|
38
|
+
# React Native CLI app with TypeScript
|
|
39
|
+
cd example/signapp && npm run android
|
|
40
|
+
cd example/signapp && npm run ios
|
|
41
|
+
|
|
42
|
+
# Expo app with modern Expo Router
|
|
43
|
+
cd example/expo-app && npm start
|
|
44
|
+
cd example/expo-app && npm run android
|
|
45
|
+
cd example/expo-app && npm run ios
|
|
46
|
+
|
|
47
|
+
# Basic React Native CLI app
|
|
48
|
+
cd example/exampleApp && npm start
|
|
49
|
+
```
|
|
50
|
+
|
|
51
|
+
### Testing
|
|
52
|
+
```bash
|
|
53
|
+
# Run tests in example apps
|
|
54
|
+
cd example/signapp && npm test
|
|
55
|
+
cd example/expo-app && npm test
|
|
56
|
+
```
|
|
57
|
+
|
|
58
|
+
### Linting
|
|
59
|
+
```bash
|
|
60
|
+
# Lint example apps
|
|
61
|
+
cd example/signapp && npm run lint
|
|
62
|
+
cd example/expo-app && npm run lint
|
|
63
|
+
```
|
|
64
|
+
|
|
65
|
+
## Development Notes
|
|
66
|
+
|
|
67
|
+
### Modifying the Core Component
|
|
68
|
+
- The main component logic is in `index.js`
|
|
69
|
+
- WebView HTML template is in `h5/html.js`
|
|
70
|
+
- JavaScript functionality is split between `h5/js/signature_pad.js` and `h5/js/app.js`
|
|
71
|
+
|
|
72
|
+
### Adding New Features
|
|
73
|
+
1. Add props to the main component interface
|
|
74
|
+
2. Update TypeScript definitions in `index.d.ts`
|
|
75
|
+
3. Modify the HTML template in `h5/html.js` if UI changes are needed
|
|
76
|
+
4. Update the injected JavaScript in `h5/js/app.js` for new functionality
|
|
77
|
+
5. Test across multiple example apps to ensure compatibility
|
|
78
|
+
|
|
79
|
+
### Example App Structure
|
|
80
|
+
- `signapp/`: Full React Native CLI app with TypeScript and Jest testing
|
|
81
|
+
- `expo-app/`: Modern Expo app with Expo Router and TypeScript
|
|
82
|
+
- `exampleApp/`: Basic React Native CLI app
|
|
83
|
+
- `expo-app1/`, `signapp1/`, `sign-app/`, `ts-expo/`: Various other example configurations
|
|
84
|
+
|
|
85
|
+
### Dependencies
|
|
86
|
+
- Main library only has peer dependency on `react-native-webview`
|
|
87
|
+
- Example apps include additional dependencies for testing and development
|
|
88
|
+
- No build process required for the main library (it's a pure React Native component)
|
package/QUICK_START.md
ADDED
|
@@ -0,0 +1,219 @@
|
|
|
1
|
+
# Quick Start Guide
|
|
2
|
+
|
|
3
|
+
Get up and running with `react-native-signature-canvas` in minutes!
|
|
4
|
+
|
|
5
|
+
## 🚀 Installation
|
|
6
|
+
|
|
7
|
+
```bash
|
|
8
|
+
# Install the package
|
|
9
|
+
npm install react-native-signature-canvas
|
|
10
|
+
|
|
11
|
+
# For React Native CLI projects, also install WebView
|
|
12
|
+
npm install react-native-webview
|
|
13
|
+
cd ios && pod install # iOS only
|
|
14
|
+
```
|
|
15
|
+
|
|
16
|
+
## 📱 Basic Example
|
|
17
|
+
|
|
18
|
+
```jsx
|
|
19
|
+
import React, { useRef, useState } from 'react';
|
|
20
|
+
import { View, Button, StyleSheet } from 'react-native';
|
|
21
|
+
import SignatureCanvas from 'react-native-signature-canvas';
|
|
22
|
+
|
|
23
|
+
export default function App() {
|
|
24
|
+
const ref = useRef();
|
|
25
|
+
const [signature, setSignature] = useState();
|
|
26
|
+
|
|
27
|
+
const handleOK = (signature) => {
|
|
28
|
+
console.log(signature);
|
|
29
|
+
setSignature(signature);
|
|
30
|
+
};
|
|
31
|
+
|
|
32
|
+
const handleClear = () => {
|
|
33
|
+
ref.current?.clearSignature();
|
|
34
|
+
};
|
|
35
|
+
|
|
36
|
+
const handleSave = () => {
|
|
37
|
+
ref.current?.readSignature();
|
|
38
|
+
};
|
|
39
|
+
|
|
40
|
+
return (
|
|
41
|
+
<View style={styles.container}>
|
|
42
|
+
<SignatureCanvas
|
|
43
|
+
ref={ref}
|
|
44
|
+
onOK={handleOK}
|
|
45
|
+
onEmpty={() => console.log('Empty')}
|
|
46
|
+
descriptionText="Sign here"
|
|
47
|
+
clearText="Clear"
|
|
48
|
+
confirmText="Save"
|
|
49
|
+
style={styles.signature}
|
|
50
|
+
/>
|
|
51
|
+
|
|
52
|
+
<View style={styles.buttons}>
|
|
53
|
+
<Button title="Clear" onPress={handleClear} />
|
|
54
|
+
<Button title="Save" onPress={handleSave} />
|
|
55
|
+
</View>
|
|
56
|
+
</View>
|
|
57
|
+
);
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
const styles = StyleSheet.create({
|
|
61
|
+
container: {
|
|
62
|
+
flex: 1,
|
|
63
|
+
padding: 20,
|
|
64
|
+
},
|
|
65
|
+
signature: {
|
|
66
|
+
flex: 1,
|
|
67
|
+
borderColor: '#000033',
|
|
68
|
+
borderWidth: 1,
|
|
69
|
+
},
|
|
70
|
+
buttons: {
|
|
71
|
+
flexDirection: 'row',
|
|
72
|
+
justifyContent: 'space-around',
|
|
73
|
+
marginTop: 20,
|
|
74
|
+
},
|
|
75
|
+
});
|
|
76
|
+
```
|
|
77
|
+
|
|
78
|
+
## ⚡ Enhanced Example with New Features
|
|
79
|
+
|
|
80
|
+
```jsx
|
|
81
|
+
import React, { useRef, useState } from 'react';
|
|
82
|
+
import { View, Button, StyleSheet, Alert } from 'react-native';
|
|
83
|
+
import SignatureCanvas from 'react-native-signature-canvas';
|
|
84
|
+
|
|
85
|
+
export default function EnhancedSignatureApp() {
|
|
86
|
+
const ref = useRef();
|
|
87
|
+
const [signature, setSignature] = useState();
|
|
88
|
+
const [isLoading, setIsLoading] = useState(false);
|
|
89
|
+
|
|
90
|
+
const handleSignature = (signature) => {
|
|
91
|
+
setSignature(signature);
|
|
92
|
+
setIsLoading(false);
|
|
93
|
+
Alert.alert('Success', 'Signature saved!');
|
|
94
|
+
};
|
|
95
|
+
|
|
96
|
+
const handleEmpty = () => {
|
|
97
|
+
setIsLoading(false);
|
|
98
|
+
Alert.alert('Empty', 'Please draw a signature first');
|
|
99
|
+
};
|
|
100
|
+
|
|
101
|
+
const handleError = (error) => {
|
|
102
|
+
setIsLoading(false);
|
|
103
|
+
Alert.alert('Error', error.message);
|
|
104
|
+
};
|
|
105
|
+
|
|
106
|
+
const handleSave = () => {
|
|
107
|
+
setIsLoading(true);
|
|
108
|
+
ref.current?.readSignature();
|
|
109
|
+
};
|
|
110
|
+
|
|
111
|
+
return (
|
|
112
|
+
<View style={styles.container}>
|
|
113
|
+
<SignatureCanvas
|
|
114
|
+
ref={ref}
|
|
115
|
+
onOK={handleSignature}
|
|
116
|
+
onEmpty={handleEmpty}
|
|
117
|
+
onError={handleError}
|
|
118
|
+
descriptionText="Sign here"
|
|
119
|
+
clearText="Clear"
|
|
120
|
+
confirmText={isLoading ? "Saving..." : "Save"}
|
|
121
|
+
penColor="#0066cc"
|
|
122
|
+
backgroundColor="rgba(255,255,255,0)"
|
|
123
|
+
// NEW: WebView customization
|
|
124
|
+
webviewProps={{
|
|
125
|
+
cacheEnabled: true,
|
|
126
|
+
androidLayerType: "hardware",
|
|
127
|
+
}}
|
|
128
|
+
style={styles.signature}
|
|
129
|
+
/>
|
|
130
|
+
|
|
131
|
+
<View style={styles.controls}>
|
|
132
|
+
<Button
|
|
133
|
+
title="Clear"
|
|
134
|
+
onPress={() => ref.current?.clearSignature()}
|
|
135
|
+
/>
|
|
136
|
+
<Button
|
|
137
|
+
title="Undo"
|
|
138
|
+
onPress={() => ref.current?.undo()}
|
|
139
|
+
/>
|
|
140
|
+
<Button
|
|
141
|
+
title="Save"
|
|
142
|
+
onPress={handleSave}
|
|
143
|
+
disabled={isLoading}
|
|
144
|
+
/>
|
|
145
|
+
</View>
|
|
146
|
+
</View>
|
|
147
|
+
);
|
|
148
|
+
}
|
|
149
|
+
|
|
150
|
+
const styles = StyleSheet.create({
|
|
151
|
+
container: {
|
|
152
|
+
flex: 1,
|
|
153
|
+
backgroundColor: '#f5f5f5',
|
|
154
|
+
padding: 20,
|
|
155
|
+
},
|
|
156
|
+
signature: {
|
|
157
|
+
flex: 1,
|
|
158
|
+
borderColor: '#ddd',
|
|
159
|
+
borderWidth: 1,
|
|
160
|
+
borderRadius: 8,
|
|
161
|
+
backgroundColor: 'white',
|
|
162
|
+
},
|
|
163
|
+
controls: {
|
|
164
|
+
flexDirection: 'row',
|
|
165
|
+
justifyContent: 'space-around',
|
|
166
|
+
marginTop: 20,
|
|
167
|
+
paddingVertical: 10,
|
|
168
|
+
},
|
|
169
|
+
});
|
|
170
|
+
```
|
|
171
|
+
|
|
172
|
+
## 🔧 Common Configurations
|
|
173
|
+
|
|
174
|
+
### High Performance Setup
|
|
175
|
+
```jsx
|
|
176
|
+
<SignatureCanvas
|
|
177
|
+
webviewProps={{
|
|
178
|
+
cacheEnabled: true,
|
|
179
|
+
androidLayerType: "hardware",
|
|
180
|
+
androidHardwareAccelerationDisabled: false,
|
|
181
|
+
}}
|
|
182
|
+
/>
|
|
183
|
+
```
|
|
184
|
+
|
|
185
|
+
### Low Memory Setup
|
|
186
|
+
```jsx
|
|
187
|
+
<SignatureCanvas
|
|
188
|
+
webviewProps={{
|
|
189
|
+
cacheEnabled: false,
|
|
190
|
+
androidLayerType: "software",
|
|
191
|
+
androidHardwareAccelerationDisabled: true,
|
|
192
|
+
}}
|
|
193
|
+
/>
|
|
194
|
+
```
|
|
195
|
+
|
|
196
|
+
### Security Focused Setup
|
|
197
|
+
```jsx
|
|
198
|
+
<SignatureCanvas
|
|
199
|
+
webviewProps={{
|
|
200
|
+
allowFileAccess: false,
|
|
201
|
+
allowFileAccessFromFileURLs: false,
|
|
202
|
+
mixedContentMode: "never",
|
|
203
|
+
allowsLinkPreview: false,
|
|
204
|
+
}}
|
|
205
|
+
/>
|
|
206
|
+
```
|
|
207
|
+
|
|
208
|
+
## 📖 Next Steps
|
|
209
|
+
|
|
210
|
+
- [Read the full documentation](./README.md)
|
|
211
|
+
- [Learn about WebView customization](./WEBVIEW_PROPS.md)
|
|
212
|
+
- [Check out example apps](./example/)
|
|
213
|
+
- [View TypeScript definitions](./index.d.ts)
|
|
214
|
+
|
|
215
|
+
## 🆘 Need Help?
|
|
216
|
+
|
|
217
|
+
- [Check troubleshooting guide](./README.md#troubleshooting)
|
|
218
|
+
- [View common issues](https://github.com/YanYuanFE/react-native-signature-canvas/issues)
|
|
219
|
+
- [Ask questions in discussions](https://github.com/YanYuanFE/react-native-signature-canvas/discussions)
|
package/README.md
CHANGED
|
@@ -10,14 +10,19 @@ A React Native component for capturing signatures or drawing on a canvas with a
|
|
|
10
10
|
|
|
11
11
|
## Features
|
|
12
12
|
|
|
13
|
-
- Cross-platform support (iOS, Android, Expo)
|
|
14
|
-
- Smooth, responsive drawing experience
|
|
15
|
-
- Customizable pen color, size, and background
|
|
16
|
-
- Support for background and overlay images
|
|
17
|
-
- Export signatures as PNG, JPEG, or SVG
|
|
18
|
-
- Undo/redo functionality
|
|
19
|
-
- Drawing and erasing modes
|
|
20
|
-
- TypeScript support
|
|
13
|
+
- ✅ **Cross-platform support** (iOS, Android, Expo)
|
|
14
|
+
- ✅ **Smooth, responsive drawing experience** with optimized performance
|
|
15
|
+
- ✅ **Customizable pen color, size, and background**
|
|
16
|
+
- ✅ **Support for background and overlay images**
|
|
17
|
+
- ✅ **Export signatures** as PNG, JPEG, or SVG
|
|
18
|
+
- ✅ **Undo/redo functionality**
|
|
19
|
+
- ✅ **Drawing and erasing modes**
|
|
20
|
+
- ✅ **Full TypeScript support** with enhanced type definitions
|
|
21
|
+
- 🆕 **Advanced error handling** with automatic recovery
|
|
22
|
+
- 🆕 **Performance monitoring** and optimization
|
|
23
|
+
- 🆕 **Flexible WebView customization** via `webviewProps`
|
|
24
|
+
- 🆕 **Enhanced security** with configurable restrictions
|
|
25
|
+
- 🆕 **Memory management** and leak prevention
|
|
21
26
|
|
|
22
27
|
## Installation
|
|
23
28
|
|
|
@@ -55,23 +60,33 @@ import SignatureCanvas from 'react-native-signature-canvas';
|
|
|
55
60
|
|
|
56
61
|
const SignatureScreen = () => {
|
|
57
62
|
const [signature, setSignature] = useState(null);
|
|
63
|
+
const [isLoading, setIsLoading] = useState(false);
|
|
58
64
|
const ref = useRef();
|
|
59
65
|
|
|
60
66
|
const handleSignature = (signature) => {
|
|
61
|
-
console.log(signature);
|
|
67
|
+
console.log('Signature captured:', signature);
|
|
62
68
|
setSignature(signature);
|
|
69
|
+
setIsLoading(false);
|
|
63
70
|
};
|
|
64
71
|
|
|
65
72
|
const handleEmpty = () => {
|
|
66
|
-
console.log('
|
|
73
|
+
console.log('Signature is empty');
|
|
74
|
+
setIsLoading(false);
|
|
67
75
|
};
|
|
68
76
|
|
|
69
77
|
const handleClear = () => {
|
|
70
|
-
console.log('
|
|
78
|
+
console.log('Signature cleared');
|
|
79
|
+
setSignature(null);
|
|
80
|
+
};
|
|
81
|
+
|
|
82
|
+
const handleError = (error) => {
|
|
83
|
+
console.error('Signature pad error:', error);
|
|
84
|
+
setIsLoading(false);
|
|
71
85
|
};
|
|
72
86
|
|
|
73
87
|
const handleEnd = () => {
|
|
74
|
-
|
|
88
|
+
setIsLoading(true);
|
|
89
|
+
ref.current?.readSignature();
|
|
75
90
|
};
|
|
76
91
|
|
|
77
92
|
return (
|
|
@@ -91,10 +106,18 @@ const SignatureScreen = () => {
|
|
|
91
106
|
onOK={handleSignature}
|
|
92
107
|
onEmpty={handleEmpty}
|
|
93
108
|
onClear={handleClear}
|
|
109
|
+
onError={handleError}
|
|
94
110
|
autoClear={true}
|
|
95
111
|
descriptionText="Sign here"
|
|
96
112
|
clearText="Clear"
|
|
97
|
-
confirmText="Save"
|
|
113
|
+
confirmText={isLoading ? "Processing..." : "Save"}
|
|
114
|
+
penColor="#000000"
|
|
115
|
+
backgroundColor="rgba(255,255,255,0)"
|
|
116
|
+
webviewProps={{
|
|
117
|
+
// Custom WebView optimization
|
|
118
|
+
cacheEnabled: true,
|
|
119
|
+
androidLayerType: "hardware",
|
|
120
|
+
}}
|
|
98
121
|
/>
|
|
99
122
|
</View>
|
|
100
123
|
);
|
|
@@ -162,6 +185,8 @@ export default SignatureScreen;
|
|
|
162
185
|
| `webStyle` | `string` | - | WebView style to override default style |
|
|
163
186
|
| `webviewContainerStyle` | `object` | - | Style for the WebView container |
|
|
164
187
|
| `androidLayerType` | `none\|software\|hardware` | `hardware` | Sets the Android WebView layer type |
|
|
188
|
+
| `onError` | `function` | - | Callback when an error occurs |
|
|
189
|
+
| `webviewProps` | `object` | `{}` | Additional props to pass to the underlying WebView |
|
|
165
190
|
|
|
166
191
|
## Methods
|
|
167
192
|
|
|
@@ -179,6 +204,76 @@ Access these methods using a ref to the SignatureCanvas component.
|
|
|
179
204
|
| `undo()` | Undo last stroke |
|
|
180
205
|
| `redo()` | Redo last stroke |
|
|
181
206
|
|
|
207
|
+
## WebView Customization (New!)
|
|
208
|
+
|
|
209
|
+
The `webviewProps` parameter allows you to customize the underlying WebView behavior while maintaining signature functionality:
|
|
210
|
+
|
|
211
|
+
```jsx
|
|
212
|
+
<SignatureCanvas
|
|
213
|
+
// ... other props
|
|
214
|
+
webviewProps={{
|
|
215
|
+
// Performance optimization
|
|
216
|
+
cacheEnabled: true,
|
|
217
|
+
androidLayerType: "hardware",
|
|
218
|
+
androidHardwareAccelerationDisabled: false,
|
|
219
|
+
|
|
220
|
+
// Security settings
|
|
221
|
+
allowFileAccess: false,
|
|
222
|
+
allowFileAccessFromFileURLs: false,
|
|
223
|
+
mixedContentMode: "never",
|
|
224
|
+
|
|
225
|
+
// UI customization
|
|
226
|
+
decelerationRate: 'fast',
|
|
227
|
+
bounces: false,
|
|
228
|
+
|
|
229
|
+
// Any other WebView props...
|
|
230
|
+
}}
|
|
231
|
+
/>
|
|
232
|
+
```
|
|
233
|
+
|
|
234
|
+
### Performance Optimization Examples
|
|
235
|
+
|
|
236
|
+
```jsx
|
|
237
|
+
// High-performance mode
|
|
238
|
+
<SignatureCanvas
|
|
239
|
+
webviewProps={{
|
|
240
|
+
cacheEnabled: true,
|
|
241
|
+
androidLayerType: "hardware",
|
|
242
|
+
androidHardwareAccelerationDisabled: false,
|
|
243
|
+
}}
|
|
244
|
+
/>
|
|
245
|
+
|
|
246
|
+
// Low-memory mode
|
|
247
|
+
<SignatureCanvas
|
|
248
|
+
webviewProps={{
|
|
249
|
+
cacheEnabled: false,
|
|
250
|
+
androidLayerType: "software",
|
|
251
|
+
androidHardwareAccelerationDisabled: true,
|
|
252
|
+
}}
|
|
253
|
+
/>
|
|
254
|
+
```
|
|
255
|
+
|
|
256
|
+
## Error Handling (Enhanced!)
|
|
257
|
+
|
|
258
|
+
```jsx
|
|
259
|
+
const [error, setError] = useState(null);
|
|
260
|
+
|
|
261
|
+
const handleError = (error) => {
|
|
262
|
+
console.error('Signature error:', error);
|
|
263
|
+
setError(error.message);
|
|
264
|
+
// Error recovery is automatic, but you can handle it here
|
|
265
|
+
};
|
|
266
|
+
|
|
267
|
+
<SignatureCanvas
|
|
268
|
+
onError={handleError}
|
|
269
|
+
// Component automatically retries on recoverable errors
|
|
270
|
+
/>
|
|
271
|
+
|
|
272
|
+
{error && (
|
|
273
|
+
<Text style={{ color: 'red' }}>Error: {error}</Text>
|
|
274
|
+
)}
|
|
275
|
+
```
|
|
276
|
+
|
|
182
277
|
## Advanced Usage
|
|
183
278
|
|
|
184
279
|
### Using a Background Image
|
|
@@ -304,12 +399,162 @@ const styles = StyleSheet.create({
|
|
|
304
399
|
});
|
|
305
400
|
```
|
|
306
401
|
|
|
402
|
+
## Performance & Reliability
|
|
403
|
+
|
|
404
|
+
### Automatic Error Recovery
|
|
405
|
+
- **Smart retry logic** with exponential backoff
|
|
406
|
+
- **Circuit breaker pattern** to prevent cascading failures
|
|
407
|
+
- **Memory leak prevention** with automatic cleanup
|
|
408
|
+
- **Performance monitoring** with automatic optimization
|
|
409
|
+
|
|
410
|
+
### Performance Features
|
|
411
|
+
- **Debounced resize handling** for smooth interaction
|
|
412
|
+
- **Memory pressure detection** with adaptive optimization
|
|
413
|
+
- **Optimized rendering** with reduced re-renders
|
|
414
|
+
- **Device-specific optimization** based on hardware capabilities
|
|
415
|
+
|
|
416
|
+
### Security Enhancements
|
|
417
|
+
- **Configurable WebView security** via `webviewProps`
|
|
418
|
+
- **Input validation** for all methods and callbacks
|
|
419
|
+
- **XSS protection** with content security policies
|
|
420
|
+
- **File access restrictions** by default
|
|
421
|
+
|
|
422
|
+
## Migration Guide
|
|
423
|
+
|
|
424
|
+
### From v4.6.x to v4.7.x
|
|
425
|
+
|
|
426
|
+
This version is fully backward compatible. New features:
|
|
427
|
+
|
|
428
|
+
```jsx
|
|
429
|
+
// NEW: Enhanced error handling
|
|
430
|
+
<SignatureCanvas
|
|
431
|
+
onError={(error) => console.error(error)} // New callback
|
|
432
|
+
/>
|
|
433
|
+
|
|
434
|
+
// NEW: WebView customization
|
|
435
|
+
<SignatureCanvas
|
|
436
|
+
webviewProps={{ // New prop
|
|
437
|
+
cacheEnabled: false,
|
|
438
|
+
androidLayerType: "software"
|
|
439
|
+
}}
|
|
440
|
+
/>
|
|
441
|
+
```
|
|
442
|
+
|
|
443
|
+
## Troubleshooting
|
|
444
|
+
|
|
445
|
+
### Common Issues
|
|
446
|
+
|
|
447
|
+
**Issue**: Signature pad not loading
|
|
448
|
+
```jsx
|
|
449
|
+
// Solution: Add error handling and check WebView props
|
|
450
|
+
<SignatureCanvas
|
|
451
|
+
onError={(error) => console.log('Error:', error)}
|
|
452
|
+
onLoadEnd={() => console.log('Loaded successfully')}
|
|
453
|
+
webviewProps={{
|
|
454
|
+
startInLoadingState: true,
|
|
455
|
+
renderLoading: () => <ActivityIndicator />
|
|
456
|
+
}}
|
|
457
|
+
/>
|
|
458
|
+
```
|
|
459
|
+
|
|
460
|
+
**Issue**: Poor performance on older devices
|
|
461
|
+
```jsx
|
|
462
|
+
// Solution: Use low-performance mode
|
|
463
|
+
<SignatureCanvas
|
|
464
|
+
webviewProps={{
|
|
465
|
+
androidLayerType: "software",
|
|
466
|
+
androidHardwareAccelerationDisabled: true,
|
|
467
|
+
cacheEnabled: false
|
|
468
|
+
}}
|
|
469
|
+
/>
|
|
470
|
+
```
|
|
471
|
+
|
|
472
|
+
**Issue**: Memory issues
|
|
473
|
+
```jsx
|
|
474
|
+
// Solution: The component now handles this automatically
|
|
475
|
+
// But you can customize via webviewProps if needed
|
|
476
|
+
<SignatureCanvas
|
|
477
|
+
webviewProps={{
|
|
478
|
+
cacheEnabled: false, // Reduce memory usage
|
|
479
|
+
androidLayerType: "software" // Use software rendering
|
|
480
|
+
}}
|
|
481
|
+
/>
|
|
482
|
+
```
|
|
483
|
+
|
|
484
|
+
## API Reference
|
|
485
|
+
|
|
486
|
+
For detailed API documentation, see:
|
|
487
|
+
- [WEBVIEW_PROPS.md](./WEBVIEW_PROPS.md) - WebView customization guide
|
|
488
|
+
- [TypeScript definitions](./index.d.ts) - Complete type definitions
|
|
489
|
+
|
|
307
490
|
## Core Technology
|
|
308
491
|
|
|
309
492
|
This component is built on:
|
|
310
493
|
- [signature_pad.js](https://github.com/szimek/signature_pad) for the core signature functionality
|
|
311
494
|
- React Native WebView for cross-platform rendering
|
|
495
|
+
- Enhanced with performance monitoring and error recovery systems
|
|
496
|
+
|
|
497
|
+
## Contributing
|
|
498
|
+
|
|
499
|
+
Contributions are welcome! Please read our contributing guidelines and submit pull requests to help improve this component.
|
|
500
|
+
|
|
501
|
+
### Development Setup
|
|
502
|
+
|
|
503
|
+
```bash
|
|
504
|
+
# Clone the repository
|
|
505
|
+
git clone https://github.com/YanYuanFE/react-native-signature-canvas.git
|
|
506
|
+
|
|
507
|
+
# Install dependencies
|
|
508
|
+
cd react-native-signature-canvas
|
|
509
|
+
npm install
|
|
510
|
+
|
|
511
|
+
# Run example apps
|
|
512
|
+
cd example/expo-app
|
|
513
|
+
npm install && npm start
|
|
514
|
+
```
|
|
515
|
+
|
|
516
|
+
## Changelog
|
|
517
|
+
|
|
518
|
+
### v4.7.x (Latest)
|
|
519
|
+
- 🆕 Added `webviewProps` for WebView customization
|
|
520
|
+
- 🆕 Enhanced error handling with automatic recovery
|
|
521
|
+
- 🆕 Performance monitoring and optimization
|
|
522
|
+
- 🆕 Memory leak prevention
|
|
523
|
+
- 🆕 Improved TypeScript definitions
|
|
524
|
+
- 🔧 Fixed global variable pollution in WebView JavaScript
|
|
525
|
+
- 🔧 Added input validation for all methods
|
|
526
|
+
- ⚡ Optimized rendering performance
|
|
527
|
+
|
|
528
|
+
[View full changelog](./CHANGELOG.md)
|
|
312
529
|
|
|
313
530
|
## License
|
|
314
531
|
|
|
315
|
-
MIT
|
|
532
|
+
MIT License - see [LICENSE](./LICENSE) file for details.
|
|
533
|
+
|
|
534
|
+
|
|
535
|
+
## Buy Me a Coffee ☕
|
|
536
|
+
|
|
537
|
+
If you find this project helpful, consider supporting its development with cryptocurrency donations:
|
|
538
|
+
|
|
539
|
+
### Cryptocurrency Donations
|
|
540
|
+
|
|
541
|
+
| Currency | Address | QR Code |
|
|
542
|
+
|----------|---------|----------|
|
|
543
|
+
| **Bitcoin (BTC)** | `bc1phyz9agr0m9l2w9pd8w85w4da2jt3wl4cre7vv0qq4uesm3fv00pscu96tux` |  |
|
|
544
|
+
| **Ethereum (ETH)** | `0xf5dfe16b1e64e8e3a92063fb2922447e13b48945` |  |
|
|
545
|
+
| **Solana (SOL)** | `3VuhyeTj3hMSrmzq7NctHkgFxvJrmtAUQTzagEBEu3Vm` |  |
|
|
546
|
+
|
|
547
|
+
|
|
548
|
+
### Other Ways to Support
|
|
549
|
+
|
|
550
|
+
- ⭐ Star this repository
|
|
551
|
+
- 🐛 Report bugs and issues
|
|
552
|
+
- 💡 Suggest new features
|
|
553
|
+
- 🤝 Contribute code improvements
|
|
554
|
+
- 📢 Share this project with others
|
|
555
|
+
|
|
556
|
+
Your support helps maintain and improve this open-source project. Thank you! 🙏
|
|
557
|
+
|
|
558
|
+
---
|
|
559
|
+
|
|
560
|
+
**Made with ❤️ for the React Native community**
|