Skip to content

Commit 17cbf36

Browse files
authored
Merge branch 'master' into meteorlxy/build-clean-up-useless-file
2 parents f15f206 + e68d4ab commit 17cbf36

File tree

12 files changed

+61
-152
lines changed

12 files changed

+61
-152
lines changed

docs/popup.md

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,6 @@ import { Popup } from 'react-native-map-link';
1717
modalProps={{ // you can put all modal props inside.
1818
animationType: 'slide'
1919
}}
20-
appsWhiteList={[ /* Array of apps (apple-maps, google-maps, etc...) that you want
21-
to show in the popup, if is undefined or an empty array it will show all supported apps installed on device.*/ ]}
22-
appTitles: {{ /* Optional: you can override app titles. */ }}
2320
options={{ /* See `showLocation` method above, this accepts the same options. */ }}
2421
style={{ /* Optional: you can override default style by passing your values. */ }}
2522
/>

src/components/popup/Popup.tsx

Lines changed: 15 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,21 @@
11
import React, {useEffect, useState} from 'react';
2-
import {
3-
StyleSheet,
4-
View,
5-
Modal,
6-
Dimensions,
7-
ModalProps,
8-
ViewStyle,
9-
TextStyle,
10-
ImageStyle,
11-
} from 'react-native';
2+
import {StyleSheet, View, Modal, Dimensions} from 'react-native';
3+
import type {ImageStyle, ModalProps, ViewStyle, TextStyle} from 'react-native';
124
import {getAvailableApps, checkNotSupportedApps} from '../../utils';
135
import {generatePrefixes, generateTitles} from '../../constants';
6+
import type {MapId, ShowLocationProps} from '../../type';
147
import PopupFooter from './PopupFooter';
158
import PopupHeader from './PopupHeader';
169
import PopupBody from './PopupBody';
1710
import {showLocation} from '../..';
1811

