Skip to content

Commit

Permalink
feat: handle multiple scheme (ios) (#67)
Browse files Browse the repository at this point in the history
  • Loading branch information
achorein committed Jun 5, 2024
1 parent dbd538a commit 1e4686a
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 9 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ Ensure you use versions that work together

| Expo | Supported `expo-share-intent` version |
| ---------- | ------------------------------------- |
| **SDK 51** | 2.0+ |
| **SDK 50** | 1.0+ |
| **SDK 49** | 0.2+ |

Expand Down
13 changes: 10 additions & 3 deletions plugin/src/ios/writeIosShareExtensionFiles.ts
Original file line number Diff line number Diff line change
Expand Up @@ -184,10 +184,17 @@ export function getShareExtensionViewControllerContent(
scheme: string,
appIdentifier: string,
) {
let updatedScheme = scheme;
if (Array.isArray(scheme)) {
console.debug(
`[expo-share-intent] multiple scheme detected (${scheme.join(",")}), using:${updatedScheme}`,
);
updatedScheme = scheme[0];
}
console.debug(
`[expo-share-intent] add ios share extension (scheme:${scheme} appIdentifier:${appIdentifier})`,
`[expo-share-intent] add ios share extension (scheme:${updatedScheme} appIdentifier:${appIdentifier})`,
);
if (!scheme) {
if (!updatedScheme) {
throw new Error(
"[expo-share-intent] missing custom URL scheme 'expo.scheme' in app.json ! (see https://docs.expo.dev/guides/linking/#linking-to-your-app)",
);
Expand All @@ -199,6 +206,6 @@ export function getShareExtensionViewControllerContent(
);

return content
.replaceAll("<SCHEME>", scheme)
.replaceAll("<SCHEME>", updatedScheme)
.replaceAll("<APPIDENTIFIER>", appIdentifier);
}
21 changes: 15 additions & 6 deletions src/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,21 @@ export const getScheme = (options?: ShareIntentOptions) => {
return options.scheme;
}
if (Constants.expoConfig?.scheme) {
options?.debug &&
console.debug(
"expoShareIntent[scheme] from expoConfig:",
Constants.expoConfig?.scheme,
);
return Constants.expoConfig?.scheme;
let updatedScheme = Constants.expoConfig?.scheme;
if (Array.isArray(Constants.expoConfig?.scheme)) {
updatedScheme = updatedScheme[0];
options?.debug &&
console.debug(
`expoShareIntent[scheme] from expoConfig: multiple scheme detected (${Constants.expoConfig?.scheme.join(",")}), using:${updatedScheme}`,
);
} else {
options?.debug &&
console.debug(
"expoShareIntent[scheme] from expoConfig:",
updatedScheme,
);
}
return updatedScheme;
}
const deepLinkUrl = createURL("dataUrl=");
const extracted = deepLinkUrl.match(/^([^:]+)/gi)?.[0] || null;
Expand Down

0 comments on commit 1e4686a

Please sign in to comment.