Skip to content

Commit cf9168f

Browse files
committed
handle diffProperties as well
1 parent a853ef5 commit cf9168f

File tree

2 files changed

+33
-7
lines changed

2 files changed

+33
-7
lines changed

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

Lines changed: 16 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -287,14 +287,23 @@ function diffProperties(
287287
prevProp = prevProps[propKey];
288288
nextProp = nextProps[propKey];
289289

290-
// functions are converted to booleans as markers that the associated
291-
// events should be sent from native.
292290
if (typeof nextProp === 'function') {
293-
nextProp = (true: any);
294-
// If nextProp is not a function, then don't bother changing prevProp
295-
// since nextProp will win and go into the updatePayload regardless.
296-
if (typeof prevProp === 'function') {
297-
prevProp = (true: any);
291+
if (typeof attributeConfig === 'object') {
292+
// When the config for a function prop has a custom process method
293+
// we don't assume its a regular event handler, but use the process method:
294+
nextProp = attributeConfig.process(nextProp);
295+
if (typeof prevProp === 'function') {
296+
prevProp = attributeConfig.process(prevProp);
297+
}
298+
} else {
299+
// functions are converted to booleans as markers that the associated
300+
// events should be sent from native.
301+
nextProp = (true: any);
302+
// If nextProp is not a function, then don't bother changing prevProp
303+
// since nextProp will win and go into the updatePayload regardless.
304+
if (typeof prevProp === 'function') {
305+
prevProp = (true: any);
306+
}
298307
}
299308
}
300309

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

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -461,4 +461,21 @@ describe('ReactNativeAttributePayloadFabric.diff', () => {
461461
),
462462
).toEqual(null);
463463
});
464+
465+
it('should use the process function config when prop is a function', () => {
466+
const process = jest.fn(a => a);
467+
const nextFunction = function () {}
468+
expect(
469+
diff(
470+
{
471+
a: function () {},
472+
},
473+
{
474+
a: nextFunction,
475+
},
476+
{a: {process}},
477+
),
478+
).toEqual({a: nextFunction});
479+
expect(process).toBeCalled()
480+
})
464481
});

0 commit comments

Comments
 (0)