Skip to content

Commit 1f7b813

Browse files
committed
init base draw maps sdk❤️
1 parent be9e927 commit 1f7b813

File tree

15 files changed

+212
-48
lines changed

15 files changed

+212
-48
lines changed

example/babel.config.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,8 @@ module.exports = function (api) {
55
api.cache(true);
66

77
return {
8-
presets: ['babel-preset-expo'],
8+
presets: ['babel-preset-expo', '@babel/typescript'],
9+
910
plugins: [
1011
[
1112
'module-resolver',

example/package.json

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,11 @@
2323
"devDependencies": {
2424
"@babel/core": "~7.12.10",
2525
"@babel/runtime": "^7.9.6",
26+
"@types/react": "~16.9.35",
27+
"@types/react-native": "~0.63.2",
2628
"babel-plugin-module-resolver": "^4.0.0",
2729
"babel-preset-expo": "8.3.0",
28-
"expo-cli": "^4.0.13"
30+
"expo-cli": "^4.0.13",
31+
"typescript": "~4.0.0"
2932
}
3033
}

example/src/App.tsx

Lines changed: 3 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,20 @@
11
import * as React from 'react';
22

33
import { StyleSheet, View, Text } from 'react-native';
4-
import MapsDraw from 'react-native-maps-draw';
4+
import Map from 'react-native-maps-draw';
55

66
export default function App() {
7-
const [result, setResult] = React.useState<number | undefined>();
8-
9-
React.useEffect(() => {
10-
MapsDraw.multiply(3, 7).then(setResult);
11-
}, []);
12-
137
return (
148
<View style={styles.container}>
15-
<Text>Result: {result}</Text>
9+
<Map style={{ flex: 1 }} />
10+
<Text>3</Text>
1611
</View>
1712
);
1813
}
1914

2015
const styles = StyleSheet.create({
2116
container: {
2217
flex: 1,
23-
alignItems: 'center',
24-
justifyContent: 'center',
2518
},
2619
box: {
2720
width: 60,

package.json

Lines changed: 17 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,8 @@
2525
"test": "jest",
2626
"typescript": "tsc --noEmit",
2727
"lint": "eslint \"**/*.{js,ts,tsx}\"",
28-
"prepare": "bob build",
28+
"prepare": "bob build && yarn copy-dts",
29+
"copy-dts": "copyfiles -u 1 \"src/**/*.d.ts\" lib/typescript",
2930
"release": "release-it",
3031
"example": "yarn --cwd example",
3132
"pods": "cd example && pod-install --quiet",
@@ -50,9 +51,11 @@
5051
"@commitlint/config-conventional": "^11.0.0",
5152
"@react-native-community/eslint-config": "^2.0.0",
5253
"@release-it/conventional-changelog": "^2.0.0",
53-
"@types/jest": "^26.0.0",
54-
"@types/react": "^16.9.19",
55-
"@types/react-native": "0.62.13",
54+
"@types/jest": "^26.0.23",
55+
"@types/node": "^15.12.1",
56+
"@types/react": "^17.0.9",
57+
"@types/react-native": "^0.64.10",
58+
"@types/react-test-renderer": "^17.0.1",
5659
"commitlint": "^11.0.0",
5760
"eslint": "^7.2.0",
5861
"eslint-config-prettier": "^7.0.0",
@@ -63,9 +66,8 @@
6366
"prettier": "^2.0.5",
6467
"react": "16.13.1",
6568
"react-native": "0.63.4",
66-
"react-native-builder-bob": "^0.18.0",
6769
"release-it": "^14.2.2",
68-
"typescript": "^4.1.3"
70+
"typescript": "^4.3.2"
6971
},
7072
"peerDependencies": {
7173
"react": "*",
@@ -136,18 +138,20 @@
136138
"trailingComma": "es5",
137139
"useTabs": false
138140
},
139-
"react-native-builder-bob": {
141+
"@react-native-community/bob": {
140142
"source": "src",
141143
"output": "lib",
142144
"targets": [
143145
"commonjs",
144146
"module",
145-
[
146-
"typescript",
147-
{
148-
"project": "tsconfig.build.json"
149-
}
150-
]
147+
"typescript"
151148
]
149+
},
150+
"dependencies": {
151+
"@react-native-community/bob": "^0.17.1",
152+
"react-native-gesture-handler": "^1.10.3",
153+
"react-native-maps": "^0.28.0",
154+
"react-native-reanimated": "^2.2.0",
155+
"react-native-svg": "^12.1.1"
152156
}
153157
}

src/canvas/canvas.tsx

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
import { useWindowDimensions } from 'react-native';
2+
import Svg, { Polyline } from 'react-native-svg';
3+
import type { TouchPoint } from '../types';
4+
import React, { FC, useMemo } from 'react';
5+
6+
interface CanvasProps {
7+
path: TouchPoint[];
8+
color?: string;
9+
widthLine?: number;
10+
}
11+
12+
const Canvas: FC<CanvasProps> = ({ path, color, widthLine }) => {
13+
const { width, height } = useWindowDimensions();
14+
const points = useMemo(
15+
() =>
16+
path.map((item: TouchPoint) => `${item.x - 10},${item.y + 40}`).join(' '),
17+
[path]
18+
);
19+
20+
return (
21+
<Svg height="100%" width="100%" viewBox={`0 0 ${width} ${height}`}>
22+
<Polyline
23+
fill="none"
24+
stroke={color}
25+
points={points}
26+
strokeWidth={widthLine}
27+
/>
28+
</Svg>
29+
);
30+
};
31+
32+
export { Canvas };

src/canvas/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
export * from './canvas';

src/gesture/gesture-responder.tsx

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
import React, { FC, useRef } from 'react';
2+
import {
3+
PanResponder,
4+
StyleSheet,
5+
View,
6+
GestureResponderEvent,
7+
PanResponderGestureState,
8+
} from 'react-native';
9+
import type { TouchPoint } from '../types';
10+
11+
interface GestureProps {
12+
onEndTouchEvents?: (
13+
event: GestureResponderEvent,
14+
state: PanResponderGestureState,
15+
points: TouchPoint[]
16+
) => void;
17+
onStartTouchEvents?: (
18+
event: GestureResponderEvent,
19+
state: PanResponderGestureState
20+
) => void;
21+
onChangeTouchEvents: (points: TouchPoint[]) => void;
22+
}
23+
24+
const GestureHandler: FC<GestureProps> = ({
25+
onEndTouchEvents,
26+
onStartTouchEvents,
27+
onChangeTouchEvents,
28+
}) => {
29+
const pathRef = useRef<TouchPoint[]>([]);
30+
31+
const panResponder = useRef(
32+
PanResponder.create({
33+
onStartShouldSetPanResponder: () => true,
34+
onStartShouldSetPanResponderCapture: () => true,
35+
onMoveShouldSetPanResponder: () => true,
36+
onMoveShouldSetPanResponderCapture: () => true,
37+
38+
onPanResponderGrant: (e, gestureState) => {
39+
pathRef.current = [];
40+
onStartTouchEvents && onStartTouchEvents(e, gestureState);
41+
},
42+
onPanResponderMove: (event) => {
43+
pathRef.current.push({
44+
x: event.nativeEvent.locationX,
45+
y: event.nativeEvent.locationY,
46+
});
47+
onChangeTouchEvents([...pathRef.current]);
48+
},
49+
onPanResponderRelease: (e, gestureState) => {
50+
const points = [...pathRef.current];
51+
onChangeTouchEvents(points);
52+
onEndTouchEvents && onEndTouchEvents(e, gestureState, points);
53+
},
54+
})
55+
).current;
56+
57+
return <View style={StyleSheet.absoluteFill} {...panResponder.panHandlers} />;
58+
};
59+
60+
export { GestureHandler };

src/gesture/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
export * from './gesture-responder';

src/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
export { default } from './maps';

src/index.tsx

Lines changed: 0 additions & 5 deletions
This file was deleted.

0 commit comments

Comments
 (0)