Skip to content

Commit 89ceb70

Browse files
Merge pull request #7 from KeyValueSoftwareSystems/add-stroke-config
Add stroke config property so that stroke can be customized
2 parents 9335335 + 4bf158b commit 89ceb70

File tree

3 files changed

+28
-8
lines changed

3 files changed

+28
-8
lines changed

README.md

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,24 +5,28 @@ React native package to capture user scribbling on screen and converting it to a
55
## Installation
66

77
```sh
8-
npm install react-native-scribble
8+
npm i @keyvaluesystems/react-native-scribble
99
```
1010

1111
## Usage
1212

1313
```jsx
14+
import { SvgCapture ,useSvgCapture } from '@keyvaluesystems/react-native-scribble';
15+
// ...
1416
const signatureProps = useSvgCapture();
1517
const { clearPad, getFilePath } = signatureProps;
1618

1719
const handleFileGeneration = async () => {
1820
const filePath = await getFilePath();
1921
};
2022
// ...
21-
<>
22-
<SvgCapture {...signatureProps} />
23-
<Button title="Clear" onClick={clearPad} />
24-
<Button title="Save" onClick={handleFileGeneration} />
25-
</>
23+
return (
24+
<>
25+
<SvgCapture {...signatureProps} />
26+
<Button title="Clear" onClick={clearPad} />
27+
<Button title="Save" onClick={handleFileGeneration} />
28+
</>
29+
);
2630
```
2731

2832
## Contributing

src/components/SvgCapture.tsx

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import React from 'react';
2+
import type { ColorValue } from 'react-native';
23
import {
34
type GestureResponderEvent,
45
type LayoutChangeEvent,
@@ -8,10 +9,18 @@ import {
89
type StyleProp,
910
} from 'react-native';
1011
import Svg, { G, Polyline } from 'react-native-svg';
12+
import {
13+
DEFAULT_STROKE_COLOR,
14+
DEFAULT_STROKE_WIDTH,
15+
} from '../constants/common';
1116

1217
type CaptureSignatureProps = {
1318
paths: number[][];
1419
canvasStyle?: StyleProp<ViewStyle>;
20+
strokeConfig?: {
21+
strokeColor: ColorValue;
22+
strokeWidth: number;
23+
};
1524
handleOnTouchStart: (e: GestureResponderEvent) => void;
1625
handleOnTouchMove: (e: GestureResponderEvent) => void;
1726
handleLayout: (e: LayoutChangeEvent) => void;
@@ -20,6 +29,7 @@ type CaptureSignatureProps = {
2029
const SvgCapture = ({
2130
paths,
2231
canvasStyle,
32+
strokeConfig,
2333
handleOnTouchStart,
2434
handleOnTouchMove,
2535
handleLayout,
@@ -40,8 +50,10 @@ const SvgCapture = ({
4050
key={JSON.stringify(item)}
4151
points={item}
4252
fill="transparent"
43-
stroke="blue"
44-
strokeWidth="3"
53+
stroke={strokeConfig?.strokeColor || DEFAULT_STROKE_COLOR}
54+
strokeWidth={
55+
strokeConfig?.strokeWidth || DEFAULT_STROKE_WIDTH
56+
}
4557
/>
4658
);
4759
})}

src/constants/common.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
const DEFAULT_STROKE_WIDTH = 3;
2+
const DEFAULT_STROKE_COLOR = 'black';
3+
4+
export { DEFAULT_STROKE_COLOR, DEFAULT_STROKE_WIDTH };

0 commit comments

Comments
 (0)