From 7d9bd759d11a3345edb91df3764d74132a4f88aa Mon Sep 17 00:00:00 2001 From: achorein Date: Tue, 9 Apr 2024 22:22:13 +0200 Subject: [PATCH] fix: missing scheme on runtime when using expo-updates --- example/basic/App.tsx | 1 + src/ExpoShareIntentModule.types.ts | 1 + src/useShareIntent.tsx | 15 +++++++++++++-- 3 files changed, 15 insertions(+), 2 deletions(-) diff --git a/example/basic/App.tsx b/example/basic/App.tsx index 4a571ab..d4ea1d8 100644 --- a/example/basic/App.tsx +++ b/example/basic/App.tsx @@ -7,6 +7,7 @@ export default function App() { useShareIntent({ debug: true, resetOnBackground: true, + scheme: "exposhareintentexample", // needed only when using expo-updates }); return ( diff --git a/src/ExpoShareIntentModule.types.ts b/src/ExpoShareIntentModule.types.ts index 9d77c2e..00011ad 100644 --- a/src/ExpoShareIntentModule.types.ts +++ b/src/ExpoShareIntentModule.types.ts @@ -10,6 +10,7 @@ export type ShareIntentOptions = { debug?: boolean; resetOnBackground?: boolean; disabled?: boolean; + scheme?: string; onResetShareIntent?: () => void; }; diff --git a/src/useShareIntent.tsx b/src/useShareIntent.tsx index 508d88f..a27809a 100644 --- a/src/useShareIntent.tsx +++ b/src/useShareIntent.tsx @@ -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?.(); @@ -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") {