Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit a5e5f2a

Browse files
committed
Adding test for components rendered with Fabric with Paper's setNativeProps
1 parent ef52e22 commit a5e5f2a

File tree

2 files changed

+24
-2
lines changed

2 files changed

+24
-2
lines changed

packages/react-native-renderer/src/ReactNativeSetNativeProps.js

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ import UIManager from 'UIManager';
1919

2020
const ReactCurrentOwner = ReactSharedInternals.ReactCurrentOwner;
2121

22-
export function setNativeProps(handle, nativeProps: Object) {
22+
export function setNativeProps(handle: any, nativeProps: Object) {
2323
if (handle._nativeTag == null) {
2424
warningWithoutStack(
2525
handle._nativeTag != null,
@@ -34,7 +34,6 @@ export function setNativeProps(handle, nativeProps: Object) {
3434
}
3535

3636
const updatePayload = create(nativeProps, handle.viewConfig.validAttributes);
37-
3837
// Avoid the overhead of bridge calls if there's no update.
3938
// This is an expensive no-op for Android, and causes an unnecessary
4039
// view invalidation for certain components (eg RCTTextInput) on iOS.

packages/react-native-renderer/src/__tests__/ReactFabricAndNative-test.internal.js

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,12 +13,14 @@
1313
let React;
1414
let ReactFabric;
1515
let ReactNative;
16+
let UIManager;
1617
let createReactNativeComponentClass;
1718

1819
describe('ReactFabric', () => {
1920
beforeEach(() => {
2021
jest.resetModules();
2122
ReactNative = require('react-native-renderer');
23+
UIManager = require('UIManager');
2224
jest.resetModules();
2325
jest.mock('shared/ReactFeatureFlags', () =>
2426
require('shared/forks/ReactFeatureFlags.native-oss'),
@@ -49,4 +51,25 @@ describe('ReactFabric', () => {
4951
let handle = ReactNative.findNodeHandle(ref.current);
5052
expect(handle).toBe(2);
5153
});
54+
55+
it('sets native props with setNativeProps on Fabric nodes with the RN renderer', () => {
56+
UIManager.updateView.mockReset();
57+
const View = createReactNativeComponentClass('RCTView', () => ({
58+
validAttributes: {title: true},
59+
uiViewClassName: 'RCTView',
60+
}));
61+
62+
let ref = React.createRef();
63+
64+
ReactFabric.render(<View title="bar" ref={ref} />, 11);
65+
expect(UIManager.updateView).not.toBeCalled();
66+
ReactNative.setNativeProps(ref.current, {title: 'baz'});
67+
expect(UIManager.updateView).toHaveBeenCalledTimes(1);
68+
expect(UIManager.updateView).toHaveBeenCalledWith(
69+
expect.any(Number),
70+
'RCTView',
71+
{title: 'baz'},
72+
);
73+
});
74+
5275
});

0 commit comments

Comments
 (0)