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

Android - pass initial props to ViewManager createView in non-Fabric #31053

Closed
wants to merge 1 commit into from

Conversation

gkode
Copy link

@gkode gkode commented Feb 25, 2021

Summary

#31051
When trying to create custom viewmanagers, we don't have props, I have a use case where I want to create views on the basis of provided react prop from react native.

Changelog

[CATEGORY] [TYPE] - ReactNative WebView

Test Plan

Tested Manually.

@facebook-github-bot
Copy link
Contributor

Hi @gkode!

Thank you for your pull request and welcome to our community.

Action Required

In order to merge any pull request (code, docs, etc.), we require contributors to sign our Contributor License Agreement, and we don't seem to have one on file for you.

Process

In order for us to review and merge your suggested changes, please sign at https://code.facebook.com/cla. If you are contributing on behalf of someone else (eg your employer), the individual CLA may not be sufficient and your employer may need to sign the corporate CLA.

Once the CLA is signed, our tooling will perform checks and validations. Afterwards, the pull request will be tagged with CLA signed. The tagging process may take up to 1 hour after signing. Please give it that time before contacting us about it.

If you have received this in error or have any questions, please contact us at cla@fb.com. Thanks!

Copy link

@analysis-bot analysis-bot left a comment

Choose a reason for hiding this comment

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

Code analysis results:

@pull-bot
Copy link

Messages
📖

📋 Verify Changelog Format - A changelog entry has the following format: [CATEGORY] [TYPE] - Message.

CATEGORY may be:
  • General
  • iOS
  • Android
  • JavaScript
  • Internal (for changes that do not need to be called out in the release notes)

TYPE may be:

  • Added, for new features.
  • Changed, for changes in existing functionality.
  • Deprecated, for soon-to-be removed features.
  • Removed, for now removed features.
  • Fixed, for any bug fixes.
  • Security, in case of vulnerabilities.

MESSAGE may answer "what and why" on a feature level. Use this to briefly tell React Native users about notable changes.

Generated by 🚫 dangerJS against 127c0e0

@analysis-bot
Copy link

Platform Engine Arch Size (bytes) Diff
ios - universal n/a --

Base commit: eeb36f4

@analysis-bot
Copy link

Platform Engine Arch Size (bytes) Diff
android hermes arm64-v8a 8,898,706 -3
android hermes armeabi-v7a 8,396,142 +6
android hermes x86 9,387,581 +2
android hermes x86_64 9,330,414 +12
android jsc arm64-v8a 10,632,780 +2
android jsc armeabi-v7a 10,113,306 +15
android jsc x86 10,683,143 +5
android jsc x86_64 11,266,225 +0

Base commit: eeb36f4

@facebook-github-bot facebook-github-bot added the CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed. label Feb 25, 2021
@JoshuaGross
Copy link
Contributor

@gkode Can you specify defaults in your custom view manager that will be used if null props are passed in? That seems like an easier change and wouldn't require upstreaming anything.

For this sort of change we would need a more comprehensive test plan than "tested manually" - how does this impact components in the ecosystem in general? Could it break anything?

A few lines below your change, updateProperties will be called. Why isn't that good enough?

@JoshuaGross JoshuaGross changed the title View managers custom fix Android - pass initial props to ViewManager createView in non-Fabric Feb 27, 2021
@JoshuaGross
Copy link
Contributor

In the future I would also recommend giving PRs a more descriptive title to help maintainers. I updated this one for you :)

Other thoughts:

  1. We tend to be hesitant about making changes like this without a lot of testing and a comprehensive test plan. This behavior hasn't changed in ~6 years, and it's a fairly invasive change. What side-effects could it cause?
  2. Is there another way to achieve this in general?
  3. On the other hand, Fabric does pass in initialProps on createView, and we did this intentionally so that certain decisions can be made when views are created for some custom ViewManagers, so maybe consistency is good between non-Fabric and Fabric: https://github.com/facebook/react-native/blob/master/ReactAndroid/src/main/java/com/facebook/react/fabric/mounting/SurfaceMountingManager.java#L500

I think I'd be okay making this change in the spirit of consistency between Fabric and non-Fabric, but I would want to see a more reproducible and fleshed-out test plan first.

@gkode
Copy link
Author

gkode commented Feb 28, 2021

@gkode Can you specify defaults in your custom view manager that will be used if null props are passed in? That seems like an easier change and wouldn't require upstreaming anything.

For this sort of change we would need a more comprehensive test plan than "tested manually" - how does this impact components in the ecosystem in general? Could it break anything?

A few lines below your change, updateProperties will be called. Why isn't that good enough?

While createViewInstance, I want to provide already existing view in memory on the basis of provided props to Native hierarchy. But in Update properties, view is already created and added in native view hierarchy. So, I will have to replace my existing view (in memory) in update properties method with the one created in CreateViewInstance which makes my code a bit messy.

Can you please help with making test plan for it ? What all test we want to pass on it to make sure it doesn't break anything. I tested this change on android only.

@JoshuaGross
Copy link
Contributor

I realized that some of our FB-internal view managers use the presence of props in the constructor to differentiate between Fabric and non-Fabric rendering modes. I will need to think about this a bit more.

@gkode
Copy link
Author

gkode commented Mar 1, 2021

I realized that some of our FB-internal view managers use the presence of props in the constructor to differentiate between Fabric and non-Fabric rendering modes. I will need to think about this a bit more.

is it really right parameter to differentiate between fabric and non-fabric?

Copy link
Contributor

@facebook-github-bot facebook-github-bot left a comment

Choose a reason for hiding this comment

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

@JoshuaGross has imported this pull request. If you are a Facebook employee, you can view this diff on Phabricator.

@gkode
Copy link
Author

gkode commented Mar 2, 2021

I realized that some of our FB-internal view managers use the presence of props in the constructor to differentiate between Fabric and non-Fabric rendering modes. I will need to think about this a bit more.

is it really right parameter to differentiate between fabric and non-fabric?

@JoshuaGross What's the plan to take this change forward

@gkode
Copy link
Author

gkode commented Mar 4, 2021

@JoshuaGross Any update on it.

@facebook-github-bot
Copy link
Contributor

@JoshuaGross merged this pull request in ea34953.

@facebook-github-bot facebook-github-bot added the Merged This PR has been merged. label Mar 5, 2021
@JoshuaGross
Copy link
Contributor

Merged @gkode, just took a while to audit everything relying on this internally

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. Merged This PR has been merged.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

5 participants