Skip to content

Commit a68c72f

Browse files
chore: update documentation with location permissions and listener methods for navigation
1 parent ef1cdab commit a68c72f

File tree

5 files changed

+135
-186
lines changed

5 files changed

+135
-186
lines changed

docs/README.md

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,12 @@ This will automatically configure the necessary settings for Mapbox integration
9292
<string>location</string>
9393
</array>
9494
```
95+
5. Add NSLocationWhenInUseUsageDescription to `Info.plist` with a description of why your app needs access to the user's location.
9596

97+
```
98+
<key>NSLocationWhenInUseUsageDescription</key>
99+
<string>This app requires access to your location for navigation purposes.</string>
100+
```
96101
* ### Android Specific Instructions
97102

98103
1. Place your secret token in your android app's top level `gradle.properties` or `«USER_HOME»/.gradle/gradle.properties` file
@@ -132,6 +137,13 @@ This will automatically configure the necessary settings for Mapbox integration
132137
<string name="mapbox_access_token" translatable="false" tools:ignore="UnusedResources">YOUR_MAPBOX_ACCESS_TOKEN</string>
133138
</resources>
134139
```
140+
4. Add the following permissions to your `AndroidManifest.xml` file:
141+
142+
```xml
143+
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
144+
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
145+
<uses-permission android:name="android.permission.FOREGROUND_SERVICE" />
146+
```
135147

