Skip to content

Commit

Permalink
fix: missing scheme on runtime when using expo-updates
Browse files Browse the repository at this point in the history
  • Loading branch information
achorein committed Apr 9, 2024
1 parent c909ea0 commit 7d9bd75
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 2 deletions.
1 change: 1 addition & 0 deletions example/basic/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ export default function App() {
useShareIntent({
debug: true,
resetOnBackground: true,
scheme: "exposhareintentexample", // needed only when using expo-updates
});

return (
Expand Down
1 change: 1 addition & 0 deletions src/ExpoShareIntentModule.types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ export type ShareIntentOptions = {
debug?: boolean;
resetOnBackground?: boolean;
disabled?: boolean;
scheme?: string;
onResetShareIntent?: () => void;
};

Expand Down
15 changes: 13 additions & 2 deletions src/useShareIntent.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,9 @@ export default function useShareIntent(
if (options.disabled) return;
setError(null);
clearNativeModule &&
clearShareIntent(`${Constants.expoConfig?.scheme}ShareKey`);
clearShareIntent(
`${Constants.expoConfig?.scheme || options.scheme}ShareKey`,
);
if (shareIntent?.text || shareIntent?.files) {
setSharedIntent(SHAREINTENT_DEFAULTVALUE);
options.onResetShareIntent?.();
Expand All @@ -113,7 +115,16 @@ export default function useShareIntent(
*/
const refreshShareIntent = () => {
options.debug && console.debug("useShareIntent[refresh]", url);
if (url?.startsWith(`${Constants.expoConfig?.scheme}://dataUrl`)) {
if (Platform.OS === "ios" && !Constants.expoConfig?.scheme) {
console.warn(
`Constants.expoConfig.scheme is empty! Falling back to options.scheme "${options.scheme}"`,
);
}
if (
url?.startsWith(
`${Constants.expoConfig?.scheme || options.scheme}://dataUrl`,
)
) {
// iOS only
getShareIntent(url);
} else if (Platform.OS === "android") {
Expand Down

0 comments on commit 7d9bd75

Please sign in to comment.