Skip to content

Commit

Permalink
cleanup, android share extension fix wip
Browse files Browse the repository at this point in the history
  • Loading branch information
BrtqKr committed Mar 1, 2024
1 parent 4715627 commit 53b28b5
Show file tree
Hide file tree
Showing 16 changed files with 126 additions and 107 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ public List<NativeModule> createNativeModules(
List<NativeModule> modules = new ArrayList<>();

modules.add(new StartupTimer(reactContext));
modules.add(new ShareActionHandlerModule(reactContext));

return modules;
}
Expand Down
16 changes: 7 additions & 9 deletions android/app/src/main/java/com/expensify/chat/MainActivity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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.
Expand Down Expand Up @@ -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)
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
package com.expensify.chat.shareExtensionHandler
package com.expensify.chat

import com.facebook.react.bridge.Arguments
import com.facebook.react.bridge.Callback
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) {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
package com.expensify.chat.intentHandler

abstract class AbstractIntentHandler: IntentHandler {
override fun onCompleted() {}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand All @@ -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
}
}
Expand Down Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,5 @@ import android.content.Intent

interface IntentHandler {
fun handle(intent: Intent?): Boolean
fun onCompleted()
}
Original file line number Diff line number Diff line change
@@ -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
}
}
}

This file was deleted.

24 changes: 19 additions & 5 deletions ios/NewExpensify.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -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 */; };
Expand Down Expand Up @@ -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";
Expand Down Expand Up @@ -150,6 +152,8 @@
E5647A492B8E0CE40047156F /* ShareViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ShareViewController.swift; sourceTree = "<group>"; };
E5647A4C2B8E0CE40047156F /* Base */ = {isa = PBXFileReference; lastKnownFileType = file.storyboard; name = Base; path = Base.lproj/MainInterface.storyboard; sourceTree = "<group>"; };
E5647A4E2B8E0CE40047156F /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = "<group>"; };
E5647A592B9202B50047156F /* RCTShareActionHandlerModule.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = RCTShareActionHandlerModule.h; sourceTree = "<group>"; };
E5647A5A2B9203B10047156F /* RCTShareActionHandlerModule.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = RCTShareActionHandlerModule.m; sourceTree = "<group>"; };
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 = "<group>"; };
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 = "<group>"; };
E9DF872C2525201700607FDC /* AirshipConfig.plist */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.plist.xml; path = AirshipConfig.plist; sourceTree = "<group>"; };
Expand All @@ -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;
Expand Down Expand Up @@ -280,6 +284,8 @@
83CBB9F61A601CBA00E9B192 = {
isa = PBXGroup;
children = (
E5647A5A2B9203B10047156F /* RCTShareActionHandlerModule.m */,
E5647A592B9202B50047156F /* RCTShareActionHandlerModule.h */,
374FB8D528A133A7000D84EF /* OriginImageRequestHandler.h */,
374FB8D628A133FE000D84EF /* OriginImageRequestHandler.mm */,
F0C450E92705020500FD2970 /* colors.json */,
Expand Down Expand Up @@ -890,13 +896,15 @@
0CDA8E35287DD650004ECBEC /* AppDelegate.mm in Sources */,
7041848626A8E47D00E09F4D /* RCTStartupTimer.m in Sources */,
7F5E81F06BCCF61AD02CEA06 /* ExpoModulesProvider.swift in Sources */,
E5647A5C2B9203B20047156F /* RCTShareActionHandlerModule.m in Sources */,
);
runOnlyForDeploymentPostprocessing = 0;
};
13B07F871A680F5B00A75B9A /* Sources */ = {
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 */,
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand Down
16 changes: 16 additions & 0 deletions ios/RCTShareActionHandlerModule.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
//
// RCTShareActionHandlerModule.h
// NewExpensify
//
// Created by Bartek Krasoń on 01/03/2024.
//

#ifndef RCTShareActionHandlerModule_h
#define RCTShareActionHandlerModule_h

#import <React/RCTBridgeModule.h>

@interface RCTShareActionHandlerModule : NSObject <RCTBridgeModule>
@end

#endif /* RCTShareActionHandlerModule_h */
Original file line number Diff line number Diff line change
@@ -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 <Foundation/Foundation.h>
#import "ios:NewExpensify:RCTShareExtensionHandlerModule.h"
#import "RCTShareActionHandlerModule.h"
#import <React/RCTLog.h>

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)
{
Expand All @@ -37,25 +37,25 @@ @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];
NSMutableArray *imageFinalPaths = [NSMutableArray array];

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;
}

Expand Down
15 changes: 0 additions & 15 deletions ios/ios:NewExpensify:RCTShareExtensionHandlerModule.h

This file was deleted.

9 changes: 9 additions & 0 deletions src/modules/ShareActionHandlerModule.ts
Original file line number Diff line number Diff line change
@@ -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;
Loading

0 comments on commit 53b28b5

Please sign in to comment.