-
Notifications
You must be signed in to change notification settings - Fork 47.6k
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
Changes from 2 commits
ef52e22
411ca62
676a5ba
6a46015
ada38e2
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
/** | ||
* Copyright (c) Facebook, Inc. and its affiliates. | ||
* | ||
* This source code is licensed under the MIT license found in the | ||
* LICENSE file in the root directory of this source tree. | ||
* | ||
* @flow | ||
*/ | ||
|
||
import {create} from './ReactNativeAttributePayload'; | ||
import {warnForStyleProps} from './NativeMethodsMixinUtils'; | ||
|
||
import warningWithoutStack from 'shared/warningWithoutStack'; | ||
|
||
// Module provided by RN: | ||
import UIManager from 'UIManager'; | ||
|
||
export function setNativeProps(handle: any, nativeProps: Object) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Is there a better flow type I should be using for There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 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. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Alright, seems like a problem for another PR at another time. :) |
||
if (handle._nativeTag == null) { | ||
warningWithoutStack( | ||
handle._nativeTag != null, | ||
"setNativeProps was called on a ref that isn't a " + | ||
'native component. Use React.forwardRef to get access to the underlying native component', | ||
); | ||
return; | ||
} | ||
|
||
if (__DEV__) { | ||
warnForStyleProps(nativeProps, handle.viewConfig.validAttributes); | ||
} | ||
|
||
const updatePayload = create(nativeProps, handle.viewConfig.validAttributes); | ||
// Avoid the overhead of bridge calls if there's no update. | ||
// This is an expensive no-op for Android, and causes an unnecessary | ||
// view invalidation for certain components (eg RCTTextInput) on iOS. | ||
if (updatePayload != null) { | ||
UIManager.updateView( | ||
handle._nativeTag, | ||
handle.viewConfig.uiViewClassName, | ||
updatePayload, | ||
); | ||
} | ||
} |
There was a problem hiding this comment.
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?