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

Add function to customise RootView in Bridgeless #42088

Closed
wants to merge 1 commit into from

Conversation

cipolleschi
Copy link
Contributor

@cipolleschi cipolleschi commented Dec 28, 2023

Summary:
This change adds an extra function to customise the RootView in both Bridge and Bridgeless mode.
To nudge users in a migration, we also add a warning message for next version that should push our users to migrate away from the old implementation to the new one.
The Warning is shown ONLY when the user do customise the rootView. For users which were not customising the Root View, the warning will not appear.

The documentation of the new method plus the warning should guide the users toward the right migration path.

Changelog

[iOS][Added] - Added the customiseRootView method which is called in both bridge and bridgeless. Added also a warning for 0.74 with instructions on how to migrate.

Differential Revision: D52442598

TestPlan

Tested locally on RNTester:

Bridge/Bridgeless Light Theme Dark Theme
Bridge Mode Screenshot 2023-12-28 at 10 32 54 Screenshot 2023-12-28 at 10 33 18
Bridgeless Screenshot 2023-12-28 at 10 51 00 Screenshot 2023-12-28 at 10 50 47

@facebook-github-bot facebook-github-bot added CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed. p: Facebook Partner: Facebook Partner fb-exported labels Dec 28, 2023
@facebook-github-bot
Copy link
Contributor

This pull request was exported from Phabricator. Differential Revision: D52442598

cipolleschi added a commit to cipolleschi/react-native that referenced this pull request Dec 28, 2023
Summary:

This change adds an extra function to customise the RootView in both Bridge and Bridgeless mode.
To nudge users in a migration, we also add a warning message for next version that should push our users to migrate away from the old implementation to the new one.
*The Warning is shown ONLY when the user do customise the rootView*. For users which were not customising the Root View, the warning will not appear.

The documentation of the new method plus the warning should guide the users toward the right migration path.

## Changelog
[iOS][Added] - Added the customiseRootView method which is called in both bridge and bridgeless. Added also a warning for 0.74 with instructions on how to migrate.

Differential Revision: D52442598
@facebook-github-bot
Copy link
Contributor

This pull request was exported from Phabricator. Differential Revision: D52442598

cipolleschi added a commit to cipolleschi/react-native that referenced this pull request Dec 28, 2023
Summary:

This change adds an extra function to customise the RootView in both Bridge and Bridgeless mode.
To nudge users in a migration, we also add a warning message for next version that should push our users to migrate away from the old implementation to the new one.
*The Warning is shown ONLY when the user do customise the rootView*. For users which were not customising the Root View, the warning will not appear.

The documentation of the new method plus the warning should guide the users toward the right migration path.

## Changelog
[iOS][Added] - Added the customiseRootView method which is called in both bridge and bridgeless. Added also a warning for 0.74 with instructions on how to migrate.

Differential Revision: D52442598
@facebook-github-bot
Copy link
Contributor

This pull request was exported from Phabricator. Differential Revision: D52442598

@analysis-bot
Copy link

analysis-bot commented Dec 28, 2023

Platform Engine Arch Size (bytes) Diff
android hermes arm64-v8a 16,577,954 +0
android hermes armeabi-v7a n/a --
android hermes x86 n/a --
android hermes x86_64 n/a --
android jsc arm64-v8a 19,955,039 -3
android jsc armeabi-v7a n/a --
android jsc x86 n/a --
android jsc x86_64 n/a --

Base commit: af8c56a
Branch: main

Copy link
Contributor

@okwasniewski okwasniewski left a comment

Choose a reason for hiding this comment

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

Looks good, left few minor comments

@@ -117,6 +118,7 @@ - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(
}
rootView = [self createRootViewWithBridge:self.bridge moduleName:self.moduleName initProps:initProps];
}
[self customizeRootView:(RCTRootView *)rootView];
Copy link
Contributor

Choose a reason for hiding this comment

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

nit: Can't we set the rootView variable type to RCTRootView? And cast it to UIView if needed

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Nope, this won't change a lot.

The variable is defined as UIView *rootView because it is the common ancestor.

