Skip to content

Commit

Permalink
Add support for setNativeProps to Fabric
Browse files Browse the repository at this point in the history
  • Loading branch information
sammy-SC committed Dec 6, 2022
1 parent d807eb5 commit e4e62e6
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 16 deletions.
10 changes: 4 additions & 6 deletions packages/react-native-renderer/src/ReactFabricHostConfig.js
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ const {
unstable_DefaultEventPriority: FabricDefaultPriority,
unstable_DiscreteEventPriority: FabricDiscretePriority,
unstable_getCurrentEventPriority: fabricGetCurrentEventPriority,
setNativeProps,
} = nativeFabricUIManager;

const {get: getViewConfigForType} = ReactNativeViewConfigRegistry;
Expand Down Expand Up @@ -207,13 +208,10 @@ class ReactFabricHostComponent {
}

setNativeProps(nativeProps: Object) {
if (__DEV__) {
console.error(
'Warning: setNativeProps is not currently supported in Fabric',
);
const {stateNode} = this._internalInstanceHandle;
if (stateNode != null) {
setNativeProps(stateNode.node, nativeProps);
}

return;
}

// This API (addEventListener, removeEventListener) attempts to adhere to the
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,8 @@ const RCTFabricUIManager = {

dispatchCommand: jest.fn(),

setNativeProps: jest.fn(),

sendAccessibilityEvent: jest.fn(),

registerEventHandler: jest.fn(function registerEventHandler(callback) {}),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -200,21 +200,15 @@ describe('measureLayout', () => {
});

describe('setNativeProps', () => {
test('setNativeProps(...) emits a warning', () => {
test('setNativeProps(...) invokes setNativeProps on Fabric UIManager', () => {
const {
UIManager,
} = require('react-native/Libraries/ReactPrivate/ReactNativePrivateInterface');

const [[fooRef]] = mockRenderKeys([['foo']]);
fooRef.setNativeProps({});

expect(() => {
fooRef.setNativeProps({});
}).toErrorDev(
['Warning: setNativeProps is not currently supported in Fabric'],
{
withoutStack: true,
},
);
expect(UIManager.updateView).not.toBeCalled();
expect(nativeFabricUIManager.setNativeProps).toHaveBeenCalledTimes(1);
});
});
2 changes: 1 addition & 1 deletion scripts/flow/react-native-host-hooks.js
Original file line number Diff line number Diff line change
Expand Up @@ -186,7 +186,7 @@ declare var nativeFabricUIManager: {
payload: Object,
) => void,
) => void,

setNativeProps: (node: Object, nativeProps: Object) => Object,
dispatchCommand: (node: Object, command: string, args: Array<any>) => void,
sendAccessibilityEvent: (node: Object, eventTypeName: string) => void,

Expand Down

0 comments on commit e4e62e6

Please sign in to comment.