react-native-map-link 2.9.4 → 2.10.0
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 +9 -1
- package/index.js +2 -1
- 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,5 +1,5 @@
|
|
|
1
1
|
import * as React from 'react';
|
|
2
|
-
import {ViewStyle, StyleProp, ImageStyle, TextStyle} from 'react-native';
|
|
2
|
+
import {ViewStyle, StyleProp, ImageStyle, TextStyle, ImageSourcePropType} from 'react-native';
|
|
3
3
|
|
|
4
4
|
interface Options {
|
|
5
5
|
latitude: number | string;
|
|
@@ -52,4 +52,12 @@ interface PopupProps {
|
|
|
52
52
|
export function showLocation(
|
|
53
53
|
options: Options,
|
|
54
54
|
): Promise<string | undefined | null>;
|
|
55
|
+
|
|
56
|
+
|
|
57
|
+
export type GetAppResult = {id:string, name: string, icon: ImageSourcePropType, open: () => Promise<void>}
|
|
58
|
+
export function getApps(
|
|
59
|
+
options: Options,
|
|
60
|
+
select?:string[]
|
|
61
|
+
): Promise<GetAppsResult[]>;
|
|
62
|
+
|
|
55
63
|
export class Popup extends React.Component<PopupProps> {}
|
package/index.js
CHANGED
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();
|
|
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
|
|