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

Adding ReactNative.setNativeProps that takes a ref #14907

Merged
merged 5 commits into from
Feb 21, 2019

Conversation

elicwhite
Copy link
Member

@elicwhite elicwhite commented Feb 20, 2019

As part of react-native-community/discussions-and-proposals#72 this adds a new top level API on ReactNative that we can use to setNativeProps.

This can only be called with a ref to a native component and will warn/no-op if called with an invalid component ref.

Other than jest tests, I also verified this worked by running

yarn build native --type=RN_FB_DEV

and copied the output files into FB's codebase. I added a console.warn to ensure it was using the renderer I copied in, modified react-native-implementation.js to expose this and then verified setNativeProps worked correctly from the top level for the paper renderer via a playground app.

// Module provided by RN:
import UIManager from 'UIManager';

export function setNativeProps(handle: any, nativeProps: Object) {
Copy link
Member Author

Choose a reason for hiding this comment

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

Is there a better flow type I should be using for handle?

Copy link
Collaborator

Choose a reason for hiding this comment

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

We used to pretend that native host instances were ReactNativeComponent. That’s not technically true because they’re not instanceof.

With forwardRef, we get the inner type. I would’ve expected that you have to supply the ref type to Flow. What does Flow think the type of a ref is?

Ideally it would be an opaque type which will help catch anyone trying to call something else on it.

Copy link
Member Author

Choose a reason for hiding this comment

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

Alright, seems like a problem for another PR at another time. :)

@sizebot
Copy link

sizebot commented Feb 21, 2019

Details of bundled changes.

Comparing: 4f4aa69...ada38e2

react-native-renderer

File Filesize Diff Gzip Diff Prev Size Current Size Prev Gzip Current Gzip ENV
ReactNativeRenderer-dev.js +0.2% +0.1% 609.08 KB 610.01 KB 130.83 KB 130.95 KB RN_FB_DEV
ReactNativeRenderer-prod.js 🔺+0.2% 🔺+0.2% 246.53 KB 246.95 KB 43.03 KB 43.1 KB RN_FB_PROD
ReactNativeRenderer-profiling.js +0.2% +0.1% 252.88 KB 253.3 KB 44.58 KB 44.64 KB RN_FB_PROFILING
ReactNativeRenderer-dev.js +0.2% +0.1% 608.99 KB 609.92 KB 130.79 KB 130.91 KB RN_OSS_DEV
ReactNativeRenderer-prod.js 🔺+0.2% 🔺+0.2% 246.54 KB 246.96 KB 43.03 KB 43.1 KB RN_OSS_PROD
ReactNativeRenderer-profiling.js +0.2% +0.1% 252.9 KB 253.32 KB 44.58 KB 44.64 KB RN_OSS_PROFILING
ReactFabric-dev.js +0.2% +0.1% 599.93 KB 600.86 KB 128.55 KB 128.67 KB RN_FB_DEV
ReactFabric-prod.js 🔺+0.2% 🔺+0.1% 238.88 KB 239.3 KB 41.56 KB 41.62 KB RN_FB_PROD
ReactFabric-profiling.js +0.2% +0.1% 245.1 KB 245.52 KB 43.09 KB 43.15 KB RN_FB_PROFILING
ReactFabric-dev.js +0.2% +0.1% 599.84 KB 600.77 KB 128.5 KB 128.63 KB RN_OSS_DEV
ReactFabric-prod.js 🔺+0.2% 🔺+0.1% 238.88 KB 239.3 KB 41.55 KB 41.61 KB RN_OSS_PROD
ReactFabric-profiling.js +0.2% +0.1% 245.11 KB 245.53 KB 43.09 KB 43.15 KB RN_OSS_PROFILING

Generated by 🚫 dangerJS

@sebmarkbage
Copy link
Collaborator

Prettier.

@@ -0,0 +1,43 @@
/**
Copy link
Collaborator

Choose a reason for hiding this comment

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

Since you’re going to add more of these, can we name it something more general so we don’t need a file per method?

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.

4 participants