feat: use process function if prop is a function but view attribute configured a process function #48777
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Summary:
Motivation
As per the ViewConfig flow types we can configure a custom
process
function for props:react-native/packages/react-native/Libraries/Renderer/shims/ReactNativeTypes.js
Lines 38 to 43 in 22e7691
However, this
process
function is ignored in thediffProperties
function when the incoming prop is afunction
.This is a problem, as we have no mechanism to opt-out of the default behaviour of a function prop being set to
true
. In our case we are trying to pass the props as direct JSI values to our View components, but right now function props are always received as true, due to this forced behaviour and we want to opt out.This PR implements a check to call the
process
function if it's set. This way we can opt-out of passing functions astrue
to the native side instead of the actual function.Note: this is only one piece of the puzzle, as this flow only gets triggered for updating props on a component (as far as I can see). The flow for when a component gets created is different and is handled here:
process
function to allow processing function props react#32119Changelog:
[GENERAL] [ADDED] - Call
process
for a prop's view config, even if that prop is a function.Test Plan:
I modified the code manually in a template react-native app and confirmed its working. This is a code path you only need in very special cases, thus it's a bit hard to provide a test for this. I recorded a video where you can see that the changes are active and the prop is being passed as native value once the props for a component get updated:
compressed2.mp4