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

[React Native] measure calls will now call FabricUIManager #15324

Merged
merged 11 commits into from
Apr 9, 2019

Conversation

elicwhite
Copy link
Member

@elicwhite elicwhite commented Apr 4, 2019

This PR is based on #15323, split for review.

The Fabric renderer was previously calling the paper UIManager's measure calls and passing the react tag. This PR changes the renderer to now call FabricUIManager passing the node instead.

In #15126 Seb and I were thinking that we shouldn't support components created with NativeMethodsMixin and ReactNative.NativeComponent to be able to take a ref in measureLayout.

While that is still ideal, we can't reasonably make that change because the signatures of FabricHostComponent, FiberHostComponent, NativeMethodsMixin, and ReactNativeNativeComponent all have identical type signatures as enforced in each file with this:

(ReactFabricHostComponent.prototype: NativeMethodsMixinType);

Ideally we'd type host components differently than the other methods so that we can use flow to enforce that an argument is a ref to a host component and not one of the others. Unfortunately, we are pretty far from being able to do that today because all the core components in React Native are typed like this:

(requireNativeComponent('AndroidSwitch'): Class<ReactNative.NativeComponent<Props>>)

We will need to fix this and update all the ref types throughout the codebase to be more strict in order to properly type the argument to measureLayout as a ref to a host component. This is a much bigger project and out of scope of this PR. We should make that change at some point.

In order to keep all the types consistent in this PR measureLayout is taking a reactTag or object and the checks are done at runtime.


The additions to the FabricUIManager types are consistent with D14732142.

The Fabric renderer was previously calling the paper UIManager's measure calls and passing the react tag. This PR changes the renderer to now call FabricUIManager passing the node instead.

One of the parts of this that feels more controversial is making NativeMethodsMixin and ReactNative.NativeComponent warn when calling measureLayout in Fabric. As Seb and I decided in facebook#15126, it doesn't make sense for a component created with one of these methods to require a native ref but not work the other way around. For example: a.measureLayout(b) might work but b.measureLayout(a) wouldn't. We figure we should keep these consistent and continue migrating things off of NativeMethodsMixin and NativeComponent.

If this becomes problematic for the Fabric rollout then we should revisit this.
@sizebot
Copy link

sizebot commented Apr 4, 2019

Details of bundled changes.

Comparing: c7a9599...a012aa1

react-native-renderer

File Filesize Diff Gzip Diff Prev Size Current Size Prev Gzip Current Gzip ENV
ReactNativeRenderer-dev.js +0.9% +0.2% 703.67 KB 710.03 KB 150.6 KB 150.93 KB RN_FB_DEV
ReactNativeRenderer-prod.js 🔺+1.1% 🔺+0.4% 246.96 KB 249.66 KB 43.22 KB 43.38 KB RN_FB_PROD
ReactNativeRenderer-profiling.js +1.1% +0.4% 252.97 KB 255.68 KB 44.54 KB 44.7 KB RN_FB_PROFILING
ReactNativeRenderer-dev.js +0.9% +0.2% 703.58 KB 709.94 KB 150.58 KB 150.9 KB RN_OSS_DEV
ReactNativeRenderer-prod.js 🔺+1.1% 🔺+0.4% 246.97 KB 249.68 KB 43.22 KB 43.38 KB RN_OSS_PROD
ReactNativeRenderer-profiling.js +1.1% +0.4% 252.99 KB 255.69 KB 44.54 KB 44.7 KB RN_OSS_PROFILING
ReactFabric-dev.js +0.9% +0.2% 692.52 KB 698.76 KB 147.98 KB 148.23 KB RN_FB_DEV
ReactFabric-prod.js 🔺+1.1% 🔺+0.3% 240.25 KB 242.89 KB 41.97 KB 42.07 KB RN_FB_PROD
ReactFabric-profiling.js +1.1% +0.2% 245.54 KB 248.25 KB 43.3 KB 43.41 KB RN_FB_PROFILING
ReactFabric-dev.js +0.9% +0.2% 692.43 KB 698.67 KB 147.93 KB 148.19 KB RN_OSS_DEV
ReactFabric-prod.js 🔺+1.1% 🔺+0.3% 240.26 KB 242.9 KB 41.96 KB 42.07 KB RN_OSS_PROD
ReactFabric-profiling.js +1.1% +0.2% 245.56 KB 248.26 KB 43.3 KB 43.4 KB RN_OSS_PROFILING

Generated by 🚫 dangerJS

@elicwhite
Copy link
Member Author

I need to track down these lint errors:

/home/circleci/project/build/react-native/oss/ReactFabric-dev.js
  21229:9  error  'FabricUIManager__default' is not defined  no-undef

I think I'm probably missing some define somewhere.

@bvaughn
Copy link
Contributor

bvaughn commented Apr 5, 2019

I think this is failing because the FabricUIManager module does not have a default export?

To fix this, replace:

import FabricUIManager from 'FabricUIManager';

with:

import * as FabricUIManager from 'FabricUIManager';

@@ -89,7 +89,7 @@ class ReactNativeComponent<Props> extends React.Component<Props> {
measure(callback: MeasureOnSuccessCallback): void {}
measureInWindow(callback: MeasureInWindowOnSuccessCallback): void {}
measureLayout(
relativeToNativeNode: number,
relativeToNativeNode: number | Object,
Copy link
Collaborator

Choose a reason for hiding this comment

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

Let's make this number | ReactNativeComponent and cast it on the inside. It's not correct but more specific.

@elicwhite elicwhite merged commit 1b2159a into facebook:master Apr 9, 2019
@elicwhite elicwhite deleted the fabric-measure-calls branch April 9, 2019 22:10
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants