Skip to content
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

Merged

Conversation

WoLewicki
Copy link
Contributor

@WoLewicki WoLewicki commented Nov 17, 2022

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 for setNativeProps 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.

@WoLewicki WoLewicki changed the title feat: add FabricExample app feat: add Fabric support Nov 17, 2022
RNCPicker.podspec Outdated Show resolved Hide resolved
RNCPicker.podspec Outdated Show resolved Hide resolved
ios/RNCPicker.h Outdated Show resolved Hide resolved
ios/RNCPicker.mm Outdated Show resolved Hide resolved
ios/RNCPickerComponentView.h Outdated Show resolved Hide resolved
@WoLewicki WoLewicki marked this pull request as ready for review November 21, 2022 10:01
)

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)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
# file(GLOB LIB_CUSTOM_SRCS CONFIGURE_DEPENDS *.cpp ${LIB_COMMON_DIR}/react/renderer/components/${LIB_LITERAL}/*.cpp)

${LIB_TARGET_NAME}
PUBLIC
.
# ${LIB_COMMON_DIR}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
# ${LIB_COMMON_DIR}

Comment on lines +189 to +199
public void focus(ReactPicker root) {
root.performClick();
}

public void blur(ReactPicker root) {
root.clearFocus();
}

public void setNativeSelected(ReactPicker picker, int selected) {
picker.setStagedSelection(selected);
}
Copy link
Contributor

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 =
Copy link
Contributor Author

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?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@@ -0,0 +1,73 @@
cmake_minimum_required(VERSION 3.13)
Copy link
Contributor Author

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?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes

Comment on lines 18 to 26
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
// }
Copy link
Contributor Author

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?

Copy link
Contributor

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,
]);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fixing lint issue

Suggested change
]);
props.mode
]);

@@ -10,27 +10,63 @@

'use strict';

import {requireNativeComponent} from 'react-native';
import codegenNativeComponent from 'react-native/Libraries/Utilities/codegenNativeComponent';
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Adding missing flow types

Suggested change
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';

@kevin-williams
Copy link

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!

@Korin92
Copy link

Korin92 commented Feb 27, 2023

Doesn't support Fabric yet?

@gtomitsuka
Copy link

gtomitsuka commented Mar 16, 2023

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

@efstathiosntonas
Copy link

Hey folks, are there any updates on this? Thanks

@WoLewicki
Copy link
Contributor Author

I think it's up to @Naturalclar to decide what to do with it.

@dmk3141618
Copy link

Any updates? Nowadays most of RN codes are based on the Fabric new architecture.
Can I only use this on the old 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
ios : RCT_NEW_ARCH_ENABLED=1 npx pod-install ios

@Louis-C7
Copy link

Any update?

@j-piasecki
Copy link
Contributor

@Naturalclar Are there any plans to merge this PR?

@WoLewicki
Copy link
Contributor Author

It should be ready @Naturalclar 🚀 Would be really nice to merge it and release so people can check if everything works fine.

@Naturalclar Naturalclar merged commit 498b4e3 into react-native-picker:master Nov 28, 2023
8 of 12 checks passed
github-actions bot pushed a commit that referenced this pull request Nov 28, 2023
# [2.6.0](v2.5.1...v2.6.0) (2023-11-28)

### Features

* add Fabric support ([#456](#456)) ([498b4e3](498b4e3))
@Naturalclar
Copy link
Contributor

🎉 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),

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).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.