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

Add support for setNativeProps to Fabric #25737

Merged
merged 2 commits into from
Dec 9, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 11 additions & 5 deletions packages/react-native-renderer/src/ReactFabricHostConfig.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,10 @@ import type {
TouchedViewDataAtPoint,
} from './ReactNativeTypes';

import {mountSafeCallback_NOT_REALLY_SAFE} from './NativeMethodsMixinUtils';
import {
mountSafeCallback_NOT_REALLY_SAFE,
warnForStyleProps,
} from './NativeMethodsMixinUtils';
import {create, diff} from './ReactNativeAttributePayload';

import {dispatchEvent} from './ReactFabricEventEmitter';
Expand Down Expand Up @@ -52,6 +55,7 @@ const {
unstable_DefaultEventPriority: FabricDefaultPriority,
unstable_DiscreteEventPriority: FabricDiscretePriority,
unstable_getCurrentEventPriority: fabricGetCurrentEventPriority,
setNativeProps,
} = nativeFabricUIManager;

const {get: getViewConfigForType} = ReactNativeViewConfigRegistry;
Expand Down Expand Up @@ -208,12 +212,14 @@ class ReactFabricHostComponent {

setNativeProps(nativeProps: Object) {
if (__DEV__) {
console.error(
'Warning: setNativeProps is not currently supported in Fabric',
);
warnForStyleProps(nativeProps, this.viewConfig.validAttributes);
}
const updatePayload = create(nativeProps, this.viewConfig.validAttributes);

return;
const {stateNode} = this._internalInstanceHandle;
if (stateNode != null && updatePayload != null) {
setNativeProps(stateNode.node, updatePayload);
}
}

// 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 @@ -38,7 +38,7 @@ function mockRenderKeys(keyLists) {

const mockContainerTag = 11;
const MockView = createReactNativeComponentClass('RCTMockView', () => ({
validAttributes: {},
validAttributes: {foo: true},
uiViewClassName: 'RCTMockView',
}));

Expand Down 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({foo: 'baz'});

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