Skip to content

Commit 7b8f0c2

Browse files
Merge pull request #6 from KeyValueSoftwareSystems/fix-canvas-background-style
fix: allow background canvas styles to be passed as a prop
2 parents 4a9c911 + 79b314b commit 7b8f0c2

File tree

2 files changed

+13
-4
lines changed

2 files changed

+13
-4
lines changed

src/components/SvgCapture.tsx

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,26 +4,30 @@ import {
44
type LayoutChangeEvent,
55
View,
66
StyleSheet,
7+
type ViewStyle,
8+
type StyleProp,
79
} from 'react-native';
810
import Svg, { G, Polyline } from 'react-native-svg';
911

1012
type CaptureSignatureProps = {
1113
paths: number[][];
14+
canvasStyle?: StyleProp<ViewStyle>;
1215
handleOnTouchStart: (e: GestureResponderEvent) => void;
1316
handleOnTouchMove: (e: GestureResponderEvent) => void;
1417
handleLayout: (e: LayoutChangeEvent) => void;
1518
};
1619

1720
const SvgCapture = ({
1821
paths,
22+
canvasStyle,
1923
handleOnTouchStart,
2024
handleOnTouchMove,
2125
handleLayout,
2226
}: CaptureSignatureProps) => {
2327
return (
2428
<View style={styles.canvasAndControlWrapper}>
2529
<View
26-
style={styles.canvas}
30+
style={[styles.canvas, canvasStyle]}
2731
onTouchStart={handleOnTouchStart}
2832
onTouchMove={handleOnTouchMove}
2933
onLayout={handleLayout}
@@ -55,7 +59,6 @@ const styles = StyleSheet.create({
5559
},
5660
canvas: {
5761
flex: 1,
58-
backgroundColor: '#e0e0e0',
5962
},
6063
});
6164

src/hooks/useSvgCapture.ts

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ const useSvgCapture = () => {
88

99
const handleSetLowestPoints = (x: number, y: number) => {
1010
if (x < lowestPoints.current.x) {
11-
lowestPoints.current.x = y;
11+
lowestPoints.current.x = x;
1212
}
1313
if (y < lowestPoints.current.y) {
1414
lowestPoints.current.y = y;
@@ -90,9 +90,14 @@ const useSvgCapture = () => {
9090
</svg>`;
9191
};
9292

93-
const getFilePath = () => {
93+
const getSvgAsString = () => {
9494
const cleanedSvgPath = getCleanedSvgImage();
9595
const svgString = pathsToSVG(cleanedSvgPath);
96+
return svgString;
97+
};
98+
99+
const getFilePath = async (): Promise<string> => {
100+
const svgString = getSvgAsString();
96101
const svgBlob = svgStringToBlob(svgString);
97102
return svgBlob;
98103
};
@@ -104,6 +109,7 @@ const useSvgCapture = () => {
104109
handleLayout,
105110
clearPad,
106111
getFilePath,
112+
getSvgAsString,
107113
};
108114
};
109115

0 commit comments

Comments
 (0)