136148
For more details installation you can read the [Official docs of Mapbox](https://docs.mapbox.com/android/navigation/guides/installation).
137149

@@ -157,6 +169,11 @@ import { MapboxTurnByTurnNavigationView } from "react-native-mapbox-turn-by-turn
157169
/>
158170
```
159171
Please refer to the [example](_media/App.tsx) project for more detailed usage and configuration options.
172+
173+
## Docs
174+
175+
For detailed documentation please refer to the [docs](_media/globals.md) directory.
176+
160177
## Contributing
161178

162179
Contributions are welcome! Please see the [contributing guide](_media/CONTRIBUTING.md) to learn how to contribute to the repository and the development workflow.

docs/_media/App.tsx

Lines changed: 34 additions & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -9,11 +9,15 @@ import {
99
import { useEffect, useRef, useState } from 'react';
1010
import {
1111
MapboxTurnByTurnNavigationView,
12-
type MapboxTurnByTurnNavigation,
12+
type LocationData,
1313
} from 'react-native-mapbox-turn-by-turn-navigation';
14+
import type {
15+
Coordinate,
16+
RouteProgress,
17+
WaypointEvent,
18+
} from '../../lib/typescript/src';
1419

1520
export default function App() {
16-
const [hybridRef, setHybridRef] = useState<MapboxTurnByTurnNavigation>();
1721
const isMountedRef = useRef<boolean>(true);
1822
const [ready, setReady] = useState(false);
1923

@@ -44,53 +48,6 @@ export default function App() {
4448
};
4549
}, []);
4650

47-
useEffect(() => {
48-
let unsubscribeFromListeners: (() => void)[] = [];
49-
50-
if (hybridRef) {
51-
unsubscribeFromListeners.push(
52-
hybridRef.addOnArrivalListener((event) => {
53-
console.log('Arrived at destination:', event);
54-
})
55-
);
56-
unsubscribeFromListeners.push(
57-
hybridRef.addOnWaypointArrivalListener((event) => {
58-
console.log('Arrived at waypoint:', event);
59-
})
60-
);
61-
unsubscribeFromListeners.push(
62-
hybridRef.addOnLocationChangeListener((event) => {
63-
console.log('Location changed:', event);
64-
})
65-
);
66-
unsubscribeFromListeners.push(
67-
hybridRef.addOnRouteProgressChangeListener((event) => {
68-
console.log('Route progress changed:', event);
69-
})
70-
);
71-
unsubscribeFromListeners.push(
72-
hybridRef.addOnErrorListener((error) => {
73-
console.error('Error occurred:', error);
74-
})
75-
);
76-
unsubscribeFromListeners.push(
77-
hybridRef.addOnCancelListener(() => {
78-
console.log('Navigation cancelled');
79-
})
80-
);
81-
}
82-
83-
return () => {
84-
console.log('Cleaning up listeners');
85-
if (unsubscribeFromListeners.length > 0) {
86-
unsubscribeFromListeners.forEach(
87-
(unsubscribe) => typeof unsubscribe === 'function' && unsubscribe()
88-
);
89-
unsubscribeFromListeners = [];
90-
}
91-
};
92-
}, [hybridRef]);
93-
9451
if (!ready) {
9552
return <View style={styles.container} />;
9653
}
@@ -101,14 +58,38 @@ export default function App() {
10158
<View style={styles.container}>
10259
<MapboxTurnByTurnNavigationView
10360
style={styles.mapboxView}
104-
hybridRef={{ f: (hRef) => setHybridRef(hRef) }}
10561
origin={{
62+
longitude: 5.082325,
63+
latitude: 51.558588,
64+
}}
65+
destination={{
10666
longitude: 5.058566,
10767
latitude: 51.560985,
10868
}}
109-
destination={{
110-
longitude: 5.082325,
111-
latitude: 51.558588,
69+
onLocationChange={{
70+
f: (event: LocationData) => {
71+
console.log('Location changed:', event);
72+
},
73+
}}
74+
onCancel={{
75+
f: () => {
76+
console.log('Navigation cancelled');
77+
},
78+
}}
79+
onArrival={{
80+
f: (coordinates: Coordinate) => {
81+
console.log('Arrived at destination:', coordinates);
82+
},
83+
}}
84+
onWaypointArrival={{
85+
f: (event: WaypointEvent) => {
86+
console.log('Arrived at waypoint:', event);
87+
},
88+
}}
89+
onRouteProgressChange={{
90+
f: (event: RouteProgress) => {
91+
console.log('Route progress changed:', event);
92+
},
11293
}}
11394
/>
11495
</View>

docs/_media/globals.md

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
[**react-native-mapbox-turn-by-turn-navigation**](README.md)
2+
3+
***
4+
5+
# react-native-mapbox-turn-by-turn-navigation
6+
7+
## Enumerations
8+
9+
- [DistanceUnitEnum](enumerations/DistanceUnitEnum.md)
10+
- [TravelModeEnum](enumerations/TravelModeEnum.md)
11+
12+
## Interfaces
13+
14+
- [Coordinate](interfaces/Coordinate.md)
15+
- [LocationData](interfaces/LocationData.md)
16+
- [MapboxTurnByTurnNavigationMethods](interfaces/MapboxTurnByTurnNavigationMethods.md)
17+
- [MapboxTurnByTurnNavigationProps](interfaces/MapboxTurnByTurnNavigationProps.md)
18+
- [Message](interfaces/Message.md)
19+
- [RouteProgress](interfaces/RouteProgress.md)
20+
- [Waypoint](interfaces/Waypoint.md)
21+
- [WaypointEvent](interfaces/WaypointEvent.md)
22+
23+
## Type Aliases
24+
25+
- [LocationChangeListener](type-aliases/LocationChangeListener.md)
26+
- [MapboxTurnByTurnNavigation](type-aliases/MapboxTurnByTurnNavigation.md)
27+
- [OnArrivalListener](type-aliases/OnArrivalListener.md)
28+
- [OnCancelListener](type-aliases/OnCancelListener.md)
29+
- [OnErrorListener](type-aliases/OnErrorListener.md)
30+
- [OnWaypointArrivalListener](type-aliases/OnWaypointArrivalListener.md)
31+
- [RouteProgressChangeListener](type-aliases/RouteProgressChangeListener.md)
32+
33+
## Variables
34+
35+
- [MapboxTurnByTurnNavigationView](variables/MapboxTurnByTurnNavigationView.md)

docs/interfaces/MapboxTurnByTurnNavigationMethods.md

Lines changed: 1 addition & 133 deletions
Original file line numberDiff line numberDiff line change
@@ -6,140 +6,8 @@
66

77
# Interface: MapboxTurnByTurnNavigationMethods
88

9-
Defined in: MapboxTurnByTurnNavigation.nitro.d.ts:72
9+
Defined in: MapboxTurnByTurnNavigation.nitro.d.ts:78
1010

1111
## Extends
1212

1313
- `HybridViewMethods`
14-
15-
## Methods
16-
17-
### addOnArrivalListener()
18-
19-
> **addOnArrivalListener**(`listener`): () => `void`
20-
21-
Defined in: MapboxTurnByTurnNavigation.nitro.d.ts:74
22-
23-
#### Parameters
24-
25-
##### listener
26-
27-
[`OnArrivalListener`](../type-aliases/OnArrivalListener.md)
28-
29-
#### Returns
30-
31-
> (): `void`
32-
33-
##### Returns
34-
35-
`void`
36-
37-
***
38-
39-
### addOnCancelListener()
40-
41-
> **addOnCancelListener**(`listener`): () => `void`
42-
43-
Defined in: MapboxTurnByTurnNavigation.nitro.d.ts:77
44-
45-
#### Parameters
46-
47-
##### listener
48-
49-
[`OnCancelListener`](../type-aliases/OnCancelListener.md)
50-
51-
#### Returns
52-
53-
> (): `void`
54-
55-
##### Returns
56-
57-
`void`
58-
59-
***
60-
61-
### addOnErrorListener()
62-
63-
> **addOnErrorListener**(`listener`): () => `void`
64-
65-
Defined in: MapboxTurnByTurnNavigation.nitro.d.ts:78
66-
67-
#### Parameters
68-
69-
##### listener
70-
71-
[`OnErrorListener`](../type-aliases/OnErrorListener.md)
72-
73-
#### Returns
74-
75-
> (): `void`
76-
77-
##### Returns
78-
79-
`void`
80-
81-
***
82-
83-
### addOnLocationChangeListener()
84-
85-
> **addOnLocationChangeListener**(`listener`): () => `void`
86-
87-
Defined in: MapboxTurnByTurnNavigation.nitro.d.ts:75
88-
89-
#### Parameters
90-
91-
##### listener
92-
93-
[`LocationChangeListener`](../type-aliases/LocationChangeListener.md)
94-
95-
#### Returns
96-
97-
> (): `void`
98-
99-
##### Returns
100-
101-
`void`
102-
103-
***
104-
105-
### addOnRouteProgressChangeListener()
106-
107-
> **addOnRouteProgressChangeListener**(`listener`): () => `void`
108-
109-
Defined in: MapboxTurnByTurnNavigation.nitro.d.ts:76
110-
111-
#### Parameters
112-
113-
##### listener
114-
115-
[`RouteProgressChangeListener`](../type-aliases/RouteProgressChangeListener.md)
116-
117-
#### Returns
118-
119-
> (): `void`
120-
121-
##### Returns
122-
123-
`void`
124-
125-
***
126-
127-
### addOnWaypointArrivalListener()
128-
129-
> **addOnWaypointArrivalListener**(`listener`): () => `void`
130-
131-
Defined in: MapboxTurnByTurnNavigation.nitro.d.ts:73
132-
133-
#### Parameters
134-
135-
##### listener
136-
137-
[`OnWaypointArrivalListener`](../type-aliases/OnWaypointArrivalListener.md)
138-
139-
#### Returns
140-
141-
> (): `void`
142-
143-
##### Returns
144-
145-
`void`

docs/interfaces/MapboxTurnByTurnNavigationProps.md

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,54 @@ Defined in: MapboxTurnByTurnNavigation.nitro.d.ts:59
6262

6363
***
6464

65+
### onArrival?
66+
67+
> `optional` **onArrival**: [`OnArrivalListener`](../type-aliases/OnArrivalListener.md)
68+
69+
Defined in: MapboxTurnByTurnNavigation.nitro.d.ts:75
70+
71+
***
72+
73+
### onCancel?
74+
75+
> `optional` **onCancel**: [`OnCancelListener`](../type-aliases/OnCancelListener.md)
76+
77+
Defined in: MapboxTurnByTurnNavigation.nitro.d.ts:73
78+
79+
***
80+
81+
### onError?
82+
83+
> `optional` **onError**: [`OnErrorListener`](../type-aliases/OnErrorListener.md)
84+
85+
Defined in: MapboxTurnByTurnNavigation.nitro.d.ts:74
86+
87+
***
88+
89+
### onLocationChange?
90+
91+
> `optional` **onLocationChange**: [`LocationChangeListener`](../type-aliases/LocationChangeListener.md)
92+
93+
Defined in: MapboxTurnByTurnNavigation.nitro.d.ts:71
94+
95+
***
96+
97+
### onRouteProgressChange?
98+
99+
> `optional` **onRouteProgressChange**: [`RouteProgressChangeListener`](../type-aliases/RouteProgressChangeListener.md)
100+
101+
Defined in: MapboxTurnByTurnNavigation.nitro.d.ts:72
102+
103+
***
104+
105+
### onWaypointArrival?
106+
107+
> `optional` **onWaypointArrival**: [`OnWaypointArrivalListener`](../type-aliases/OnWaypointArrivalListener.md)
108+
109+
Defined in: MapboxTurnByTurnNavigation.nitro.d.ts:76
110+
111+
***
112+
65113
### origin
66114

67115
> **origin**: [`Coordinate`](Coordinate.md)

0 commit comments

Comments
 (0)