From 53b28b5e07a39fae3a10a55641b618d4ce94ad4f Mon Sep 17 00:00:00 2001 From: BrtqKr Date: Fri, 1 Mar 2024 18:19:16 +0100 Subject: [PATCH] cleanup, android share extension fix wip --- .../expensify/chat/ExpensifyAppPackage.java | 1 + .../java/com/expensify/chat/MainActivity.kt | 16 ++--- .../com/expensify/chat/MainApplication.kt | 3 +- ...rModule.kt => ShareActionHandlerModule.kt} | 6 +- .../intentHandler/AbstractIntentHandler.kt | 5 ++ .../chat/intentHandler/ImageIntentHandler.kt | 10 +-- .../chat/intentHandler/IntentHandler.kt | 1 + .../intentHandler/IntentHandlerFactory.kt | 14 ++++ .../ShareExtensionHandlerPackage.kt | 19 ------ ios/NewExpensify.xcodeproj/project.pbxproj | 24 +++++-- ios/RCTShareActionHandlerModule.h | 16 +++++ ...Module.m => RCTShareActionHandlerModule.m} | 20 +++--- ...Expensify:RCTShareExtensionHandlerModule.h | 15 ----- src/modules/ShareActionHandlerModule.ts | 9 +++ src/modules/ShareExtensionHandlerModule.ts | 9 --- src/pages/share/ShareRootPage.tsx | 65 ++++++++++--------- 16 files changed, 126 insertions(+), 107 deletions(-) rename android/app/src/main/java/com/expensify/chat/{shareExtensionHandler/ShareExtensionHandlerModule.kt => ShareActionHandlerModule.kt} (79%) create mode 100644 android/app/src/main/java/com/expensify/chat/intentHandler/AbstractIntentHandler.kt create mode 100644 android/app/src/main/java/com/expensify/chat/intentHandler/IntentHandlerFactory.kt delete mode 100644 android/app/src/main/java/com/expensify/chat/shareExtensionHandler/ShareExtensionHandlerPackage.kt create mode 100644 ios/RCTShareActionHandlerModule.h rename ios/{RCTShareExtensionHandlerModule.m => RCTShareActionHandlerModule.m} (80%) delete mode 100644 ios/ios:NewExpensify:RCTShareExtensionHandlerModule.h create mode 100644 src/modules/ShareActionHandlerModule.ts delete mode 100644 src/modules/ShareExtensionHandlerModule.ts diff --git a/android/app/src/main/java/com/expensify/chat/ExpensifyAppPackage.java b/android/app/src/main/java/com/expensify/chat/ExpensifyAppPackage.java index 63195d50b2cb..3d651e907d76 100644 --- a/android/app/src/main/java/com/expensify/chat/ExpensifyAppPackage.java +++ b/android/app/src/main/java/com/expensify/chat/ExpensifyAppPackage.java @@ -22,6 +22,7 @@ public List createNativeModules( List modules = new ArrayList<>(); modules.add(new StartupTimer(reactContext)); + modules.add(new ShareActionHandlerModule(reactContext)); return modules; } diff --git a/android/app/src/main/java/com/expensify/chat/MainActivity.kt b/android/app/src/main/java/com/expensify/chat/MainActivity.kt index 1af7daa535df..0969a2c9b4d3 100644 --- a/android/app/src/main/java/com/expensify/chat/MainActivity.kt +++ b/android/app/src/main/java/com/expensify/chat/MainActivity.kt @@ -9,7 +9,7 @@ import android.view.View import android.view.WindowInsets import com.expensify.chat.bootsplash.BootSplash import com.expensify.chat.intentHandler.ImageIntentHandler -import com.expensify.chat.intentHandler.IntentHandler +import com.expensify.chat.intentHandler.IntentHandlerFactory import com.expensify.reactnativekeycommand.KeyCommandModule import com.facebook.react.ReactActivity import com.facebook.react.ReactActivityDelegate @@ -18,8 +18,6 @@ import com.facebook.react.defaults.DefaultReactActivityDelegate import expo.modules.ReactActivityDelegateWrapper class MainActivity : ReactActivity() { - private lateinit var imageIntentHandler: IntentHandler - /** * Returns the name of the main component registered from JavaScript. This is used to schedule * rendering of the component. @@ -59,20 +57,20 @@ class MainActivity : ReactActivity() { ) } - imageIntentHandler = ImageIntentHandler(this) - if (intent != null) { - imageIntentHandler.handle(intent) + handleIntent(intent) } } override fun onNewIntent(intent: Intent) { super.onNewIntent(intent) setIntent(intent) // Must store the new intent unless getIntent() will return the old one + handleIntent(intent) + } - if (intent != null) { - imageIntentHandler.handle(intent) - } + private fun handleIntent(intent: Intent) { + val intentHandler = IntentHandlerFactory.getIntentHandler(this, intent.type) + intentHandler?.handle(intent) } /** diff --git a/android/app/src/main/java/com/expensify/chat/MainApplication.kt b/android/app/src/main/java/com/expensify/chat/MainApplication.kt index e97b6e63720d..a6e762c82e63 100644 --- a/android/app/src/main/java/com/expensify/chat/MainApplication.kt +++ b/android/app/src/main/java/com/expensify/chat/MainApplication.kt @@ -6,7 +6,6 @@ import android.database.CursorWindow import android.os.Process import androidx.multidex.MultiDexApplication import com.expensify.chat.bootsplash.BootSplashPackage -import com.expensify.chat.shareExtensionHandler.ShareExtensionHandlerPackage import com.facebook.react.PackageList import com.facebook.react.ReactApplication import com.facebook.react.ReactNativeHost @@ -30,7 +29,7 @@ class MainApplication : MultiDexApplication(), ReactApplication { add(BootSplashPackage()) add(ExpensifyAppPackage()) add(RNTextInputResetPackage()) - add(ShareExtensionHandlerPackage()) +// add(ShareExtensionHandlerPackage()) } override fun getJSMainModuleName() = ".expo/.virtual-metro-entry" diff --git a/android/app/src/main/java/com/expensify/chat/shareExtensionHandler/ShareExtensionHandlerModule.kt b/android/app/src/main/java/com/expensify/chat/ShareActionHandlerModule.kt similarity index 79% rename from android/app/src/main/java/com/expensify/chat/shareExtensionHandler/ShareExtensionHandlerModule.kt rename to android/app/src/main/java/com/expensify/chat/ShareActionHandlerModule.kt index ab80eb5dc628..e4ca0852e519 100644 --- a/android/app/src/main/java/com/expensify/chat/shareExtensionHandler/ShareExtensionHandlerModule.kt +++ b/android/app/src/main/java/com/expensify/chat/ShareActionHandlerModule.kt @@ -1,4 +1,4 @@ -package com.expensify.chat.shareExtensionHandler +package com.expensify.chat import com.facebook.react.bridge.Arguments import com.facebook.react.bridge.Callback @@ -6,8 +6,8 @@ import com.facebook.react.bridge.ReactApplicationContext import com.facebook.react.bridge.ReactContextBaseJavaModule import com.facebook.react.bridge.ReactMethod -class ShareExtensionHandlerModule(reactContext: ReactApplicationContext) : ReactContextBaseJavaModule(reactContext) { - override fun getName() = "ShareExtensionHandlerModule" +class ShareActionHandlerModule(reactContext: ReactApplicationContext) : ReactContextBaseJavaModule(reactContext) { + override fun getName() = "ShareActionHandlerModule" @ReactMethod fun processFiles(callback: Callback) { diff --git a/android/app/src/main/java/com/expensify/chat/intentHandler/AbstractIntentHandler.kt b/android/app/src/main/java/com/expensify/chat/intentHandler/AbstractIntentHandler.kt new file mode 100644 index 000000000000..a58c687bee56 --- /dev/null +++ b/android/app/src/main/java/com/expensify/chat/intentHandler/AbstractIntentHandler.kt @@ -0,0 +1,5 @@ +package com.expensify.chat.intentHandler + +abstract class AbstractIntentHandler: IntentHandler { + override fun onCompleted() {} +} \ No newline at end of file diff --git a/android/app/src/main/java/com/expensify/chat/intentHandler/ImageIntentHandler.kt b/android/app/src/main/java/com/expensify/chat/intentHandler/ImageIntentHandler.kt index b7f26d4ae230..e4532a3c021f 100644 --- a/android/app/src/main/java/com/expensify/chat/intentHandler/ImageIntentHandler.kt +++ b/android/app/src/main/java/com/expensify/chat/intentHandler/ImageIntentHandler.kt @@ -7,7 +7,7 @@ import android.util.Log import com.expensify.chat.image.ImageUtils.copyUriToStorage -class ImageIntentHandler(private val context: Context) : IntentHandler { +class ImageIntentHandler(private val context: Context) : AbstractIntentHandler() { override fun handle(intent: Intent?): Boolean { Log.i("ImageIntentHandler", "Handle intent" + intent.toString()) if (intent == null) { @@ -22,13 +22,13 @@ class ImageIntentHandler(private val context: Context) : IntentHandler { when(action) { Intent.ACTION_SEND -> { Log.i("ImageIntentHandler", "Handle receive single image") -// handleSingleImageIntent(intent, context) - openShareRoot() + handleSingleImageIntent(intent, context) + onCompleted() return true } Intent.ACTION_SEND_MULTIPLE -> { handleMultipleImagesIntent(intent, context) - openShareRoot() + onCompleted() return true } } @@ -65,7 +65,7 @@ class ImageIntentHandler(private val context: Context) : IntentHandler { // Yapl.getInstance().callIntentCallback(resultingImagePaths) } - private fun openShareRoot() { + override fun onCompleted() { val uri: Uri = Uri.parse("new-expensify://share/root") val deepLinkIntent = Intent(Intent.ACTION_VIEW, uri) deepLinkIntent.flags = Intent.FLAG_ACTIVITY_NEW_TASK diff --git a/android/app/src/main/java/com/expensify/chat/intentHandler/IntentHandler.kt b/android/app/src/main/java/com/expensify/chat/intentHandler/IntentHandler.kt index 0b98c0d13bde..6cd93dff276a 100644 --- a/android/app/src/main/java/com/expensify/chat/intentHandler/IntentHandler.kt +++ b/android/app/src/main/java/com/expensify/chat/intentHandler/IntentHandler.kt @@ -4,4 +4,5 @@ import android.content.Intent interface IntentHandler { fun handle(intent: Intent?): Boolean + fun onCompleted() } \ No newline at end of file diff --git a/android/app/src/main/java/com/expensify/chat/intentHandler/IntentHandlerFactory.kt b/android/app/src/main/java/com/expensify/chat/intentHandler/IntentHandlerFactory.kt new file mode 100644 index 000000000000..c89af09e2b50 --- /dev/null +++ b/android/app/src/main/java/com/expensify/chat/intentHandler/IntentHandlerFactory.kt @@ -0,0 +1,14 @@ +package com.expensify.chat.intentHandler + +import android.content.Context + +object IntentHandlerFactory { + fun getIntentHandler(context: Context, mimeType: String?): IntentHandler? { + if (mimeType == null) return null + return when { + mimeType.startsWith("image/") -> ImageIntentHandler(context) + // Add other cases like video/*, application/pdf etc. + else -> null + } + } +} \ No newline at end of file diff --git a/android/app/src/main/java/com/expensify/chat/shareExtensionHandler/ShareExtensionHandlerPackage.kt b/android/app/src/main/java/com/expensify/chat/shareExtensionHandler/ShareExtensionHandlerPackage.kt deleted file mode 100644 index 982f9fa4eaba..000000000000 --- a/android/app/src/main/java/com/expensify/chat/shareExtensionHandler/ShareExtensionHandlerPackage.kt +++ /dev/null @@ -1,19 +0,0 @@ -package com.expensify.chat.shareExtensionHandler - -import android.view.View -import com.facebook.react.ReactPackage -import com.facebook.react.bridge.NativeModule -import com.facebook.react.bridge.ReactApplicationContext -import com.facebook.react.uimanager.ReactShadowNode -import com.facebook.react.uimanager.ViewManager - -class ShareExtensionHandlerPackage : ReactPackage { - - override fun createViewManagers( - reactContext: ReactApplicationContext - ): MutableList>> = mutableListOf() - - override fun createNativeModules( - reactContext: ReactApplicationContext - ): MutableList = listOf(ShareExtensionHandlerModule(reactContext)).toMutableList() -} \ No newline at end of file diff --git a/ios/NewExpensify.xcodeproj/project.pbxproj b/ios/NewExpensify.xcodeproj/project.pbxproj index 317b79c19c0d..8fc9e8ae99c4 100644 --- a/ios/NewExpensify.xcodeproj/project.pbxproj +++ b/ios/NewExpensify.xcodeproj/project.pbxproj @@ -39,11 +39,13 @@ BDB853621F354EBB84E619C2 /* ExpensifyNewKansas-MediumItalic.otf in Resources */ = {isa = PBXBuildFile; fileRef = D2AFB39EC1D44BF9B91D3227 /* ExpensifyNewKansas-MediumItalic.otf */; }; DD79042B2792E76D004484B4 /* RCTBootSplash.m in Sources */ = {isa = PBXBuildFile; fileRef = DD79042A2792E76D004484B4 /* RCTBootSplash.m */; }; DDCB2E57F334C143AC462B43 /* ExpoModulesProvider.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4D20D83B0E39BA6D21761E72 /* ExpoModulesProvider.swift */; }; - E51DC681C7DEE40AEBDDFBFE /* (null) in Frameworks */ = {isa = PBXBuildFile; }; + E51DC681C7DEE40AEBDDFBFE /* BuildFile in Frameworks */ = {isa = PBXBuildFile; }; E5647A4A2B8E0CE40047156F /* ShareViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = E5647A492B8E0CE40047156F /* ShareViewController.swift */; }; E5647A4D2B8E0CE40047156F /* MainInterface.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = E5647A4B2B8E0CE40047156F /* MainInterface.storyboard */; }; E5647A512B8E0CE40047156F /* ShareMenuExtension.appex in Embed Foundation Extensions */ = {isa = PBXBuildFile; fileRef = E5647A472B8E0CE20047156F /* ShareMenuExtension.appex */; settings = {ATTRIBUTES = (RemoveHeadersOnCopy, ); }; }; - E5CB2F182B7F834000B63003 /* (null) in Embed Foundation Extensions */ = {isa = PBXBuildFile; settings = {ATTRIBUTES = (RemoveHeadersOnCopy, ); }; }; + E5647A5B2B9203B20047156F /* RCTShareActionHandlerModule.m in Sources */ = {isa = PBXBuildFile; fileRef = E5647A5A2B9203B10047156F /* RCTShareActionHandlerModule.m */; }; + E5647A5C2B9203B20047156F /* RCTShareActionHandlerModule.m in Sources */ = {isa = PBXBuildFile; fileRef = E5647A5A2B9203B10047156F /* RCTShareActionHandlerModule.m */; }; + E5CB2F182B7F834000B63003 /* BuildFile in Embed Foundation Extensions */ = {isa = PBXBuildFile; settings = {ATTRIBUTES = (RemoveHeadersOnCopy, ); }; }; E9DF872D2525201700607FDC /* AirshipConfig.plist in Resources */ = {isa = PBXBuildFile; fileRef = E9DF872C2525201700607FDC /* AirshipConfig.plist */; }; ED222ED90E074A5481A854FA /* ExpensifyNeue-BoldItalic.otf in Resources */ = {isa = PBXBuildFile; fileRef = 8B28D84EF339436DBD42A203 /* ExpensifyNeue-BoldItalic.otf */; }; F0C450EA2705020500FD2970 /* colors.json in Resources */ = {isa = PBXBuildFile; fileRef = F0C450E92705020500FD2970 /* colors.json */; }; @@ -82,7 +84,7 @@ dstSubfolderSpec = 13; files = ( 7FD73CA22B23CE9500420AF3 /* NotificationServiceExtension.appex in Embed Foundation Extensions */, - E5CB2F182B7F834000B63003 /* (null) in Embed Foundation Extensions */, + E5CB2F182B7F834000B63003 /* BuildFile in Embed Foundation Extensions */, E5647A512B8E0CE40047156F /* ShareMenuExtension.appex in Embed Foundation Extensions */, ); name = "Embed Foundation Extensions"; @@ -150,6 +152,8 @@ E5647A492B8E0CE40047156F /* ShareViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ShareViewController.swift; sourceTree = ""; }; E5647A4C2B8E0CE40047156F /* Base */ = {isa = PBXFileReference; lastKnownFileType = file.storyboard; name = Base; path = Base.lproj/MainInterface.storyboard; sourceTree = ""; }; E5647A4E2B8E0CE40047156F /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = ""; }; + E5647A592B9202B50047156F /* RCTShareActionHandlerModule.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = RCTShareActionHandlerModule.h; sourceTree = ""; }; + E5647A5A2B9203B10047156F /* RCTShareActionHandlerModule.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = RCTShareActionHandlerModule.m; sourceTree = ""; }; E704648954784DDFBAADF568 /* ExpensifyMono-Regular.otf */ = {isa = PBXFileReference; explicitFileType = undefined; fileEncoding = 9; includeInIndex = 0; lastKnownFileType = unknown; name = "ExpensifyMono-Regular.otf"; path = "../assets/fonts/native/ExpensifyMono-Regular.otf"; sourceTree = ""; }; E750C93A45B47BDC5149C5AA /* Pods-NewExpensify-NewExpensifyTests.debugdevelopment.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-NewExpensify-NewExpensifyTests.debugdevelopment.xcconfig"; path = "Target Support Files/Pods-NewExpensify-NewExpensifyTests/Pods-NewExpensify-NewExpensifyTests.debugdevelopment.xcconfig"; sourceTree = ""; }; E9DF872C2525201700607FDC /* AirshipConfig.plist */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.plist.xml; path = AirshipConfig.plist; sourceTree = ""; }; @@ -173,8 +177,8 @@ isa = PBXFrameworksBuildPhase; buildActionMask = 2147483647; files = ( - E51DC681C7DEE40AEBDDFBFE /* (null) in Frameworks */, - E51DC681C7DEE40AEBDDFBFE /* (null) in Frameworks */, + E51DC681C7DEE40AEBDDFBFE /* BuildFile in Frameworks */, + E51DC681C7DEE40AEBDDFBFE /* BuildFile in Frameworks */, 5B8996A7D8B007ECC41919E1 /* libPods-NewExpensify.a in Frameworks */, ); runOnlyForDeploymentPostprocessing = 0; @@ -280,6 +284,8 @@ 83CBB9F61A601CBA00E9B192 = { isa = PBXGroup; children = ( + E5647A5A2B9203B10047156F /* RCTShareActionHandlerModule.m */, + E5647A592B9202B50047156F /* RCTShareActionHandlerModule.h */, 374FB8D528A133A7000D84EF /* OriginImageRequestHandler.h */, 374FB8D628A133FE000D84EF /* OriginImageRequestHandler.mm */, F0C450E92705020500FD2970 /* colors.json */, @@ -890,6 +896,7 @@ 0CDA8E35287DD650004ECBEC /* AppDelegate.mm in Sources */, 7041848626A8E47D00E09F4D /* RCTStartupTimer.m in Sources */, 7F5E81F06BCCF61AD02CEA06 /* ExpoModulesProvider.swift in Sources */, + E5647A5C2B9203B20047156F /* RCTShareActionHandlerModule.m in Sources */, ); runOnlyForDeploymentPostprocessing = 0; }; @@ -897,6 +904,7 @@ isa = PBXSourcesBuildPhase; buildActionMask = 2147483647; files = ( + E5647A5B2B9203B20047156F /* RCTShareActionHandlerModule.m in Sources */, 18D050E0262400AF000D658B /* BridgingFile.swift in Sources */, 0F5E5350263B73FD004CA14F /* EnvironmentChecker.m in Sources */, 374FB8D728A133FE000D84EF /* OriginImageRequestHandler.mm in Sources */, @@ -2351,6 +2359,7 @@ MTL_ENABLE_DEBUG_INFO = INCLUDE_SOURCE; MTL_FAST_MATH = YES; ONLY_ACTIVE_ARCH = YES; + OTHER_SWIFT_FLAGS = "$(inherited) -D EXPO_CONFIGURATION_DEBUG"; PRODUCT_BUNDLE_IDENTIFIER = com.expensify.chat.dev.ShareMenuExtension; PRODUCT_NAME = "$(TARGET_NAME)"; SDKROOT = iphoneos; @@ -2434,6 +2443,7 @@ MTL_ENABLE_DEBUG_INFO = INCLUDE_SOURCE; MTL_FAST_MATH = YES; ONLY_ACTIVE_ARCH = YES; + OTHER_SWIFT_FLAGS = "$(inherited) -D EXPO_CONFIGURATION_DEBUG"; PRODUCT_BUNDLE_IDENTIFIER = com.expensify.chat.dev.ShareMenuExtension; PRODUCT_NAME = "$(TARGET_NAME)"; SDKROOT = iphoneos; @@ -2517,6 +2527,7 @@ MTL_ENABLE_DEBUG_INFO = INCLUDE_SOURCE; MTL_FAST_MATH = YES; ONLY_ACTIVE_ARCH = YES; + OTHER_SWIFT_FLAGS = "$(inherited) -D EXPO_CONFIGURATION_DEBUG"; PRODUCT_BUNDLE_IDENTIFIER = com.expensify.chat.dev.ShareMenuExtension; PRODUCT_NAME = "$(TARGET_NAME)"; SDKROOT = iphoneos; @@ -2594,6 +2605,7 @@ MARKETING_VERSION = 1.0; MTL_ENABLE_DEBUG_INFO = NO; MTL_FAST_MATH = YES; + OTHER_SWIFT_FLAGS = "$(inherited) -D EXPO_CONFIGURATION_RELEASE"; PRODUCT_BUNDLE_IDENTIFIER = com.expensify.chat.dev.ShareMenuExtension; PRODUCT_NAME = "$(TARGET_NAME)"; SDKROOT = iphoneos; @@ -2670,6 +2682,7 @@ MARKETING_VERSION = 1.0; MTL_ENABLE_DEBUG_INFO = NO; MTL_FAST_MATH = YES; + OTHER_SWIFT_FLAGS = "$(inherited) -D EXPO_CONFIGURATION_RELEASE"; PRODUCT_BUNDLE_IDENTIFIER = com.expensify.chat.dev.ShareMenuExtension; PRODUCT_NAME = "$(TARGET_NAME)"; SDKROOT = iphoneos; @@ -2746,6 +2759,7 @@ MARKETING_VERSION = 1.0; MTL_ENABLE_DEBUG_INFO = NO; MTL_FAST_MATH = YES; + OTHER_SWIFT_FLAGS = "$(inherited) -D EXPO_CONFIGURATION_RELEASE"; PRODUCT_BUNDLE_IDENTIFIER = com.expensify.chat.dev.ShareMenuExtension; PRODUCT_NAME = "$(TARGET_NAME)"; SDKROOT = iphoneos; diff --git a/ios/RCTShareActionHandlerModule.h b/ios/RCTShareActionHandlerModule.h new file mode 100644 index 000000000000..ee8d186edb0d --- /dev/null +++ b/ios/RCTShareActionHandlerModule.h @@ -0,0 +1,16 @@ +// +// RCTShareActionHandlerModule.h +// NewExpensify +// +// Created by Bartek Krasoń on 01/03/2024. +// + +#ifndef RCTShareActionHandlerModule_h +#define RCTShareActionHandlerModule_h + +#import + +@interface RCTShareActionHandlerModule : NSObject +@end + +#endif /* RCTShareActionHandlerModule_h */ diff --git a/ios/RCTShareExtensionHandlerModule.m b/ios/RCTShareActionHandlerModule.m similarity index 80% rename from ios/RCTShareExtensionHandlerModule.m rename to ios/RCTShareActionHandlerModule.m index 8779ed80d2ff..269faec4f0a4 100644 --- a/ios/RCTShareExtensionHandlerModule.m +++ b/ios/RCTShareActionHandlerModule.m @@ -1,21 +1,21 @@ // -// RCTShareExtensionHandlerModule.m +// RCTShareActionHandlerModule.m // NewExpensify // -// Created by Bartek Krasoń on 23/02/2024. +// Created by Bartek Krasoń on 01/03/2024. // #import -#import "ios:NewExpensify:RCTShareExtensionHandlerModule.h" +#import "RCTShareActionHandlerModule.h" #import NSString *const ShareExtensionGroupIdentifier = @"group.com.new-expensify"; NSString *const ShareExtensionFilesKey = @"ShareFiles"; NSString *const ShareImageFileExtension = @".png"; -@implementation RCTShareExtensionHandlerModule +@implementation RCTShareActionHandlerModule -RCT_EXPORT_MODULE(RCTShareExtensionHandlerModule); +RCT_EXPORT_MODULE(RCTShareActionHandlerModule); RCT_EXPORT_METHOD(processFiles:(RCTResponseSenderBlock)callback) { @@ -37,10 +37,10 @@ @implementation RCTShareExtensionHandlerModule NSArray *imageSrcPath = [[NSFileManager defaultManager] contentsOfDirectoryAtPath:sharedImagesFolderPath error:&error]; if (imageSrcPath.count == 0) { - NSLog(@"handleShareExtension Failed to find images in 'sharedImagesFolderPath'"); + NSLog(@"handleShareAction Failed to find images in 'sharedImagesFolderPath'"); return; } - NSLog(@"handleShareExtension shared %lu images", imageSrcPath.count); + NSLog(@"handleShareAction shared %lu images", imageSrcPath.count); NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES); NSString *documentsDirectory = [paths objectAtIndex:0]; @@ -48,14 +48,14 @@ @implementation RCTShareExtensionHandlerModule for (int i = 0; i < imageSrcPath.count; i++) { if (imageSrcPath[i] == NULL) { - NSLog(@"handleShareExtension Invalid image in position %d, imageSrcPath[i] is nil", i); + NSLog(@"handleShareAction Invalid image in position %d, imageSrcPath[i] is nil", i); continue; } - NSLog(@"handleShareExtension Valid image in position %d", i); + NSLog(@"handleShareAction Valid image in position %d", i); NSString *srcImageAbsolutePath = [sharedImagesFolderPath stringByAppendingPathComponent:imageSrcPath[i]]; UIImage *smartScanImage = [[UIImage alloc] initWithContentsOfFile:srcImageAbsolutePath]; if (smartScanImage == NULL) { - NSLog(@"handleShareExtension Failed to load image %@", srcImageAbsolutePath); + NSLog(@"handleShareAction Failed to load image %@", srcImageAbsolutePath); continue; } diff --git a/ios/ios:NewExpensify:RCTShareExtensionHandlerModule.h b/ios/ios:NewExpensify:RCTShareExtensionHandlerModule.h deleted file mode 100644 index 161bb3496766..000000000000 --- a/ios/ios:NewExpensify:RCTShareExtensionHandlerModule.h +++ /dev/null @@ -1,15 +0,0 @@ -// -// ios:NewExpensify:RCTShareExtensionHandlerModule.h -// NewExpensify -// -// Created by Bartek Krasoń on 23/02/2024. -// - -#ifndef ios_NewExpensify_RCTShareExtensionHandlerModule_h -#define ios_NewExpensify_RCTShareExtensionHandlerModule_h - -#import -@interface RCTShareExtensionHandlerModule : NSObject -@end - -#endif /* ios_NewExpensify_RCTShareExtensionHandlerModule_h */ diff --git a/src/modules/ShareActionHandlerModule.ts b/src/modules/ShareActionHandlerModule.ts new file mode 100644 index 000000000000..34add7ae6e6a --- /dev/null +++ b/src/modules/ShareActionHandlerModule.ts @@ -0,0 +1,9 @@ +import {NativeModules} from 'react-native'; + +const {ShareActionHandlerModule} = NativeModules; + +type ShareActionHandlerType = { + processFiles(callback: (array: string[]) => void): void; +}; + +export default ShareActionHandlerModule as ShareActionHandlerType; diff --git a/src/modules/ShareExtensionHandlerModule.ts b/src/modules/ShareExtensionHandlerModule.ts deleted file mode 100644 index a283189ca9c6..000000000000 --- a/src/modules/ShareExtensionHandlerModule.ts +++ /dev/null @@ -1,9 +0,0 @@ -import {NativeModules} from 'react-native'; - -const {ShareExtensionHandlerModule} = NativeModules; - -type ShareExtensionHandlerType = { - processFiles(callback: (array: string[]) => void): void; -}; - -export default ShareExtensionHandlerModule as ShareExtensionHandlerType; diff --git a/src/pages/share/ShareRootPage.tsx b/src/pages/share/ShareRootPage.tsx index b482d15a1030..b1ecdb2703cd 100644 --- a/src/pages/share/ShareRootPage.tsx +++ b/src/pages/share/ShareRootPage.tsx @@ -1,6 +1,6 @@ import React, {useCallback, useEffect, useRef} from 'react'; import type {AppStateStatus} from 'react-native'; -import {AppState, View} from 'react-native'; +import {AppState, Platform, View} from 'react-native'; import type {OnyxEntry} from 'react-native-onyx'; import {withOnyx} from 'react-native-onyx'; import HeaderWithBackButton from '@components/HeaderWithBackButton'; @@ -15,7 +15,7 @@ import Navigation from '@navigation/Navigation'; import OnyxTabNavigator, {TopTab} from '@navigation/OnyxTabNavigator'; import MoneyRequestParticipantsSelector from '@pages/iou/steps/MoneyRequstParticipantsPage/MoneyRequestParticipantsSelector'; import CONST from '@src/CONST'; -import ShareExtensionHandlerModule from '@src/modules/ShareExtensionHandlerModule'; +// import ShareActionHandlerModule from '@src/modules/ShareActionHandlerModule'; import ONYXKEYS from '@src/ONYXKEYS'; import ROUTES from '@src/ROUTES'; import type {Report} from '@src/types/onyx'; @@ -37,26 +37,41 @@ function ShareRootPage({selectedTab, iou}: ShareRootPageProps) { const selectedReportID = useRef(optimisticReportID); const appState = useRef(AppState.currentState); - const handleAppStateChange = (nextAppState: AppStateStatus) => { - if (appState.current.match(/inactive|background/) && nextAppState === 'active') { - ShareExtensionHandlerModule?.processFiles((processedFiles) => { - // eslint-disable-next-line no-console - console.log('PROCESSED FILES ', processedFiles); - }); - } - - appState.current = nextAppState; - // eslint-disable-next-line no-console - console.log('AppState', appState.current); - }; + // const handleAppStateChange = (nextAppState: AppStateStatus) => { + // if (appState.current.match(/inactive|background/) && nextAppState === 'active') { + // console.log('PROCESSED FILES ATTEMPT'); + + // ShareActionHandlerModule.processFiles((processedFiles) => { + // // eslint-disable-next-line no-console + // console.log('PROCESSED FILES ', processedFiles); + // }); + // } + + // appState.current = nextAppState; + // // eslint-disable-next-line no-console + // console.log('AppState', appState.current); + // }; + + // const handleAppStateFocus = (nextAppState: AppStateStatus) => { + // console.log('PROCESSED FILES ATTEMPT'); - useEffect(() => { - const appStateSubscription = AppState.addEventListener('change', handleAppStateChange); + // ShareActionHandlerModule.processFiles((processedFiles) => { + // // eslint-disable-next-line no-console + // console.log('PROCESSED FILES ', processedFiles); + // }); - return () => { - appStateSubscription.remove(); - }; - }, []); + // appState.current = nextAppState; + // // eslint-disable-next-line no-console + // console.log('AppState', appState.current); + // }; + + // useEffect(() => { + // const changeSubscription = Platform.OS === 'ios' ? AppState.addEventListener('change', handleAppStateChange) : AppState.addEventListener('focus', handleAppStateFocus); + + // return () => { + // changeSubscription.remove(); + // }; + // }, []); const navigateBack = () => { Navigation.dismissModal(); @@ -131,13 +146,3 @@ function ShareRootPage({selectedTab, iou}: ShareRootPageProps) { } ShareRootPage.displayName = 'ShareRootPage'; - -export default withOnyx({ - selectedTab: { - key: `${ONYXKEYS.COLLECTION.SELECTED_TAB}${CONST.TAB.RECEIPT_TAB_ID}`, - }, - // @ts-expect-error To fix - iou: { - key: ONYXKEYS.IOU, - }, -})(ShareRootPage);