-
Notifications
You must be signed in to change notification settings - Fork 300
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
feat: add Fabric support #456
feat: add Fabric support #456
Conversation
Co-authored-by: Tomek Zawadzki <tomekzawadzki98@gmail.com>
android/src/main/jni/CMakeLists.txt
Outdated
) | ||
|
||
file(GLOB LIB_CUSTOM_SRCS CONFIGURE_DEPENDS *.cpp) | ||
# file(GLOB LIB_CUSTOM_SRCS CONFIGURE_DEPENDS *.cpp ${LIB_COMMON_DIR}/react/renderer/components/${LIB_LITERAL}/*.cpp) |
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.
# file(GLOB LIB_CUSTOM_SRCS CONFIGURE_DEPENDS *.cpp ${LIB_COMMON_DIR}/react/renderer/components/${LIB_LITERAL}/*.cpp) |
android/src/main/jni/CMakeLists.txt
Outdated
${LIB_TARGET_NAME} | ||
PUBLIC | ||
. | ||
# ${LIB_COMMON_DIR} |
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.
# ${LIB_COMMON_DIR} |
public void focus(ReactPicker root) { | ||
root.performClick(); | ||
} | ||
|
||
public void blur(ReactPicker root) { | ||
root.clearFocus(); | ||
} | ||
|
||
public void setNativeSelected(ReactPicker picker, int selected) { | ||
picker.setStagedSelection(selected); | ||
} |
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.
We could use those methods in the receiveCommands
and setSelected
prop to avoid duplication.
@@ -149,9 +149,15 @@ protected void onAfterUpdateTransaction(ReactPicker view) { | |||
protected void addEventEmitters( | |||
final ThemedReactContext reactContext, | |||
final ReactPicker picker) { | |||
EventDispatcher eventDispatcher = |
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.
Why is it done like this now? Cause it is a null on Fabric
? If so, what about those listeners?
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.
It didn't work on Fabric the way it was before, so I checked how it's done in the core components: https://github.com/facebook/react-native/blob/84874704766c0bc2dde88720b04b3ba4a695cf30/ReactAndroid/src/main/java/com/facebook/react/views/drawer/ReactDrawerLayoutManager.java#L60-L66.
@@ -0,0 +1,73 @@ | |||
cmake_minimum_required(VERSION 3.13) |
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.
Is it taken from the react-native-screens
repo?
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.
Yes
react-native.config.js
Outdated
let supportsCodegenConfig = true; | ||
// try { | ||
// const rnCliAndroidVersion = require('@react-native-community/cli-platform-android/package.json') | ||
// .version; | ||
// const [major] = rnCliAndroidVersion.split('.'); | ||
// supportsCodegenConfig = major >= 9; | ||
// } catch (e) { | ||
// // ignore | ||
// } |
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.
Should it be left like that?
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.
It was this way because the commented part was picking the rncli version from the root package instead of the fabric example.
I made a workaround for it in 1f41b69, I added a flag that allows to enable the custom config and made a patch to the cli so that it runs with the added flag.
Co-authored-by: Jesse Katsumata <niconico.clarinet@gmail.com>
nativeSelectedIndex, | ||
props.children, | ||
FABRIC_ENABLED, | ||
]); |
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.
fixing lint issue
]); | |
props.mode | |
]); |
@@ -10,27 +10,63 @@ | |||
|
|||
'use strict'; | |||
|
|||
import {requireNativeComponent} from 'react-native'; | |||
import codegenNativeComponent from 'react-native/Libraries/Utilities/codegenNativeComponent'; |
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.
Adding missing flow types
import codegenNativeComponent from 'react-native/Libraries/Utilities/codegenNativeComponent'; | |
import * as React from 'react'; | |
import type {Int32} from 'react-native/Libraries/Types/CodegenTypes'; | |
import type {BubblingEventHandler} from 'react-native/Libraries/Types/CodegenTypes'; | |
import type {ColorValue} from 'react-native/Libraries/StyleSheet/StyleSheet'; | |
import type {ViewProps} from 'react-native/Libraries/Components/View/ViewPropTypes'; | |
import type {ComponentType} from 'react'; | |
import codegenNativeComponent from 'react-native/Libraries/Utilities/codegenNativeComponent'; |
Any update to this PR? I have a release I want to get to prod for our company because fabric makes the app so much faster. This is one of my last TODOs on the upgrade. If the PR is soon I'll wait. Thanks! |
Doesn't support Fabric yet? |
Hey, are there any remaining milestones on the JS or iOS side? Happy to support! We could push this to a feature branch for easier beta testing & further work by more contributors |
Hey folks, are there any updates on this? Thanks |
I think it's up to @Naturalclar to decide what to do with it. |
Any updates? Nowadays most of RN codes are based on the Fabric new architecture. It seems I can not use only this package on the old architecture because I can only select one architecture with compile level option. aos : gradle.properties > newArchEnabled=true |
Any update? |
@Naturalclar Are there any plans to merge this PR? |
It should be ready @Naturalclar 🚀 Would be really nice to merge it and release so people can check if everything works fine. |
498b4e3
into
react-native-picker:master
# [2.6.0](v2.5.1...v2.6.0) (2023-11-28) ### Features * add Fabric support ([#456](#456)) ([498b4e3](498b4e3))
🎉 This PR is included in version 2.6.0 🎉 The release is available on: Your semantic-release bot 📦🚀 |
value: child.props.value, | ||
label: child.props.label, | ||
return { | ||
value: String(child.props.value), |
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.
this change caused a regression in my app, as the expected type returned by the onValueChange
handler used to be an integer (if the item's value was initially an int).
PR adding Fabric support to the library. Android code regarding handling state on Fabric has been mainly taken from
react-native-screens
repo (Screen component).As for the JS code, I have changed the implementation to functional style components, based mainly on
Switch
: https://github.com/facebook/react-native/blob/5dd2f2e4b7669397f8bfa9b3845afee7e4e47626/Libraries/Components/Switch/Switch.js.It was done like this since
Fabric
introduces some changes in how the render/layout phases work, leading to jumping layout when native commands (substitute forsetNativeProps
on Fabric) were called in the event callback (see attached video).Now the native event changes the state of component, leading to a rerender and call of
useLayoutEffect
, where there is a chance of reverting the native change.Simulator.Screen.Recording.-.iPhone.14.Pro.-.2022-11-24.at.15.37.34.mp4
Coauthored by @j-piasecki.