Skip to content

Commit d0118b0

Browse files
committed
feat: done
1 parent c765608 commit d0118b0

File tree

8 files changed

+255
-144
lines changed

8 files changed

+255
-144
lines changed

CONTRIBUTING.md

Lines changed: 79 additions & 93 deletions
Original file line numberDiff line numberDiff line change
@@ -1,113 +1,99 @@
1-
# Contributing
1+
# react-native-apple-mapkit-directions
22

3-
Contributions are always welcome, no matter how large or small!
3+
React Native wrapper for Apple MapKit Directions.
4+
You can get distance, expectedTravelTime, name, advisoryNotices or coordinates.
45

5-
We want this community to be friendly and respectful to each other. Please follow it in all your interactions with the project. Before contributing, please read the [code of conduct](./CODE_OF_CONDUCT.md).
6-
7-
## Development workflow
8-
9-
To get started with the project, run `yarn` in the root directory to install the required dependencies for each package:
10-
11-
```sh
12-
yarn
13-
```
14-
15-
> While it's possible to use [`npm`](https://github.com/npm/cli), the tooling is built around [`yarn`](https://classic.yarnpkg.com/), so you'll have an easier time if you use `yarn` for development.
16-
17-
While developing, you can run the [example app](/example/) to test your changes. Any changes you make in your library's JavaScript code will be reflected in the example app without a rebuild. If you change any native code, then you'll need to rebuild the example app.
18-
19-
To start the packager:
20-
21-
```sh
22-
yarn example start
23-
```
24-
25-
To run the example app on Android:
26-
27-
```sh
28-
yarn example android
29-
```
30-
31-
To run the example app on iOS:
32-
33-
```sh
34-
yarn example ios
35-
```
36-
37-
Make sure your code passes TypeScript and ESLint. Run the following to verify:
6+
## Installation
387

398
```sh
40-
yarn typescript
41-
yarn lint
9+
npm install react-native-apple-mapkit-directions
4210
```
4311

44-
To fix formatting errors, run the following:
12+
or
4513

4614
```sh
47-
yarn lint --fix
15+
yarn add react-native-apple-mapkit-directions
4816
```
4917

50-
Remember to add tests for your change if possible. Run the unit tests by:
51-
52-
```sh
53-
yarn test
18+
## Usage
19+
20+
```js
21+
import { getAppleMapKitDirections } from 'react-native-maps-apple-directions';
22+
23+
// ...
24+
const origin = {
25+
latitude: 55.751244,
26+
longitude: 37.618423,
27+
};
28+
const destination = {
29+
latitude: 59.9375,
30+
longitude: 30.308611,
31+
};
32+
const transitType = MapKitTransit.AUTOMOBILE;
33+
const points = await getAppleMapKitDirections(origin, destination, transitType);
5434
```
5535

56-
To edit the Objective-C or Swift files, open `example/ios/AppleMapkitDirectionsExample.xcworkspace` in XCode and find the source files at `Pods > Development Pods > react-native-apple-mapkit-directions`.
57-
58-
To edit the Java or Kotlin files, open `example/android` in Android studio and find the source files at `react-native-apple-mapkit-directions` under `Android`.
59-
60-
### Commit message convention
61-
62-
We follow the [conventional commits specification](https://www.conventionalcommits.org/en) for our commit messages:
63-
64-
- `fix`: bug fixes, e.g. fix crash due to deprecated method.
65-
- `feat`: new features, e.g. add new method to the module.
66-
- `refactor`: code refactor, e.g. migrate from class components to hooks.
67-
- `docs`: changes into documentation, e.g. add usage example for the module..
68-
- `test`: adding or updating tests, e.g. add integration tests using detox.
69-
- `chore`: tooling changes, e.g. change CI config.
70-
71-
Our pre-commit hooks verify that your commit message matches this format when committing.
36+
You can use it with react-native-maps
37+
38+
```js
39+
import * as React from 'react';
40+
41+
import { StyleSheet } from 'react-native';
42+
import MapView, { LatLng, Polyline } from 'react-native-maps';
43+
import {
44+
getAppleMapKitDirections,
45+
MapKitTransit,
46+
} from 'react-native-maps-apple-directions';
47+
48+
export default function App() {
49+
const styles = StyleSheet.create({
50+
map: {
51+
...StyleSheet.absoluteFillObject,
52+
},
53+
});
54+
const origin = {
55+
latitude: 55.751244,
56+
longitude: 37.618423,
57+
};
58+
const destination = {
59+
latitude: 59.9375,
60+
longitude: 30.308611,
61+
};
62+
const transitType = MapKitTransit.AUTOMOBILE;
63+
const [state, setState] = React.useState<LatLng[]>();
64+
React.useEffect(() => {
65+
const getPoints = async () => {
66+
try {
67+
const points = await getAppleMapKitDirections(
68+
origin,
69+
destination,
70+
transitType
71+
);
72+
setState(points.coordinates);
73+
} catch (error) {
74+
console.log('error', error);
75+
}
76+
};
77+
getPoints();
78+
}, []);
79+
80+
return (
81+
<MapView style={styles.map}>
82+
{state && <Polyline coordinates={state} />}
83+
</MapView>
84+
);
85+
}
7286