19-
interface PopupProps {
12+
export interface PopupProps {
2013
isVisible: boolean;
14+
setIsVisible: (isVisible: boolean) => void;
2115
showHeader?: boolean;
22-
customHeader?: JSX.Element;
23-
customFooter?: JSX.Element;
24-
onAppPressed: (app: string) => void;
16+
customHeader?: React.ReactNode;
17+
customFooter?: React.ReactNode;
18+
onAppPressed: (app: MapId) => void;
2519
onCancelPressed: () => void;
2620
style?: {
2721
container?: ViewStyle;
@@ -37,19 +31,7 @@ interface PopupProps {
3731
activityIndicatorContainer?: ViewStyle;
3832
};
3933
modalProps?: ModalProps;
40-
options: {
41-
dialogTitle?: string;
42-
dialogMessage?: string;
43-
cancelText?: string;
44-
appTitles?: Record<string, string>;
45-
alwaysIncludeGoogle?: boolean;
46-
naverCallerName?: string;
47-
latitude: number;
48-
longitude: number;
49-
title?: string;
50-
};
51-
appsWhiteList?: string[];
52-
setIsVisible: (isVisible: boolean) => void;
34+
options: ShowLocationProps;
5335
}
5436

5537
const SCREEN_HEIGHT = Dimensions.get('screen').height;
@@ -64,10 +46,9 @@ export const Popup: React.FC<PopupProps> = ({
6446
style = {},
6547
modalProps,
6648
options,
67-
appsWhiteList,
6849
setIsVisible,
6950
}) => {
70-
const [apps, setApps] = useState<string[]>([]);
51+
const [apps, setApps] = useState<MapId[]>([]);
7152
const [isLoading, setIsLoading] = useState(true);
7253
const [titles, setTitles] = useState<{[key: string]: string}>({});
7354

@@ -79,10 +60,10 @@ export const Popup: React.FC<PopupProps> = ({
7960
naverCallerName: options.naverCallerName,
8061
}),
8162
);
82-
if (appsWhiteList && appsWhiteList.length) {
83-
checkNotSupportedApps(appsWhiteList);
63+
if (options.appsWhiteList && options.appsWhiteList.length) {
64+
checkNotSupportedApps(options.appsWhiteList);
8465
appsData = appsData.filter((appName) =>
85-
appsWhiteList.includes(appName),
66+
options.appsWhiteList?.includes(appName),
8667
);
8768
}
8869
setApps(appsData);
@@ -91,13 +72,13 @@ export const Popup: React.FC<PopupProps> = ({
9172
loadApps();
9273
setTitles(generateTitles(options.appTitles));
9374
}, [
94-
appsWhiteList,
9575
options.alwaysIncludeGoogle,
9676
options.appTitles,
77+
options.appsWhiteList,
9778
options.naverCallerName,
9879
]);
9980

100-
const _onAppPressed = (app: string) => {
81+
const _onAppPressed = (app: MapId) => {
10182
showLocation({
10283
...options,
10384
app,

src/components/popup/PopupBody.tsx

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,7 @@
11
import React from 'react';
2-
import {
3-
ActivityIndicator,
4-
StyleSheet,
5-
ViewStyle,
6-
TextStyle,
7-
ImageStyle,
8-
} from 'react-native';
2+
import {ActivityIndicator, StyleSheet} from 'react-native';
3+
import type {ImageStyle, TextStyle, ViewStyle} from 'react-native';
4+
import type {MapId} from '../../type';
95
import PopupItem from './PopupItem';
106
import PopupSeparator from './PopupSeparator';
117
import PopupFlatList from './PopupFlatList';
@@ -31,8 +27,8 @@ const PopupBody = ({
3127
image?: ImageStyle;
3228
itemText?: TextStyle;
3329
};
34-
apps: string[];
35-
onAppPressed: (app: string) => void;
30+
apps: MapId[];
31+
onAppPressed: (app: MapId) => void;
3632
titles: Record<string, string>;
3733
}) => {
3834
if (isLoading) {

src/components/popup/PopupFlatList.tsx

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,18 @@
11
import React from 'react';
22
import {FlatList} from 'react-native';
3+
import type {ListRenderItem} from 'react-native';
4+
import type {MapId} from '../../type';
35

46
const PopupFlatList = ({
57
separator,
68
data,
79
renderItem,
810
keyExtractor,
911
}: {
10-
separator: JSX.Element;
11-
data: string[];
12-
renderItem: ({item}: {item: string}) => JSX.Element;
13-
keyExtractor: (item: string) => string;
12+
separator: React.ReactNode;
13+
data: MapId[];
14+
renderItem: ListRenderItem<MapId>;
15+
keyExtractor: (item: MapId) => string;
1416
}) => {
1517
return (
1618
<FlatList

src/components/popup/PopupFooter.tsx

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import React from 'react';
2-
import {Text, TouchableOpacity, ViewStyle, TextStyle} from 'react-native';
2+
import {Text, TouchableOpacity} from 'react-native';
3+
import type {TextStyle, ViewStyle} from 'react-native';
34

45
const PopupFooter = ({
56
customFooter,
@@ -10,14 +11,14 @@ const PopupFooter = ({
1011
},
1112
options,
1213
}: {
13-
customFooter?: JSX.Element;
14+
customFooter?: React.ReactNode;
1415
onCancelPressed: () => void;
1516
style: {
1617
cancelButtonContainer?: ViewStyle;
1718
cancelButtonText?: TextStyle;
1819
};
1920
options: {
20-
cancelText?: string;
21+
cancelText?: string | null;
2122
};
2223
}) => {
2324
if (customFooter) {

src/components/popup/PopupHeader.tsx

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import React from 'react';
2-
import {StyleSheet, Text, View, ViewStyle, TextStyle} from 'react-native';
2+
import {StyleSheet, Text, View} from 'react-native';
3+
import type {TextStyle, ViewStyle} from 'react-native';
34
import {colorsPopup} from '../../constants';
45

56
const PopupHeader = ({
@@ -13,15 +14,15 @@ const PopupHeader = ({
1314
options,
1415
}: {
1516
showHeader: boolean;
16-
customHeader?: JSX.Element;
17+
customHeader?: React.ReactNode;
1718
style: {
1819
headerContainer?: ViewStyle;
1920
titleText?: TextStyle;
2021
subtitleText?: TextStyle;
2122
};
2223
options: {
23-
dialogTitle?: string;
24-
dialogMessage?: string;
24+
dialogTitle?: string | null;
25+
dialogMessage?: string | null;
2526
};
2627
}) => {
2728
if (!showHeader) {

src/components/popup/PopupItem.tsx

Lines changed: 6 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,8 @@
11
import React from 'react';
2-
import {
3-
Image,
4-
Text,
5-
TouchableOpacity,
6-
View,
7-
StyleSheet,
8-
ViewStyle,
9-
TextStyle,
10-
ImageStyle,
11-
} from 'react-native';
2+
import {Image, StyleSheet, Text, TouchableOpacity, View} from 'react-native';
3+
import type {ImageStyle, TextStyle, ViewStyle} from 'react-native';
124
import {colorsPopup, icons} from '../../constants';
5+
import type {MapId} from '../../type';
136

147
const PopupItem = ({
158
item,
@@ -21,14 +14,14 @@ const PopupItem = ({
2114
onAppPressed,
2215
titles,
2316
}: {
24-
item: string;
17+
item: MapId;
2518
style: {
2619
itemContainer?: ViewStyle;
2720
image?: ImageStyle;
2821
itemText?: TextStyle;
2922
};
30-
onAppPressed: (app: string) => void;
31-
titles: Record<string, string>;
23+
onAppPressed: (app: MapId) => void;
24+
titles: Record<MapId, string>;
3225
}) => {
3326
return (
3427
<TouchableOpacity

src/components/popup/PopupSeparator.tsx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import React from 'react';
2-
import {View, StyleSheet, ViewStyle} from 'react-native';
2+
import {View, StyleSheet} from 'react-native';
3+
import type {ViewStyle} from 'react-native';
34
import {colorsPopup} from '../../constants';
45

56
const PopupSeparator = ({

src/constants.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import {Platform} from 'react-native';
2+
import type {MapId} from './type';
23

34
export const isIOS: boolean = Platform.OS === 'ios';
45

@@ -8,7 +9,7 @@ export const generatePrefixes = ({
89
}: {
910
alwaysIncludeGoogle?: boolean;
1011
naverCallerName?: string;
11-
}): Record<string, string> => {
12+
}): Record<MapId, string> => {
1213
return {
1314
'apple-maps': isIOS ? 'maps://' : 'applemaps://',
1415
'google-maps': prefixForGoogleMaps(alwaysIncludeGoogle),

src/index.ts

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -15,14 +15,12 @@ export type {
1515
GetAppsProps,
1616
GetAppsResponse,
1717
MapId,
18-
MapLinkOptions,
19-
PopupProps,
20-
PopupStyleProp,
2118
SharedOptions,
2219
ShowLocationProps,
2320
} from './type';
2421

2522
export {Popup} from './components/popup/Popup';
23+
export type {PopupProps} from './components/popup/Popup';
2624

2725
export const showLocation = async ({
2826
latitude,
@@ -151,7 +149,7 @@ export async function getApps({
151149
}
152150

153151
const titles = generateTitles({...appTitles});
154-
async function open(app: string) {
152+
async function open(app: MapId) {
155153
return showLocation({
156154
...rest,
157155
app,
@@ -165,7 +163,7 @@ export async function getApps({
165163
const list: GetAppsResponse[] = [];
166164
for (const app of apps) {
167165
list.push({
168-
id: app as MapId,
166+
id: app,
169167
name: titles[app],
170168
icon: icons[app],
171169
open: () => open(app),

0 commit comments

Comments
 (0)