-
Notifications
You must be signed in to change notification settings - Fork 46.9k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Adding ReactNative.setNativeProps that takes a ref (#14907)
* Adding ReactNative.setNativeProps that takes a ref * Adding test for components rendered with Fabric with Paper's setNativeProps * Fixing flow types * Fix prettier * Rename ReactNativeSetNativeProps.js to be more general
- Loading branch information
Showing
7 changed files
with
242 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
43 changes: 43 additions & 0 deletions
43
packages/react-native-renderer/src/ReactNativeRendererSharedExports.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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): void { | ||
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, | ||
); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters