From 93d328d2e0bc5bdaf30f91c49e1ee8857494950c Mon Sep 17 00:00:00 2001 From: gaodeng Date: Wed, 20 Dec 2023 13:23:03 +0800 Subject: [PATCH 1/2] Breaking: Update react-native-threads for RN 0.70+ API changes This commit revises react-native-threads to accommodate API changes introduced in React Native 0.70+. The update constitutes a breaking change for users on older React Native versions, who will need to use previous react-native-threads versions. --- ios/RNThread.podspec => RNThread.podspec | 4 ++-- .../java/com/reactlibrary/ReactContextBuilder.java | 12 ++++++------ .../com/reactlibrary/ThreadBaseReactPackage.java | 7 ++++--- ios/ThreadManager.m | 4 +++- package.json | 4 +++- 5 files changed, 18 insertions(+), 13 deletions(-) rename ios/RNThread.podspec => RNThread.podspec (83%) diff --git a/ios/RNThread.podspec b/RNThread.podspec similarity index 83% rename from ios/RNThread.podspec rename to RNThread.podspec index 704c326..dd403a9 100644 --- a/ios/RNThread.podspec +++ b/RNThread.podspec @@ -1,6 +1,6 @@ require 'json' -package = JSON.parse(File.read(File.join(__dir__, '../package.json'))) +package = JSON.parse(File.read(File.join(__dir__, './package.json'))) Pod::Spec.new do |s| s.name = "RNThread" @@ -11,7 +11,7 @@ Pod::Spec.new do |s| s.author = package['author'] s.homepage = "https://github.com/joltup/RNThread.git" s.source = { :git => "https://github.com/joltup/RNThread.git", :tag => s.version } - s.source_files = "**/*.{h,m}" + s.source_files = "ios/**/*.{h,m}" s.platform = :ios, "7.0" s.tvos.deployment_target = '10.0' diff --git a/android/src/main/java/com/reactlibrary/ReactContextBuilder.java b/android/src/main/java/com/reactlibrary/ReactContextBuilder.java index d14383c..0a5c384 100644 --- a/android/src/main/java/com/reactlibrary/ReactContextBuilder.java +++ b/android/src/main/java/com/reactlibrary/ReactContextBuilder.java @@ -12,7 +12,7 @@ import com.facebook.react.bridge.JavaScriptExecutorFactory; import com.facebook.react.jscexecutor.JSCExecutorFactory; import com.facebook.react.bridge.JavaScriptExecutor; -import com.facebook.react.bridge.NativeModuleCallExceptionHandler; +import com.facebook.react.bridge.JSExceptionHandler; import com.facebook.react.bridge.ReactApplicationContext; import com.facebook.react.ReactInstanceManager; import com.facebook.react.bridge.queue.ReactQueueConfigurationSpec; @@ -76,7 +76,7 @@ public ReactApplicationContext build() throws Exception { // fresh new react context final ReactApplicationContext reactContext = new ReactApplicationContext(parentContext); if (devSupportManager != null) { - reactContext.setNativeModuleCallExceptionHandler(devSupportManager); + reactContext.setJSExceptionHandler(devSupportManager); } // load native modules @@ -88,9 +88,9 @@ public ReactApplicationContext build() throws Exception { .setJSExecutor(jsExecutor) .setRegistry(nativeRegistryBuilder.build()) .setJSBundleLoader(jsBundleLoader) - .setNativeModuleCallExceptionHandler(devSupportManager != null + .setJSExceptionHandler(devSupportManager != null ? devSupportManager - : createNativeModuleExceptionHandler() + : createJSExceptionHandler() ); @@ -132,8 +132,8 @@ public Object call() throws Exception { return reactContext; } - private NativeModuleCallExceptionHandler createNativeModuleExceptionHandler() { - return new NativeModuleCallExceptionHandler() { + private JSExceptionHandler createJSExceptionHandler() { + return new JSExceptionHandler() { @Override public void handleException(Exception e) { throw new RuntimeException(e); diff --git a/android/src/main/java/com/reactlibrary/ThreadBaseReactPackage.java b/android/src/main/java/com/reactlibrary/ThreadBaseReactPackage.java index 353799c..65c77e1 100644 --- a/android/src/main/java/com/reactlibrary/ThreadBaseReactPackage.java +++ b/android/src/main/java/com/reactlibrary/ThreadBaseReactPackage.java @@ -9,12 +9,13 @@ import com.facebook.react.modules.core.ExceptionsManagerModule; import com.facebook.react.modules.core.TimingModule; import com.facebook.react.modules.debug.SourceCodeModule; +import com.facebook.react.modules.deviceinfo.DeviceInfoModule; import com.facebook.react.modules.intent.IntentModule; import com.facebook.react.modules.network.NetworkingModule; -import com.facebook.react.modules.storage.AsyncStorageModule; import com.facebook.react.modules.systeminfo.AndroidInfoModule; import com.facebook.react.modules.vibration.VibrationModule; import com.facebook.react.modules.websocket.WebSocketModule; +import com.facebook.react.uimanager.UIManagerModule; import com.facebook.react.uimanager.ViewManager; import com.facebook.react.modules.debug.DevSettingsModule; @@ -38,12 +39,12 @@ public List createNativeModules(ReactApplicationContext catalystAp new ExceptionsManagerModule(reactInstanceManager.getDevSupportManager()), new AppStateModule(catalystApplicationContext), new TimingModule(catalystApplicationContext, reactInstanceManager.getDevSupportManager()), - new UIManagerStubModule(catalystApplicationContext), + new UIManagerModule(catalystApplicationContext, reactInstanceManager.getOrCreateViewManagers(catalystApplicationContext), -1), + new DeviceInfoModule(catalystApplicationContext), new SourceCodeModule(catalystApplicationContext), new JSCHeapCapture(catalystApplicationContext), // Main list - new AsyncStorageModule(catalystApplicationContext), new IntentModule(catalystApplicationContext), new NetworkingModule(catalystApplicationContext), new VibrationModule(catalystApplicationContext), diff --git a/ios/ThreadManager.m b/ios/ThreadManager.m index 3aa1bba..a600439 100644 --- a/ios/ThreadManager.m +++ b/ios/ThreadManager.m @@ -20,7 +20,9 @@ @implementation ThreadManager int threadId = abs(arc4random()); - NSURL *threadURL = [[RCTBundleURLProvider sharedSettings] jsBundleURLForBundleRoot:name fallbackResource:name]; + NSURL *threadURL = [[RCTBundleURLProvider sharedSettings] jsBundleURLForBundleRoot:name fallbackURLProvider:^NSURL * { + return [[NSBundle mainBundle] URLForResource:name withExtension:@"jsbundle"]; + }]; NSLog(@"starting Thread %@", [threadURL absoluteString]); diff --git a/package.json b/package.json index 73233fc..2742f17 100644 --- a/package.json +++ b/package.json @@ -24,7 +24,9 @@ "android/", "ios/", "js/", - "index.js" + "index.js", + "react-native.config.js", + "RNThread.podspec" ], "peerDependencies": { "react-native": ">=0.50.0" From e41e53a53f480030865860b898bf85712d321a5b Mon Sep 17 00:00:00 2001 From: gaodeng Date: Wed, 27 Dec 2023 18:58:44 +0800 Subject: [PATCH 2/2] Reinstate main RCTBridge post-thread-bridge setup --- ios/ThreadManager.m | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/ios/ThreadManager.m b/ios/ThreadManager.m index a600439..cef7f37 100644 --- a/ios/ThreadManager.m +++ b/ios/ThreadManager.m @@ -26,9 +26,12 @@ @implementation ThreadManager NSLog(@"starting Thread %@", [threadURL absoluteString]); - RCTBridge *threadBridge = [[RCTBridge alloc] initWithBundleURL:threadURL + RCTBridge* currentBridge = RCTBridge.currentBridge; + RCTBridge *threadBridge = [[RCTBridge alloc] initWithBundleURL:threadURL moduleProvider:nil launchOptions:nil]; + RCTBridge.currentBridge = currentBridge; + ThreadSelfManager *threadSelf = [threadBridge moduleForName:@"ThreadSelfManager"]; [threadSelf setThreadId:threadId];