-
Notifications
You must be signed in to change notification settings - Fork 467
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Convert library to TurboModule #910
Convert library to TurboModule #910
Conversation
a090679
to
1a99729
Compare
This PR has been marked as stale due to inactivity. Please address any comments within 7 days or it will be closed. |
# Conflicts: # android/build.gradle # package.json # react-native.config.js # src/RCTAsyncStorage.ts # yarn.lock
Hi Jakub, I have a branch with the iOS Turbomodule working, based on this PR: https://github.com/shwanton/async-storage/tree/%40shwanton/turbomodule-ios-working CleanShot.2023-06-13.at.22.17.12.mp4
I'm not super familiar w/ Android TM's, what is the current state? Would love to get this PR working so we can use this lib as Turbomodule! |
As far as I remember, both Android and iOS were ready to be merged at the time of submitting the PR. You can check if the Android version works and if it doesn't I will look into fixing it 😄. As a side note, what is the reason behind this change? In my opinion |
@@ -36,7 +36,7 @@ android.enableJetifier=true | |||
|
|||
# Enable new architecture, i.e. Fabric + TurboModule - implies USE_FABRIC=1. | |||
# Note that this is incompatible with web debugging. | |||
#newArchEnabled=true | |||
newArchEnabled=true |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do we want all examples to be newArchEnabled
?
:hermes_enabled => false, | ||
:turbomodule_enabled => true, | ||
} | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The podspec requires the RCT_NEW_ARCH_ENABLED
be passed to pod install
. Enabling these options w/o the flag will not enable new arch.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Edit: I misread. Let me check again. Will update this post.
Edit 2: I still can't repro this.
Are you sure about this? I've just tested in master
and it seems to be working?
diff --git a/RNCAsyncStorage.podspec b/RNCAsyncStorage.podspec
index 5d74402..45be872 100644
--- a/RNCAsyncStorage.podspec
+++ b/RNCAsyncStorage.podspec
@@ -2,6 +2,10 @@ require 'json'
package = JSON.parse(File.read(File.join(__dir__, 'package.json')))
+p '%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%'
+p ENV['RCT_NEW_ARCH_ENABLED']
+p '%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%'
+
Pod::Spec.new do |s|
s.name = "RNCAsyncStorage"
s.version = package['version']
diff --git a/example/macos/Podfile b/example/macos/Podfile
index 19f6452..0eda101 100644
--- a/example/macos/Podfile
+++ b/example/macos/Podfile
@@ -2,7 +2,13 @@ require_relative '../../node_modules/react-native-test-app/macos/test_app.rb'
workspace 'AsyncStorageExample.xcworkspace'
-use_test_app! do |target|
+options = {
+ :fabric_enabled => true,
+ :hermes_enabled => false,
+ :turbomodule_enabled => true,
+}
+
+use_test_app! options do |target|
target.app do
pod 'RNCAsyncStorage', :path => '../..'
pod 'AsyncStorageExample', :path => '..'
Output:
% pod install
...
Auto-linking React Native module for target `ReactTestApp`: ReactTestApp-DevSupport
Analyzing dependencies
"%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%"
"1"
"%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%"
Downloading dependencies
Generating Pods project
Setting REACT_NATIVE build settings
Setting CLANG_CXX_LANGUAGE_STANDARD to c++17 on /Users/tido/Source/async-storage/node_modules/.generated/macos/ReactTestApp.xcodeproj
Pod install took 11 [s] to run
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hmm, when I put the log inside of the Pod::Spec
block, it returns 0
for macOS
pod install --verbose
...
-> Fetching podspec for `RNCAsyncStorage` from `../..`
"%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%"
"0"
"%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%"
diff --git a/RNCAsyncStorage.podspec b/RNCAsyncStorage.podspec
index 25c9420..502ae48 100644
--- a/RNCAsyncStorage.podspec
+++ b/RNCAsyncStorage.podspec
@@ -16,6 +16,10 @@ Pod::Spec.new do |s|
s.source = { :git => "https://github.com/react-native-async-storage/async-storage.git", :tag => "v#{s.version}" }
s.source_files = "ios/**/*.{h,m,mm}"
+ p '%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%'
+ p ENV['RCT_NEW_ARCH_ENABLED']
+ p '%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%'
+
if fabric_enabled
folly_compiler_flags = '-DFOLLY_NO_CONFIG -DFOLLY_MOBILE=1 -DFOLLY_USE_LIBCPP=1 -Wno-comma -Wno-shorten-64-to-32'
diff --git a/example/macos/Podfile b/example/macos/Podfile
index d25aa3d..a79620d 100644
--- a/example/macos/Podfile
+++ b/example/macos/Podfile
@@ -3,9 +3,9 @@ require_relative '../../node_modules/react-native-test-app/macos/test_app.rb'
workspace 'AsyncStorageExample.xcworkspace'
options = {
- :fabric_enabled => false,
+ :fabric_enabled => true,
:hermes_enabled => false,
- :turbomodule_enabled => false,
+ :turbomodule_enabled => true,
}
use_test_app! do |target|
Same Podspec
when run from iOS project:
pod install --verbose
...
-> Fetching podspec for `RNCAsyncStorage` from `../..`
"%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%"
"1"
"%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%"
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I've just cleaned out my clone in case I had something stale. Still getting the same results.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not a blocker, I can just pass the flag when I install.
FYI: |
Co-authored-by: Tommy Nguyen <4123478+tido64@users.noreply.github.com>
Summary: ![image](https://user-images.githubusercontent.com/4123478/217618490-4f99e408-1a07-4acf-a05c-e8837562a931.png) `pod install --project-directory=ios` currently fails when new arch is enabled: react-native-async-storage/async-storage#910 - Patch for 0.71: #37993 - Patch for 0.72: #37994 ## Changelog: [IOS] [FIXED] - Fix `pod install --project-directory=...` when New Arch is enabled Pull Request resolved: #37992 Test Plan: ``` git clone https://github.com/react-native-async-storage/async-storage.git cd async-storage gh pr checkout 910 yarn RCT_NEW_ARCH_ENABLED=1 pod install --project-directory=example/ios ``` Reviewed By: cortinico Differential Revision: D46966225 Pulled By: cipolleschi fbshipit-source-id: 00b4650189175c09c9ec928f85d075890ba4c7c1
# Conflicts: # yarn.lock
I merged master on my branch and TM worked great on iOS/macOS. Any other blockers to merging? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The iOS bits look fine to me. It'd be great if you could get @krizzu to review the Android bits as well.
AsyncStorageModule.class, | ||
} | ||
) | ||
public class AsyncStoragePackage extends TurboReactPackage implements ViewManagerOnDemandReactPackage { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do we need to implement ViewManagerOnDemandReactPackage
? Seems unnecessary, as we only provide functional component
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You're right, I don't actually remember why I added that. Anyway, removed it in b84f11e.
android/src/paper/java/com/reactnativecommunity/asyncstorage/NativeAsyncStorageModuleSpec.java
Outdated
Show resolved
Hide resolved
android/src/kotlinPackage/java/com/reactnativecommunity/asyncstorage/AsyncStoragePackage.kt
Outdated
Show resolved
Hide resolved
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If you don't mind changing paper
to oldarch
that'd be great, but not a blocker.
Great work on this 👏
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you both for adding TM support ❤️
🎉 This PR is included in version 1.19.0 🎉 The release is available on: Your semantic-release bot 📦🚀 |
sourceDir: path.join('example', 'ios'), | ||
}, | ||
macos: { | ||
sourceDir: path.join('example', 'maacos'), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks like a typo. Does it work correctly on macos
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
My bad, I'll forward fix & test.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you!
PR adding New Architecture support to the library 🎉
We at Software Mansion have been working on improving support for the new architecture for quite a while now. If you need help with anything related to New Architecture, like:
or you just want to ask any questions, hit us up on projects@swmansion.com
Summary
This PR adds
FabricExample
app with the new arch enabled and converts the library to TurboModule.Notable changes:
RNC_AsyncSQLiteDBStorage
toRNCAsyncStorage
, matching iOS name@ReactModuleList
annotation. Previously reflection andBuildConfig
field were used to check if the Kotlin module should be used, but the annotation expects static declaration. I've achieved this using gradle source sets, to conditionally include one of the modules.Test Plan
Check the example app. On Android the new arch is enabled by default, while on iOS the
RCT_NEW_ARCH_ENABLED=1
flag is required when installing pods.