From 96f442bd2551c2ab508ae360c7790d890990f6b8 Mon Sep 17 00:00:00 2001 From: lin onetwo Date: Fri, 15 Mar 2024 20:11:02 +0800 Subject: [PATCH] fix: use expo go https://github.com/achorein/expo-share-intent/issues/23 --- src/services/NativeService/hooks.ts | 36 ++++++++++++++--------------- 1 file changed, 18 insertions(+), 18 deletions(-) diff --git a/src/services/NativeService/hooks.ts b/src/services/NativeService/hooks.ts index a84e84c..7a742aa 100644 --- a/src/services/NativeService/hooks.ts +++ b/src/services/NativeService/hooks.ts @@ -1,17 +1,5 @@ /* eslint-disable @typescript-eslint/strict-boolean-expressions */ -/** If you get error on development: - * ``` - * Error: Cannot find native module 'ExpoShareIntentModule', js engine: hermes - * Invariant Violation: "main" has not been registered. This can happen if: -* Metro (the local dev server) is run from the wrong folder. Check if Metro is running, stop it and restart it in the current project. -* A module failed to load due to an error and `AppRegistry.registerComponent` wasn't called., js engine: hermes - * ``` - * - * Comment out this import will work. - * - * Also comment out all code inside `useRegisterReceivingShareIntent`. - */ -import { useShareIntent } from 'expo-share-intent'; +import type { useShareIntent as IUseShareIntent } from 'expo-share-intent'; import { useEffect } from 'react'; import { useRegisterProxy } from 'react-native-postmessage-cat'; import { nativeService } from '.'; @@ -32,8 +20,23 @@ export function useRequestNativePermissions() { } export function useRegisterReceivingShareIntent() { - /** UnComment `return;` to fix `Error: Cannot find native module 'ExpoShareIntentModule', js engine: hermes` */ - // return; + /** If you get error on development: + * ``` + * Error: Cannot find native module 'ExpoShareIntentModule', js engine: hermes + * Invariant Violation: "main" has not been registered. This can happen if: + * Metro (the local dev server) is run from the wrong folder. Check if Metro is running, stop it and restart it in the current project. + * A module failed to load due to an error and `AppRegistry.registerComponent` wasn't called., js engine: hermes + * ``` + * + * Comment out this import will work. + * + * Also comment out all code inside `useRegisterReceivingShareIntent`. + */ + if (process.env.NODE_ENV === 'development') { + return; + } + const { useShareIntent } = require('expo-share-intent') as { useShareIntent: typeof IUseShareIntent }; + /* eslint-disable react-hooks/rules-of-hooks */ const { hasShareIntent, shareIntent, resetShareIntent, error } = useShareIntent({ debug: true, }); @@ -44,9 +47,6 @@ export function useRegisterReceivingShareIntent() { `Failed to get ShareIntent, This is normal if you are using Expo Go for dev. To debug sharing feature, create a dev build "pnpm start:devClient" instead. ${error}`, ); } - // if (process.env.NODE_ENV === 'development') { - // return; - // } void (async () => { try { if (hasShareIntent) {