The surfaceHostingProxyRootView; is actually a @interface RCTSurfaceHostingProxyRootView : RCTSurfaceHostingView where RCTSurfaceHostingView is a @interface RCTSurfaceHostingView : UIView <RCTSurfaceDelegate>.
So, technically, it is not even a RCTRootView, but a proxied one, and it will still require casting.

The createRootViewWithBridge:moduleName:initProps: technically returns a UIView *, so changing if we made the rootView a RCTRootView * we would have either to change the createRootViewWithBridge (breaking change, we don't want to do it) or add the casting to RCTRootView.

So, in the end, we will always have to cast. :(

Copy link
Contributor

Choose a reason for hiding this comment

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

Okay, thanks for the explanation

cipolleschi added a commit to cipolleschi/react-native that referenced this pull request Dec 28, 2023
Summary:

This change adds an extra function to customise the RootView in both Bridge and Bridgeless mode.
To nudge users in a migration, we also add a warning message for next version that should push our users to migrate away from the old implementation to the new one.
*The Warning is shown ONLY when the user do customise the rootView*. For users which were not customising the Root View, the warning will not appear.

The documentation of the new method plus the warning should guide the users toward the right migration path.

## Changelog
[iOS][Added] - Added the customiseRootView method which is called in both bridge and bridgeless. Added also a warning for 0.74 with instructions on how to migrate.

Differential Revision: D52442598
cipolleschi added a commit to cipolleschi/react-native that referenced this pull request Dec 28, 2023
Summary:

This change adds an extra function to customise the RootView in both Bridge and Bridgeless mode.
To nudge users in a migration, we also add a warning message for next version that should push our users to migrate away from the old implementation to the new one.
*The Warning is shown ONLY when the user do customise the rootView*. For users which were not customising the Root View, the warning will not appear.

The documentation of the new method plus the warning should guide the users toward the right migration path.

## Changelog
[iOS][Added] - Added the customiseRootView method which is called in both bridge and bridgeless. Added also a warning for 0.74 with instructions on how to migrate.

Differential Revision: D52442598
@facebook-github-bot
Copy link
Contributor

This pull request was exported from Phabricator. Differential Revision: D52442598

1 similar comment
@facebook-github-bot
Copy link
Contributor

This pull request was exported from Phabricator. Differential Revision: D52442598

@@ -156,6 +164,20 @@ - (UIView *)createRootViewWithBridge:(RCTBridge *)bridge
return rootView;
}

- (void)_logWarnIfOverridden
Copy link
Contributor Author

Choose a reason for hiding this comment

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

We will remove the log after 0.74

@@ -117,6 +118,7 @@ - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(
}
rootView = [self createRootViewWithBridge:self.bridge moduleName:self.moduleName initProps:initProps];
}
[self customizeRootView:(RCTRootView *)rootView];
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Nope, this won't change a lot.

The variable is defined as UIView *rootView because it is the common ancestor.

The surfaceHostingProxyRootView; is actually a @interface RCTSurfaceHostingProxyRootView : RCTSurfaceHostingView where RCTSurfaceHostingView is a @interface RCTSurfaceHostingView : UIView <RCTSurfaceDelegate>.
So, technically, it is not even a RCTRootView, but a proxied one, and it will still require casting.