73-
### Linting and tests
74-
75-
[ESLint](https://eslint.org/), [Prettier](https://prettier.io/), [TypeScript](https://www.typescriptlang.org/)
76-
77-
We use [TypeScript](https://www.typescriptlang.org/) for type checking, [ESLint](https://eslint.org/) with [Prettier](https://prettier.io/) for linting and formatting the code, and [Jest](https://jestjs.io/) for testing.
78-
79-
Our pre-commit hooks verify that the linter and tests pass when committing.
80-
81-
### Publishing to npm
82-
83-
We use [release-it](https://github.com/release-it/release-it) to make it easier to publish new versions. It handles common tasks like bumping version based on semver, creating tags and releases etc.
84-
85-
To publish new versions, run the following:
86-
87-
```sh
88-
yarn release
8987
```
9088

91-
### Scripts
92-
93-
The `package.json` file contains various scripts for common tasks:
89+
## Contributing
9490

95-
- `yarn bootstrap`: setup project by installing all dependencies and pods.
96-
- `yarn typescript`: type-check files with TypeScript.
97-
- `yarn lint`: lint files with ESLint.
98-
- `yarn test`: run unit tests with Jest.
99-
- `yarn example start`: start the Metro server for the example app.
100-
- `yarn example android`: run the example app on Android.
101-
- `yarn example ios`: run the example app on iOS.
91+
See the [contributing guide](CONTRIBUTING.md) to learn how to contribute to the repository and the development workflow.
10292

103-
### Sending a pull request
93+
## License
10494

105-
> **Working on your first pull request?** You can learn how from this _free_ series: [How to Contribute to an Open Source Project on GitHub](https://app.egghead.io/playlists/how-to-contribute-to-an-open-source-project-on-github).
95+
MIT
10696

107-
When you're sending a pull request:
97+
---
10898

109-
- Prefer small pull requests focused on one change.
110-
- Verify that linters and tests are passing.
111-
- Review the documentation to make sure it looks good.
112-
- Follow the pull request template when opening a pull request.
113-
- For pull requests that change the API or implementation, discuss with maintainers first by opening an issue.
99+
Made with [create-react-native-library](https://github.com/callstack/react-native-builder-bob)

example/ios/Podfile.lock

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -304,6 +304,8 @@ PODS:
304304
- glog
305305
- react-native-apple-mapkit-directions (0.1.0):
306306
- React-Core
307+
- react-native-maps (1.3.2):
308+
- React-Core
307309
- React-perflogger (0.70.5)
308310
- React-RCTActionSheet (0.70.5):
309311
- React-Core/RCTActionSheetHeaders (= 0.70.5)
@@ -423,6 +425,7 @@ DEPENDENCIES:
423425
- React-jsinspector (from `../node_modules/react-native/ReactCommon/jsinspector`)
424426
- React-logger (from `../node_modules/react-native/ReactCommon/logger`)
425427
- react-native-apple-mapkit-directions (from `../..`)
428+
- react-native-maps (from `../node_modules/react-native-maps`)
426429
- React-perflogger (from `../node_modules/react-native/ReactCommon/reactperflogger`)
427430
- React-RCTActionSheet (from `../node_modules/react-native/Libraries/ActionSheetIOS`)
428431
- React-RCTAnimation (from `../node_modules/react-native/Libraries/NativeAnimation`)
@@ -500,6 +503,8 @@ EXTERNAL SOURCES:
500503
:path: "../node_modules/react-native/ReactCommon/logger"
501504
react-native-apple-mapkit-directions:
502505
:path: "../.."
506+
react-native-maps:
507+
:path: "../node_modules/react-native-maps"
503508
React-perflogger:
504509
:path: "../node_modules/react-native/ReactCommon/reactperflogger"
505510
React-RCTActionSheet:
@@ -563,6 +568,7 @@ SPEC CHECKSUMS:
563568
React-jsinspector: badd81696361249893a80477983e697aab3c1a34
564569
React-logger: fdda34dd285bdb0232e059b19d9606fa0ec3bb9c
565570
react-native-apple-mapkit-directions: 7eeaf4f5447b214e92db10bc619216abbd370279
571+
react-native-maps: 085f614cf14d3637b2048bb9752da5b1c27c2886
566572
React-perflogger: e68d3795cf5d247a0379735cbac7309adf2fb931
567573
React-RCTActionSheet: 05452c3b281edb27850253db13ecd4c5a65bc247
568574
React-RCTAnimation: 578eebac706428e68466118e84aeacf3a282b4da

example/package.json

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,12 +10,13 @@
1010
},
1111
"dependencies": {
1212
"react": "18.1.0",
13-
"react-native": "0.70.5"
13+
"react-native": "0.70.5",
14+
"react-native-maps": "^1.3.2"
1415
},
1516
"devDependencies": {
1617
"@babel/core": "^7.12.9",
1718
"@babel/runtime": "^7.12.5",
18-
"metro-react-native-babel-preset": "0.72.3",
19-
"babel-plugin-module-resolver": "^4.1.0"
19+
"babel-plugin-module-resolver": "^4.1.0",
20+
"metro-react-native-babel-preset": "0.72.3"
2021
}
21-
}
22+
}

example/src/App.tsx

Lines changed: 38 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,31 +1,48 @@
11
import * as React from 'react';
22

3-
import { StyleSheet, View, Text } from 'react-native';
4-
import { multiply } from 'react-native-apple-mapkit-directions';
3+
import { StyleSheet } from 'react-native';
4+
import {
5+
getAppleMapKitDirections,
6+
MapKitTransit,
7+
} from 'react-native-apple-mapkit-directions';
8+
import MapView, { LatLng, Polyline } from 'react-native-maps';
59

610
export default function App() {
7-
const [result, setResult] = React.useState<number | undefined>();
8-
11+
const styles = StyleSheet.create({
12+
map: {
13+
...StyleSheet.absoluteFillObject,
14+
},
15+
});
16+
const origin = {
17+
latitude: 55.751244,
18+
longitude: 37.618423,
19+
};
20+
const destination = {
21+
latitude: 59.9375,
22+
longitude: 30.308611,
23+
};
24+
const transitType = MapKitTransit.AUTOMOBILE;
25+
const [state, setState] = React.useState<LatLng[]>();
926
React.useEffect(() => {
10-
multiply(3, 7).then(setResult);
27+
const getPoints = async () => {
28+
try {
29+
const points = await getAppleMapKitDirections(
30+
origin,
31+
destination,
32+
transitType
33+
);
34+
setState(points.coordinates);
35+
} catch (error) {
36+
console.log('error', error);
37+
}
38+
};
39+
getPoints();
40+
// eslint-disable-next-line react-hooks/exhaustive-deps
1141
}, []);
1242

1343
return (
14-
<View style={styles.container}>
15-
<Text>Result: {result}</Text>
16-
</View>
44+
<MapView style={styles.map}>
45+
{state && <Polyline coordinates={state} />}
46+
</MapView>
1747
);
1848
}
19-
20-
const styles = StyleSheet.create({
21-
container: {
22-
flex: 1,
23-
alignItems: 'center',
24-
justifyContent: 'center',
25-
},
26-
box: {
27-
width: 60,
28-
height: 60,
29-
marginVertical: 20,
30-
},
31-
});

example/yarn.lock

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1032,6 +1032,11 @@
10321032
resolved "https://registry.yarnpkg.com/@sinclair/typebox/-/typebox-0.24.51.tgz#645f33fe4e02defe26f2f5c0410e1c094eac7f5f"
10331033
integrity sha512-1P1OROm/rdubP5aFDSZQILU0vrLCJ4fvHt6EoqHEM+2D/G5MK3bIaymUKLit8Js9gbns5UyJnkP/TZROLw4tUA==
10341034

1035+
"@types/geojson@^7946.0.8":
1036+
version "7946.0.10"
1037+
resolved "https://registry.yarnpkg.com/@types/geojson/-/geojson-7946.0.10.tgz#6dfbf5ea17142f7f9a043809f1cd4c448cb68249"
1038+
integrity sha512-Nmh0K3iWQJzniTuPRcJn5hxXkfB1T1pgB89SBig5PlJQU5yocazeu4jATJlaA0GYFKWMqDdvYemoSnF2pXgLVA==
1039+
10351040
"@types/istanbul-lib-coverage@*", "@types/istanbul-lib-coverage@^2.0.0":
10361041
version "2.0.4"
10371042
resolved "https://registry.yarnpkg.com/@types/istanbul-lib-coverage/-/istanbul-lib-coverage-2.0.4.tgz#8467d4b3c087805d63580480890791277ce35c44"
@@ -3357,6 +3362,13 @@ react-native-gradle-plugin@^0.70.3:
33573362
resolved "https://registry.yarnpkg.com/react-native-gradle-plugin/-/react-native-gradle-plugin-0.70.3.tgz#cbcf0619cbfbddaa9128701aa2d7b4145f9c4fc8"
33583363
integrity sha512-oOanj84fJEXUg9FoEAQomA8ISG+DVIrTZ3qF7m69VQUJyOGYyDZmPqKcjvRku4KXlEH6hWO9i4ACLzNBh8gC0A==
33593364

3365+
react-native-maps@^1.3.2:
3366+
version "1.3.2"
3367+
resolved "https://registry.yarnpkg.com/react-native-maps/-/react-native-maps-1.3.2.tgz#8e30bfd9d934de02827253e5cde6c08a04f6356c"
3368+
integrity sha512-NB7HGRZOgxxXCWzrhIVucx/bsrEWANvk3DLci1ov4P9MQnEVQYQCCkTxsnaEvO191GeBOCRDyYn6jckqbfMtmg==
3369+
dependencies:
3370+
"@types/geojson" "^7946.0.8"
3371+
33603372
33613373
version "0.70.5"
33623374
resolved "https://registry.yarnpkg.com/react-native/-/react-native-0.70.5.tgz#f60540b21d338891086e0a834e331c124dd1f55c"

ios/AppleMapkitDirections.m

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,12 @@
22

33
@interface RCT_EXTERN_MODULE(AppleMapkitDirections, NSObject)
44

5-
RCT_EXTERN_METHOD(multiply:(float)a withB:(float)b
6-
withResolver:(RCTPromiseResolveBlock)resolve
7-
withRejecter:(RCTPromiseRejectBlock)reject)
8-
5+
RCT_EXTERN_METHOD(getAppleMapKitDirections:
6+
(NSDictionary *)origin
7+
toDestination:(NSDictionary *)destination
8+
byTransitType:(NSString *)transitType
9+
withResolver:(RCTPromiseResolveBlock)resolve
10+
withRejecter:(RCTPromiseRejectBlock)reject)
911
+ (BOOL)requiresMainQueueSetup
1012
{
1113
return NO;

0 commit comments

Comments
 (0)