Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: allow background canvas styles to be passed as a prop #6

Merged
merged 1 commit into from
Oct 16, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 5 additions & 2 deletions src/components/SvgCapture.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,26 +4,30 @@ import {
type LayoutChangeEvent,
View,
StyleSheet,
type ViewStyle,
type StyleProp,
} from 'react-native';
import Svg, { G, Polyline } from 'react-native-svg';

type CaptureSignatureProps = {
paths: number[][];
canvasStyle?: StyleProp<ViewStyle>;
handleOnTouchStart: (e: GestureResponderEvent) => void;
handleOnTouchMove: (e: GestureResponderEvent) => void;
handleLayout: (e: LayoutChangeEvent) => void;
};

const SvgCapture = ({
paths,
canvasStyle,
handleOnTouchStart,
handleOnTouchMove,
handleLayout,
}: CaptureSignatureProps) => {
return (
<View style={styles.canvasAndControlWrapper}>
<View
style={styles.canvas}
style={[styles.canvas, canvasStyle]}
onTouchStart={handleOnTouchStart}
onTouchMove={handleOnTouchMove}
onLayout={handleLayout}
Expand Down Expand Up @@ -55,7 +59,6 @@ const styles = StyleSheet.create({
},
canvas: {
flex: 1,
backgroundColor: '#e0e0e0',
},
});

Expand Down
10 changes: 8 additions & 2 deletions src/hooks/useSvgCapture.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ const useSvgCapture = () => {

const handleSetLowestPoints = (x: number, y: number) => {
if (x < lowestPoints.current.x) {
lowestPoints.current.x = y;
lowestPoints.current.x = x;
}
if (y < lowestPoints.current.y) {
lowestPoints.current.y = y;
Expand Down Expand Up @@ -90,9 +90,14 @@ const useSvgCapture = () => {
</svg>`;
};

const getFilePath = () => {
const getSvgAsString = () => {
const cleanedSvgPath = getCleanedSvgImage();
const svgString = pathsToSVG(cleanedSvgPath);
return svgString;
};

const getFilePath = async (): Promise<string> => {
const svgString = getSvgAsString();
const svgBlob = svgStringToBlob(svgString);
return svgBlob;
};
Expand All @@ -104,6 +109,7 @@ const useSvgCapture = () => {
handleLayout,
clearPad,
getFilePath,
getSvgAsString,
};
};

Expand Down
Loading