Skip to content

Commit

Permalink
feat: add appsBlackList option to filter out specific apps
Browse files Browse the repository at this point in the history
  • Loading branch information
metehandemir committed Feb 7, 2025
1 parent 751c5ff commit c802d1f
Show file tree
Hide file tree
Showing 6 changed files with 30 additions and 0 deletions.
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -258,6 +258,7 @@ showLocation({
dialogMessage: 'This is the amazing dialog Message', // optional (default: 'What app would you like to use?')
cancelText: 'This is the cancel button text', // optional (default: 'Cancel')
appsWhiteList: ['google-maps'], // optionally you can set which apps to show (default: will show all supported apps installed on device)
appsBlackList: ['uber'], // optionally you can set which apps NOT to show (default: will show all supported apps installed on device)
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.
appTitles: {'google-maps': 'My custom Google Maps title'}, // optionally you can override default app titles
app: 'uber', // optionally specify specific app to use
Expand Down Expand Up @@ -312,6 +313,7 @@ const Demo = () => {
googleForceLatLon: false, // optionally force GoogleMaps to use the latlon for the query instead of the title
alwaysIncludeGoogle: true, // optional, true will always add Google Maps to iOS and open in Safari, even if app is not installed (default: false)
appsWhiteList: ['google-maps'], // optionally you can set which apps to show (default: will show all supported apps installed on device)
appsBlackList: ['uber'], // optionally you can set which apps NOT to show (default: will show all supported apps installed on device)
});
setAvailableApps(result);
})();
Expand Down
1 change: 1 addition & 0 deletions example/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ export default function App() {
googleForceLatLon: false, // optionally force GoogleMaps to use the latlon for the query instead of the title
alwaysIncludeGoogle: true, // optional, true will always add Google Maps to iOS and open in Safari, even if app is not installed (default: false)
appsWhiteList: ['google-maps'], // optionally you can set which apps to show (default: will show all supported apps installed on device)
appsBlackList: ['uber'], // optionally you can set which apps NOT to show (default: will show all supported apps installed on device)
});
setAvailableApps(apps);
} catch (error) {
Expand Down
6 changes: 6 additions & 0 deletions src/components/popup/Popup.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,11 @@ export const Popup: React.FC<PopupProps> = ({
options.appsWhiteList?.includes(appName),
);
}
if (options.appsBlackList && options.appsBlackList.length) {
appsData = appsData.filter(
(appName) => !options.appsBlackList?.includes(appName),
);
}
setApps(appsData);
setIsLoading(false);
};
Expand All @@ -76,6 +81,7 @@ export const Popup: React.FC<PopupProps> = ({
options.alwaysIncludeGoogle,
options.appTitles,
options.appsWhiteList,
options.appsBlackList,
options.naverCallerName,
]);

Expand Down
12 changes: 12 additions & 0 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ export const showLocation = async ({
dialogMessage: customDialogMessage,
cancelText: customCancelText,
appsWhiteList: customAppsWhiteList,
appsBlackList: customAppsBlackList,
appTitles,
naverCallerName,
directionsMode,
Expand Down Expand Up @@ -103,13 +104,18 @@ export const showLocation = async ({
customAppsWhiteList && customAppsWhiteList.length
? customAppsWhiteList
: null;
const appsBlackList =
customAppsBlackList && customAppsBlackList.length
? customAppsBlackList
: null;

if (!app) {
app = await askAppChoice({
dialogTitle,
dialogMessage,
cancelText,
appsWhiteList,
appsBlackList,
prefixes,
appTitles: generateTitles(appTitles),
});
Expand Down Expand Up @@ -143,6 +149,7 @@ export const showLocation = async ({
export async function getApps({
alwaysIncludeGoogle,
appsWhiteList,
appsBlackList,
appTitles,
naverCallerName,
...rest
Expand All @@ -156,13 +163,18 @@ export async function getApps({
apps = apps.filter((appName) => appsWhiteList!.includes(appName));
}

if (appsBlackList && appsBlackList.length) {
apps = apps.filter((appName) => !appsBlackList!.includes(appName));
}

const titles = generateTitles({...appTitles});
async function open(app: MapId) {
return showLocation({
...rest,
app,
alwaysIncludeGoogle,
appsWhiteList,
appsBlackList,
appTitles,
naverCallerName,
});
Expand Down
1 change: 1 addition & 0 deletions src/type.ts
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ export interface ShowLocationProps {
dialogMessage?: string | null;
cancelText?: string | null;
appsWhiteList?: string[] | null;
appsBlackList?: string[] | null;
appTitles?: Partial<Record<MapId, string>>;
naverCallerName?: string;
directionsMode?: DirectionMode;
Expand Down
8 changes: 8 additions & 0 deletions src/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -63,13 +63,15 @@ export const askAppChoice = ({
dialogMessage,
cancelText,
appsWhiteList,
appsBlackList,
prefixes,
appTitles,
}: {
dialogTitle: string | null | undefined;
dialogMessage: string | null | undefined;
cancelText: string | null | undefined;
appsWhiteList: string[] | null | undefined;
appsBlackList: string[] | null | undefined;
prefixes: Record<string, string>;
appTitles: Record<string, string> | null | undefined;
}): Promise<MapId | null> => {
Expand All @@ -82,6 +84,12 @@ export const askAppChoice = ({
);
}

if (appsBlackList && appsBlackList.length) {
availableApps = availableApps.filter(
(appName) => !appsBlackList.includes(appName),
);
}

if (availableApps.length < 2) {
return resolve(availableApps[0] || null);
}
Expand Down

0 comments on commit c802d1f

Please sign in to comment.