The createRootViewWithBridge:moduleName:initProps: technically returns a UIView *, so changing if we made the rootView a RCTRootView * we would have either to change the createRootViewWithBridge (breaking change, we don't want to do it) or add the casting to RCTRootView.

So, in the end, we will always have to cast. :(

@facebook-github-bot
Copy link
Contributor

This pull request was exported from Phabricator. Differential Revision: D52442598

cipolleschi added a commit to cipolleschi/react-native that referenced this pull request Dec 28, 2023
Summary:

This change adds an extra function to customise the RootView in both Bridge and Bridgeless mode.
To nudge users in a migration, we also add a warning message for next version that should push our users to migrate away from the old implementation to the new one.
*The Warning is shown ONLY when the user do customise the rootView*. For users which were not customising the Root View, the warning will not appear.

The documentation of the new method plus the warning should guide the users toward the right migration path.

## Changelog
[iOS][Added] - Added the customiseRootView method which is called in both bridge and bridgeless. Added also a warning for 0.74 with instructions on how to migrate.

Differential Revision: D52442598
cipolleschi added a commit to cipolleschi/react-native that referenced this pull request Dec 28, 2023
Summary:

This change adds an extra function to customise the RootView in both Bridge and Bridgeless mode.
To nudge users in a migration, we also add a warning message for next version that should push our users to migrate away from the old implementation to the new one.
*The Warning is shown ONLY when the user do customise the rootView*. For users which were not customising the Root View, the warning will not appear.

The documentation of the new method plus the warning should guide the users toward the right migration path.

## Changelog
[iOS][Added] - Added the customiseRootView method which is called in both bridge and bridgeless. Added also a warning for 0.74 with instructions on how to migrate.

Differential Revision: D52442598
cipolleschi added a commit to cipolleschi/react-native that referenced this pull request Dec 28, 2023
Summary:

This change adds an extra function to customise the RootView in both Bridge and Bridgeless mode.
To nudge users in a migration, we also add a warning message for next version that should push our users to migrate away from the old implementation to the new one.
*The Warning is shown ONLY when the user do customise the rootView*. For users which were not customising the Root View, the warning will not appear.

The documentation of the new method plus the warning should guide the users toward the right migration path.

## Changelog
[iOS][Added] - Added the customiseRootView method which is called in both bridge and bridgeless. Added also a warning for 0.74 with instructions on how to migrate.

Differential Revision: D52442598
Copy link
Contributor

@Saadnajmi Saadnajmi left a comment

Choose a reason for hiding this comment

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

If I understand correctly, the issue with createRootViewWithBridge was that:

  • It only worked on the old architecture
  • It doesn't work with bridgeless

and this new method is just a new uniform way to do that? How does it differ from RCTAppSetupDefaultRootView?

@cipolleschi
Copy link
Contributor Author

@Saadnajmi

If I understand correctly, the issue with createRootViewWithBridge was that:

  • It only worked on the old architecture
  • It doesn't work with bridgeless
    and this new method is just a new uniform way to do that?

Correct. Before this change the only way to customise the RCTRootView in bridgeless/New Architecture in the future is to override (void)setRootView:(UIView *)rootView toRootViewController:(UIViewController *)rootViewController; and customise the rootView there.
But it is an abuse, as the purpose of that method is different. That method needs to be override when the rootViewController is a special one, with custom APIs to set the rootView, like the UISplitViewController.

How does it differ from RCTAppSetupDefaultRootView?

There are several differences:

  1. Purpose: RCTAppSetupDefaultRootView is used to initialize the rootView. It will be an abuse to use it to customise the rootView.
  2. Stability: RCTAppSetupDefaultRootView takes the RCTBridge as one of its parameters. This means that we are going to break it sooner or later. And we will have to force a migration to our users.
  3. Visibility: RCTAppSetupDefaultRootView is part of the RCTAppSetupUtils.h header, which should be a private header. At some point, we will hide it from the final users, to allow us to change the internals of React Native without breaking everyone. Furthermore, it is a plain C function, it is not usable from the AppDelegate and there is no easy way to override it.

With the purpose of being future proof and to design clean, simple API with a well-defined purpose, it is better to have a method that does only one thing, and with a clear name which is unlikely that we will break.

cipolleschi added a commit to cipolleschi/react-native that referenced this pull request Dec 28, 2023
Summary:

This change adds an extra function to customise the RootView in both Bridge and Bridgeless mode.
To nudge users in a migration, we also add a warning message for next version that should push our users to migrate away from the old implementation to the new one.
*The Warning is shown ONLY when the user do customise the rootView*. For users which were not customising the Root View, the warning will not appear.

The documentation of the new method plus the warning should guide the users toward the right migration path.

## Changelog
[iOS][Added] - Added the customiseRootView method which is called in both bridge and bridgeless. Added also a warning for 0.74 with instructions on how to migrate.

Differential Revision: D52442598
cipolleschi added a commit to cipolleschi/react-native that referenced this pull request Dec 28, 2023
Summary:

This change adds an extra function to customise the RootView in both Bridge and Bridgeless mode.
To nudge users in a migration, we also add a warning message for next version that should push our users to migrate away from the old implementation to the new one.
*The Warning is shown ONLY when the user do customise the rootView*. For users which were not customising the Root View, the warning will not appear.

The documentation of the new method plus the warning should guide the users toward the right migration path.

## Changelog
[iOS][Added] - Added the customiseRootView method which is called in both bridge and bridgeless. Added also a warning for 0.74 with instructions on how to migrate.

Differential Revision: D52442598
@facebook-github-bot
Copy link
Contributor

This pull request was exported from Phabricator. Differential Revision: D52442598

@facebook-github-bot
Copy link
Contributor

This pull request was exported from Phabricator. Differential Revision: D52442598

cipolleschi added a commit to cipolleschi/react-native that referenced this pull request Jan 2, 2024
Summary:

This change adds an extra function to customise the RootView in both Bridge and Bridgeless mode.
To nudge users in a migration, we also add a warning message for next version that should push our users to migrate away from the old implementation to the new one.
*The Warning is shown ONLY when the user do customise the rootView*. For users which were not customising the Root View, the warning will not appear.

The documentation of the new method plus the warning should guide the users toward the right migration path.

## Changelog
[iOS][Added] - Added the customiseRootView method which is called in both bridge and bridgeless. Added also a warning for 0.74 with instructions on how to migrate.

Reviewed By: cortinico

Differential Revision: D52442598
cipolleschi added a commit to cipolleschi/react-native that referenced this pull request Jan 2, 2024
Summary:

This change adds an extra function to customise the RootView in both Bridge and Bridgeless mode.
To nudge users in a migration, we also add a warning message for next version that should push our users to migrate away from the old implementation to the new one.
*The Warning is shown ONLY when the user do customise the rootView*. For users which were not customising the Root View, the warning will not appear.

The documentation of the new method plus the warning should guide the users toward the right migration path.

## Changelog
[iOS][Added] - Added the customiseRootView method which is called in both bridge and bridgeless. Added also a warning for 0.74 with instructions on how to migrate.

Reviewed By: cortinico

Differential Revision: D52442598
cipolleschi added a commit to cipolleschi/react-native that referenced this pull request Jan 2, 2024
Summary:

This change adds an extra function to customise the RootView in both Bridge and Bridgeless mode.
To nudge users in a migration, we also add a warning message for next version that should push our users to migrate away from the old implementation to the new one.
*The Warning is shown ONLY when the user do customise the rootView*. For users which were not customising the Root View, the warning will not appear.

The documentation of the new method plus the warning should guide the users toward the right migration path.

## Changelog
[iOS][Added] - Added the customiseRootView method which is called in both bridge and bridgeless. Added also a warning for 0.74 with instructions on how to migrate.

Reviewed By: cortinico

Differential Revision: D52442598
@facebook-github-bot
Copy link
Contributor

This pull request was exported from Phabricator. Differential Revision: D52442598

cipolleschi added a commit to cipolleschi/react-native that referenced this pull request Jan 2, 2024
Summary:

This change adds an extra function to customise the RootView in both Bridge and Bridgeless mode.
To nudge users in a migration, we also add a warning message for next version that should push our users to migrate away from the old implementation to the new one.
*The Warning is shown ONLY when the user do customise the rootView*. For users which were not customising the Root View, the warning will not appear.

The documentation of the new method plus the warning should guide the users toward the right migration path.

## Changelog
[iOS][Added] - Added the customiseRootView method which is called in both bridge and bridgeless. Added also a warning for 0.74 with instructions on how to migrate.

Reviewed By: cortinico

Differential Revision: D52442598
@facebook-github-bot
Copy link
Contributor

This pull request was exported from Phabricator. Differential Revision: D52442598

cipolleschi added a commit to cipolleschi/react-native that referenced this pull request Jan 2, 2024
Summary:

This change adds an extra function to customise the RootView in both Bridge and Bridgeless mode.
To nudge users in a migration, we also add a warning message for next version that should push our users to migrate away from the old implementation to the new one.
*The Warning is shown ONLY when the user do customise the rootView*. For users which were not customising the Root View, the warning will not appear.

The documentation of the new method plus the warning should guide the users toward the right migration path.

## Changelog
[iOS][Added] - Added the customiseRootView method which is called in both bridge and bridgeless. Added also a warning for 0.74 with instructions on how to migrate.

Reviewed By: cortinico

Differential Revision: D52442598
cipolleschi added a commit to cipolleschi/react-native that referenced this pull request Jan 2, 2024
Summary:

This change adds an extra function to customise the RootView in both Bridge and Bridgeless mode.
To nudge users in a migration, we also add a warning message for next version that should push our users to migrate away from the old implementation to the new one.
*The Warning is shown ONLY when the user do customise the rootView*. For users which were not customising the Root View, the warning will not appear.

The documentation of the new method plus the warning should guide the users toward the right migration path.

## Changelog
[iOS][Added] - Added the customiseRootView method which is called in both bridge and bridgeless. Added also a warning for 0.74 with instructions on how to migrate.

Reviewed By: cortinico

Differential Revision: D52442598
@facebook-github-bot
Copy link
Contributor

This pull request was exported from Phabricator. Differential Revision: D52442598

Summary:

This change adds an extra function to customise the RootView in both Bridge and Bridgeless mode.
To nudge users in a migration, we also add a warning message for next version that should push our users to migrate away from the old implementation to the new one.
*The Warning is shown ONLY when the user do customise the rootView*. For users which were not customising the Root View, the warning will not appear.

The documentation of the new method plus the warning should guide the users toward the right migration path.

## Changelog
[iOS][Added] - Added the customiseRootView method which is called in both bridge and bridgeless. Added also a warning for 0.74 with instructions on how to migrate.

Reviewed By: cortinico

Differential Revision: D52442598
cipolleschi added a commit to cipolleschi/react-native that referenced this pull request Jan 2, 2024
Summary:

This change adds an extra function to customise the RootView in both Bridge and Bridgeless mode.
To nudge users in a migration, we also add a warning message for next version that should push our users to migrate away from the old implementation to the new one.
*The Warning is shown ONLY when the user do customise the rootView*. For users which were not customising the Root View, the warning will not appear.

The documentation of the new method plus the warning should guide the users toward the right migration path.

## Changelog
[iOS][Added] - Added the customiseRootView method which is called in both bridge and bridgeless. Added also a warning for 0.74 with instructions on how to migrate.

Reviewed By: cortinico

Differential Revision: D52442598
@facebook-github-bot
Copy link
Contributor

This pull request was exported from Phabricator. Differential Revision: D52442598

@facebook-github-bot facebook-github-bot added the Merged This PR has been merged. label Jan 2, 2024
@facebook-github-bot
Copy link
Contributor

This pull request has been merged in db9c9ea.

Othinn pushed a commit to Othinn/react-native that referenced this pull request Jan 9, 2024
Summary:
Pull Request resolved: facebook#42088

This change adds an extra function to customise the RootView in both Bridge and Bridgeless mode.
To nudge users in a migration, we also add a warning message for next version that should push our users to migrate away from the old implementation to the new one.
*The Warning is shown ONLY when the user do customise the rootView*. For users which were not customising the Root View, the warning will not appear.

The documentation of the new method plus the warning should guide the users toward the right migration path.

## Changelog
[iOS][Added] - Added the customiseRootView method which is called in both bridge and bridgeless. Added also a warning for 0.74 with instructions on how to migrate.

Reviewed By: cortinico

Differential Revision: D52442598

fbshipit-source-id: 8b99b67f4741ee61989a8659a3d74c1eba27bc5b
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed. fb-exported Merged This PR has been merged. p: Facebook Partner: Facebook Partner
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants