Skip to content

Commit e33318b

Browse files
authored
Merge pull request #309 from metehandemir/appsBlackList
2 parents 751c5ff + c802d1f commit e33318b

File tree

6 files changed

+30
-0
lines changed

6 files changed

+30
-0
lines changed

README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -258,6 +258,7 @@ showLocation({
258258
dialogMessage: 'This is the amazing dialog Message', // optional (default: 'What app would you like to use?')
259259
cancelText: 'This is the cancel button text', // optional (default: 'Cancel')
260260
appsWhiteList: ['google-maps'], // optionally you can set which apps to show (default: will show all supported apps installed on device)
261+
appsBlackList: ['uber'], // optionally you can set which apps NOT to show (default: will show all supported apps installed on device)
261262
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.
262263
appTitles: {'google-maps': 'My custom Google Maps title'}, // optionally you can override default app titles
263264
app: 'uber', // optionally specify specific app to use
@@ -312,6 +313,7 @@ const Demo = () => {
312313
googleForceLatLon: false, // optionally force GoogleMaps to use the latlon for the query instead of the title
313314
alwaysIncludeGoogle: true, // optional, true will always add Google Maps to iOS and open in Safari, even if app is not installed (default: false)
314315
appsWhiteList: ['google-maps'], // optionally you can set which apps to show (default: will show all supported apps installed on device)
316+
appsBlackList: ['uber'], // optionally you can set which apps NOT to show (default: will show all supported apps installed on device)
315317
});
316318
setAvailableApps(result);
317319
})();

example/App.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ export default function App() {
3838
googleForceLatLon: false, // optionally force GoogleMaps to use the latlon for the query instead of the title
3939
alwaysIncludeGoogle: true, // optional, true will always add Google Maps to iOS and open in Safari, even if app is not installed (default: false)
4040
appsWhiteList: ['google-maps'], // optionally you can set which apps to show (default: will show all supported apps installed on device)
41+
appsBlackList: ['uber'], // optionally you can set which apps NOT to show (default: will show all supported apps installed on device)
4142
});
4243
setAvailableApps(apps);
4344
} catch (error) {

src/components/popup/Popup.tsx

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,11 @@ export const Popup: React.FC<PopupProps> = ({
6767
options.appsWhiteList?.includes(appName),
6868
);
6969
}
70+
if (options.appsBlackList && options.appsBlackList.length) {
71+
appsData = appsData.filter(
72+
(appName) => !options.appsBlackList?.includes(appName),
73+
);
74+
}
7075
setApps(appsData);
7176
setIsLoading(false);
7277
};
@@ -76,6 +81,7 @@ export const Popup: React.FC<PopupProps> = ({
7681
options.alwaysIncludeGoogle,
7782
options.appTitles,
7883
options.appsWhiteList,
84+
options.appsBlackList,
7985
options.naverCallerName,
8086
]);
8187

src/index.ts

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ export const showLocation = async ({
3838
dialogMessage: customDialogMessage,
3939
cancelText: customCancelText,
4040
appsWhiteList: customAppsWhiteList,
41+
appsBlackList: customAppsBlackList,
4142
appTitles,
4243
naverCallerName,
4344
directionsMode,
@@ -103,13 +104,18 @@ export const showLocation = async ({
103104
customAppsWhiteList && customAppsWhiteList.length
104105
? customAppsWhiteList
105106
: null;
107+
const appsBlackList =
108+
customAppsBlackList && customAppsBlackList.length
109+
? customAppsBlackList
110+
: null;
106111

107112
if (!app) {
108113
app = await askAppChoice({
109114
dialogTitle,
110115
dialogMessage,
111116
cancelText,
112117
appsWhiteList,
118+
appsBlackList,
113119
prefixes,
114120
appTitles: generateTitles(appTitles),
115121
});
@@ -143,6 +149,7 @@ export const showLocation = async ({
143149
export async function getApps({
144150
alwaysIncludeGoogle,
145151
appsWhiteList,
152+
appsBlackList,
146153
appTitles,
147154
naverCallerName,
148155
...rest
@@ -156,13 +163,18 @@ export async function getApps({
156163
apps = apps.filter((appName) => appsWhiteList!.includes(appName));
157164
}
158165

166+
if (appsBlackList && appsBlackList.length) {
167+
apps = apps.filter((appName) => !appsBlackList!.includes(appName));
168+
}
169+
159170
const titles = generateTitles({...appTitles});
160171
async function open(app: MapId) {
161172
return showLocation({
162173
...rest,
163174
app,
164175
alwaysIncludeGoogle,
165176
appsWhiteList,
177+
appsBlackList,
166178
appTitles,
167179
naverCallerName,
168180
});

src/type.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,7 @@ export interface ShowLocationProps {
6262
dialogMessage?: string | null;
6363
cancelText?: string | null;
6464
appsWhiteList?: string[] | null;
65+
appsBlackList?: string[] | null;
6566
appTitles?: Partial<Record<MapId, string>>;
6667
naverCallerName?: string;
6768
directionsMode?: DirectionMode;

src/utils.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,13 +63,15 @@ export const askAppChoice = ({
6363
dialogMessage,
6464
cancelText,
6565
appsWhiteList,
66+
appsBlackList,
6667
prefixes,
6768
appTitles,
6869
}: {
6970
dialogTitle: string | null | undefined;
7071
dialogMessage: string | null | undefined;
7172
cancelText: string | null | undefined;
7273
appsWhiteList: string[] | null | undefined;
74+
appsBlackList: string[] | null | undefined;
7375
prefixes: Record<string, string>;
7476
appTitles: Record<string, string> | null | undefined;
7577
}): Promise<MapId | null> => {
@@ -82,6 +84,12 @@ export const askAppChoice = ({
8284
);
8385
}
8486

87+
if (appsBlackList && appsBlackList.length) {
88+
availableApps = availableApps.filter(
89+
(appName) => !appsBlackList.includes(appName),
90+
);
91+
}
92+
8593
if (availableApps.length < 2) {
8694
return resolve(availableApps[0] || null);
8795
}

0 commit comments

Comments
 (0)