react-native-map-link 2.9.4 → 2.10.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +64 -18
- package/index.d.ts +80 -9
- package/index.js +3 -6
- package/package.json +1 -1
- package/src/index.js +32 -2
- package/src/utils.js +24 -4
package/README.md
CHANGED
|
@@ -214,26 +214,26 @@ More info [here](https://stackoverflow.com/a/67383641/1129689).
|
|
|
214
214
|
Using the `showLocation` function will shown an action sheet on iOS and an alert on Android, without any custom styling:
|
|
215
215
|
|
|
216
216
|
```js
|
|
217
|
-
import {
|
|
217
|
+
import {showLocation} from 'react-native-map-link';
|
|
218
218
|
|
|
219
219
|
showLocation({
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
})
|
|
220
|
+
latitude: 38.8976763,
|
|
221
|
+
longitude: -77.0387185,
|
|
222
|
+
sourceLatitude: -8.0870631, // optionally specify starting location for directions
|
|
223
|
+
sourceLongitude: -34.8941619, // not optional if sourceLatitude is specified
|
|
224
|
+
title: 'The White House', // optional
|
|
225
|
+
googleForceLatLon: false, // optionally force GoogleMaps to use the latlon for the query instead of the title
|
|
226
|
+
googlePlaceId: 'ChIJGVtI4by3t4kRr51d_Qm_x58', // optionally specify the google-place-id
|
|
227
|
+
alwaysIncludeGoogle: true, // optional, true will always add Google Maps to iOS and open in Safari, even if app is not installed (default: false)
|
|
228
|
+
dialogTitle: 'This is the dialog Title', // optional (default: 'Open in Maps')
|
|
229
|
+
dialogMessage: 'This is the amazing dialog Message', // optional (default: 'What app would you like to use?')
|
|
230
|
+
cancelText: 'This is the cancel button text', // optional (default: 'Cancel')
|
|
231
|
+
appsWhiteList: ['google-maps'], // optionally you can set which apps to show (default: will show all supported apps installed on device)
|
|
232
|
+
naverCallerName: 'com.example.myapp', // to link into Naver Map You should provide your appname which is the bundle ID in iOS and applicationId in android.
|
|
233
|
+
// appTitles: { 'google-maps': 'My custom Google Maps title' }, // optionally you can override default app titles
|
|
234
|
+
// app: 'uber', // optionally specify specific app to use
|
|
235
|
+
directionsMode: 'walk', // optional, accepted values are 'car', 'walk', 'public-transport' or 'bike'
|
|
236
|
+
});
|
|
237
237
|
```
|
|
238
238
|
|
|
239
239
|
Notes:
|
|
@@ -241,6 +241,52 @@ Notes:
|
|
|
241
241
|
- The `sourceLatitude/sourceLongitude` options only work if you specify both. Currently supports all apps except Waze.
|
|
242
242
|
- `directionsMode` works on google-maps and apple-maps (on the latter, `bike` mode will not work). Without setting it, the app will decide based on his own settings.
|
|
243
243
|
|
|
244
|
+
### Or
|
|
245
|
+
|
|
246
|
+
Using the `getApps` function will return an array (`GetAppResult[]`) with the apps available on the smartphone:
|
|
247
|
+
|
|
248
|
+
```ts
|
|
249
|
+
type GetAppResult = {
|
|
250
|
+
id: string;
|
|
251
|
+
name: string;
|
|
252
|
+
icon: NodeRequire;
|
|
253
|
+
open: () => Promise<void>;
|
|
254
|
+
};
|
|
255
|
+
```
|
|
256
|
+
|
|
257
|
+
```tsx
|
|
258
|
+
import {getApps, GetAppResult} from 'react-native-map-link';
|
|
259
|
+
|
|
260
|
+
const Demo = () => {
|
|
261
|
+
const [availableApps, setAvailableApps] = useState<GetAppResult[]>([]);
|
|
262
|
+
|
|
263
|
+
useEffect(() => {
|
|
264
|
+
(async () => {
|
|
265
|
+
const result = await getApps({
|
|
266
|
+
latitude: 38.8976763,
|
|
267
|
+
longitude: -77.0387185,
|
|
268
|
+
title: 'The White House', // optional
|
|
269
|
+
googleForceLatLon: false, // optionally force GoogleMaps to use the latlon for the query instead of the title
|
|
270
|
+
alwaysIncludeGoogle: true, // optional, true will always add Google Maps to iOS and open in Safari, even if app is not installed (default: false)
|
|
271
|
+
appsWhiteList: ['google-maps'], // optionally you can set which apps to show (default: will show all supported apps installed on device)
|
|
272
|
+
});
|
|
273
|
+
setAvailableApps(result);
|
|
274
|
+
})();
|
|
275
|
+
}, []);
|
|
276
|
+
|
|
277
|
+
return (
|
|
278
|
+
<React.Fragment>
|
|
279
|
+
{availableApps.map(({icon, name, id, open}) => (
|
|
280
|
+
<Pressable key={id} onPress={open}>
|
|
281
|
+
<Image source={icon} />
|
|
282
|
+
<Text>{name}</Text>
|
|
283
|
+
</Pressable>
|
|
284
|
+
))}
|
|
285
|
+
</React.Fragment>
|
|
286
|
+
);
|
|
287
|
+
};
|
|
288
|
+
```
|
|
289
|
+
|
|
244
290
|
## More information
|
|
245
291
|
|
|
246
292
|
- [Using this library with Expo](docs/expo.md)
|
package/index.d.ts
CHANGED
|
@@ -1,21 +1,64 @@
|
|
|
1
1
|
import * as React from 'react';
|
|
2
|
-
import {
|
|
2
|
+
import {
|
|
3
|
+
ViewStyle,
|
|
4
|
+
StyleProp,
|
|
5
|
+
ImageStyle,
|
|
6
|
+
TextStyle,
|
|
7
|
+
ImageSourcePropType,
|
|
8
|
+
} from 'react-native';
|
|
3
9
|
|
|
4
|
-
|
|
10
|
+
/** id for map application. this is the id that is passed to the `app` option */
|
|
11
|
+
export type MapId =
|
|
12
|
+
| 'apple-maps'
|
|
13
|
+
| 'google-maps'
|
|
14
|
+
| 'citymapper'
|
|
15
|
+
| 'uber'
|
|
16
|
+
| 'lyft'
|
|
17
|
+
| 'transit'
|
|
18
|
+
| 'truckmap'
|
|
19
|
+
| 'waze'
|
|
20
|
+
| 'yandex'
|
|
21
|
+
| 'moovit'
|
|
22
|
+
| 'yandex-maps'
|
|
23
|
+
| 'yandex-taxi'
|
|
24
|
+
| 'kakaomap'
|
|
25
|
+
| 'mapycz'
|
|
26
|
+
| 'maps-me'
|
|
27
|
+
| 'osmand'
|
|
28
|
+
| 'gett'
|
|
29
|
+
| 'navermap'
|
|
30
|
+
| 'dgis'
|
|
31
|
+
| 'liftago'
|
|
32
|
+
| 'petalmaps';
|
|
33
|
+
|
|
34
|
+
/** options shared across different types */
|
|
35
|
+
interface SharedOptions {
|
|
36
|
+
/** optionally you can set which apps to show (default: will show all supported apps installed on device) */
|
|
37
|
+
appsWhiteList?: MapId[];
|
|
38
|
+
/** custom titles to display for each app instead of using default titles. */
|
|
39
|
+
appTitles?: Partial<Record<MapId, string>>;
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
interface Options extends SharedOptions {
|
|
5
43
|
latitude: number | string;
|
|
6
44
|
longitude: number | string;
|
|
45
|
+
/** optionally specify starting location for directions */
|
|
7
46
|
sourceLatitude?: number;
|
|
47
|
+
/** not optional if `sourceLatitude` is specified */
|
|
8
48
|
sourceLongitude?: number;
|
|
49
|
+
/** optional, true will always add Google Maps to iOS and open in Safari, even if app is not installed (default: false) */
|
|
9
50
|
alwaysIncludeGoogle?: boolean;
|
|
10
51
|
googleForceLatLon?: boolean;
|
|
11
52
|
googlePlaceId?: string;
|
|
12
53
|
title?: string;
|
|
13
|
-
app
|
|
54
|
+
/** optionally specify specific app to use */
|
|
55
|
+
app?: MapId;
|
|
56
|
+
/** optional (default: 'Open in Maps') */
|
|
14
57
|
dialogTitle?: string;
|
|
58
|
+
/** optional (default: 'What app would you like to use?') */
|
|
15
59
|
dialogMessage?: string;
|
|
16
60
|
cancelText?: string;
|
|
17
|
-
|
|
18
|
-
appTitles?: {[key: string]: string};
|
|
61
|
+
/** to link into Naver Map You should provide your appname which is the bundle ID in iOS and applicationId in android. */
|
|
19
62
|
naverCallerName?: string;
|
|
20
63
|
directionsMode?: 'car' | 'walk' | 'public-transport' | 'bike';
|
|
21
64
|
}
|
|
@@ -34,22 +77,50 @@ interface PopupStyleProp {
|
|
|
34
77
|
activityIndicatorContainer?: StyleProp<ViewStyle>;
|
|
35
78
|
}
|
|
36
79
|
|
|
37
|
-
interface PopupProps {
|
|
80
|
+
interface PopupProps extends SharedOptions {
|
|
38
81
|
isVisible: boolean;
|
|
39
82
|
showHeader?: boolean;
|
|
40
83
|
customHeader?: React.ReactNode;
|
|
41
84
|
customFooter?: React.ReactNode;
|
|
42
85
|
onCancelPressed: () => void;
|
|
43
86
|
onBackButtonPressed: () => void;
|
|
44
|
-
onAppPressed: () => void;
|
|
87
|
+
onAppPressed: (appName: MapId) => void;
|
|
45
88
|
style?: PopupStyleProp;
|
|
46
89
|
modalProps?: object;
|
|
47
90
|
options: Options;
|
|
48
|
-
appsWhiteList?: string[];
|
|
49
|
-
appTitles?: {[key: string]: string};
|
|
50
91
|
}
|
|
51
92
|
|
|
93
|
+
/**
|
|
94
|
+
* Link users to their desired map app.
|
|
95
|
+
*
|
|
96
|
+
* If an `app` option is passed, it will directly link to that map app,
|
|
97
|
+
* else it will prompt user to select map app.
|
|
98
|
+
*
|
|
99
|
+
* Prompts via `ActionSheetIOS` on iOS & `Alert.alert` on Android.
|
|
100
|
+
*
|
|
101
|
+
* If these prompts don't meet your UI use case, checkout the `Popup` component,
|
|
102
|
+
* or use the `getApps` function to build a custom UI.
|
|
103
|
+
*/
|
|
52
104
|
export function showLocation(
|
|
53
105
|
options: Options,
|
|
54
106
|
): Promise<string | undefined | null>;
|
|
107
|
+
|
|
108
|
+
export type GetAppResult = {
|
|
109
|
+
id: MapId;
|
|
110
|
+
name: string;
|
|
111
|
+
icon: ImageSourcePropType;
|
|
112
|
+
/** function to link user to map app */
|
|
113
|
+
open: () => Promise<void>;
|
|
114
|
+
};
|
|
115
|
+
|
|
116
|
+
/**
|
|
117
|
+
* Get array of map apps on users device.
|
|
118
|
+
*
|
|
119
|
+
* Useful for building custom UIs.
|
|
120
|
+
*/
|
|
121
|
+
export function getApps(options: Options): Promise<GetAppResult[]>;
|
|
122
|
+
|
|
123
|
+
/**
|
|
124
|
+
* A styled popup component that displays icons in the app list
|
|
125
|
+
*/
|
|
55
126
|
export class Popup extends React.Component<PopupProps> {}
|
package/index.js
CHANGED
|
@@ -2,10 +2,7 @@
|
|
|
2
2
|
* React Native Map Link
|
|
3
3
|
*/
|
|
4
4
|
|
|
5
|
-
import Popup from './src/components/Popup'
|
|
6
|
-
import {
|
|
5
|
+
import Popup from './src/components/Popup';
|
|
6
|
+
import {showLocation, getApps} from './src';
|
|
7
7
|
|
|
8
|
-
export {
|
|
9
|
-
showLocation,
|
|
10
|
-
Popup
|
|
11
|
-
}
|
|
8
|
+
export {showLocation, getApps, Popup};
|
package/package.json
CHANGED
package/src/index.js
CHANGED
|
@@ -4,8 +4,13 @@
|
|
|
4
4
|
|
|
5
5
|
import {Linking} from 'react-native';
|
|
6
6
|
|
|
7
|
-
import {generatePrefixes, generateTitles, isIOS} from './constants';
|
|
8
|
-
import {
|
|
7
|
+
import {generatePrefixes, generateTitles, isIOS, icons} from './constants';
|
|
8
|
+
import {
|
|
9
|
+
askAppChoice,
|
|
10
|
+
checkOptions,
|
|
11
|
+
getAvailableApps,
|
|
12
|
+
checkNotSupportedApps,
|
|
13
|
+
} from './utils';
|
|
9
14
|
|
|
10
15
|
/**
|
|
11
16
|
* Open a maps app, or let the user choose what app to open, with the given location.
|
|
@@ -299,3 +304,28 @@ export async function showLocation(options) {
|
|
|
299
304
|
return Linking.openURL(url).then(() => Promise.resolve(app));
|
|
300
305
|
}
|
|
301
306
|
}
|
|
307
|
+
|
|
308
|
+
export async function getApps(options) {
|
|
309
|
+
let apps = await getAvailableApps(generatePrefixes(options));
|
|
310
|
+
if ('appsWhiteList' in options && options.appsWhiteList.length) {
|
|
311
|
+
checkNotSupportedApps(options.appsWhiteList);
|
|
312
|
+
apps = apps.filter((appName) => options.appsWhiteList.includes(appName));
|
|
313
|
+
}
|
|
314
|
+
|
|
315
|
+
const titles = generateTitles(options.appTitles);
|
|
316
|
+
async function open(app) {
|
|
317
|
+
return showLocation({...options, app});
|
|
318
|
+
}
|
|
319
|
+
|
|
320
|
+
let list = [];
|
|
321
|
+
for (const app of apps) {
|
|
322
|
+
list.push({
|
|
323
|
+
id: app,
|
|
324
|
+
name: titles[app],
|
|
325
|
+
icon: icons[app],
|
|
326
|
+
open: open.bind(this, app),
|
|
327
|
+
});
|
|
328
|
+
}
|
|
329
|
+
|
|
330
|
+
return list;
|
|
331
|
+
}
|
package/src/utils.js
CHANGED
|
@@ -11,15 +11,35 @@ import {appKeys, isIOS} from './constants';
|
|
|
11
11
|
*/
|
|
12
12
|
export const getAvailableApps = async (prefixes) => {
|
|
13
13
|
const availableApps = [];
|
|
14
|
+
const promises = [];
|
|
15
|
+
|
|
14
16
|
for (const app in prefixes) {
|
|
15
17
|
if (prefixes.hasOwnProperty(app)) {
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
18
|
+
promises.push(
|
|
19
|
+
new Promise(async (resolve) => {
|
|
20
|
+
try {
|
|
21
|
+
const isInstalled = await isAppInstalled(app, prefixes);
|
|
22
|
+
|
|
23
|
+
resolve({
|
|
24
|
+
app,
|
|
25
|
+
isInstalled,
|
|
26
|
+
});
|
|
27
|
+
} catch (error) {
|
|
28
|
+
resolve({
|
|
29
|
+
app,
|
|
30
|
+
isInstalled: false,
|
|
31
|
+
});
|
|
32
|
+
}
|
|
33
|
+
}),
|
|
34
|
+
);
|
|
20
35
|
}
|
|
21
36
|
}
|
|
22
37
|
|
|
38
|
+
const results = await Promise.all(promises);
|
|
39
|
+
results.forEach(
|
|
40
|
+
({isInstalled, app}) => isInstalled && availableApps.push(app),
|
|
41
|
+
);
|
|
42
|
+
|
|
23
43
|
return availableApps;
|
|
24
44
|
};
|
|
25
45
|
|