Skip to content

Commit

Permalink
Merge pull request #7 from KeyValueSoftwareSystems/add-stroke-config
Browse files Browse the repository at this point in the history
Add stroke config property so that stroke can be customized
  • Loading branch information
nirmalkeyvalue authored Oct 16, 2023
2 parents 9335335 + 4bf158b commit 89ceb70
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 8 deletions.
16 changes: 10 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,24 +5,28 @@ React native package to capture user scribbling on screen and converting it to a
## Installation

```sh
npm install react-native-scribble
npm i @keyvaluesystems/react-native-scribble
```

## Usage

```jsx
import { SvgCapture ,useSvgCapture } from '@keyvaluesystems/react-native-scribble';
// ...
const signatureProps = useSvgCapture();
const { clearPad, getFilePath } = signatureProps;

const handleFileGeneration = async () => {
const filePath = await getFilePath();
};
// ...
<>
<SvgCapture {...signatureProps} />
<Button title="Clear" onClick={clearPad} />
<Button title="Save" onClick={handleFileGeneration} />
</>
return (
<>
<SvgCapture {...signatureProps} />
<Button title="Clear" onClick={clearPad} />
<Button title="Save" onClick={handleFileGeneration} />
</>
);
```

## Contributing
Expand Down
16 changes: 14 additions & 2 deletions src/components/SvgCapture.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import React from 'react';
import type { ColorValue } from 'react-native';
import {
type GestureResponderEvent,
type LayoutChangeEvent,
Expand All @@ -8,10 +9,18 @@ import {
type StyleProp,
} from 'react-native';
import Svg, { G, Polyline } from 'react-native-svg';
import {
DEFAULT_STROKE_COLOR,
DEFAULT_STROKE_WIDTH,
} from '../constants/common';

type CaptureSignatureProps = {
paths: number[][];
canvasStyle?: StyleProp<ViewStyle>;
strokeConfig?: {
strokeColor: ColorValue;
strokeWidth: number;
};
handleOnTouchStart: (e: GestureResponderEvent) => void;
handleOnTouchMove: (e: GestureResponderEvent) => void;
handleLayout: (e: LayoutChangeEvent) => void;
Expand All @@ -20,6 +29,7 @@ type CaptureSignatureProps = {
const SvgCapture = ({
paths,
canvasStyle,
strokeConfig,
handleOnTouchStart,
handleOnTouchMove,
handleLayout,
Expand All @@ -40,8 +50,10 @@ const SvgCapture = ({
key={JSON.stringify(item)}
points={item}
fill="transparent"
stroke="blue"
strokeWidth="3"
stroke={strokeConfig?.strokeColor || DEFAULT_STROKE_COLOR}
strokeWidth={
strokeConfig?.strokeWidth || DEFAULT_STROKE_WIDTH
}
/>
);
})}
Expand Down
4 changes: 4 additions & 0 deletions src/constants/common.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
const DEFAULT_STROKE_WIDTH = 3;
const DEFAULT_STROKE_COLOR = 'black';

export { DEFAULT_STROKE_COLOR, DEFAULT_STROKE_WIDTH };

0 comments on commit 89ceb70

Please sign in to comment.