[WIP] PoC: Use jsi::Value
from prop directly
#47717
Draft
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:
🚧 THIS PoC IS WORK IN PROGRESS
This PR highlights how we'd like to access the underlying
jsi::Value
directly to work with complex data types currently not supported for our Fabric Component Views.The problem basically being that the jsi prop object we receive from JS in the
FabricUIManager
is converted to aRawProps
type, which only allows us to access props via a.at
method which returns aRawValue
. ThisRawValue
only supportsfolly::dynamic
types (primitives, arrays and objects), to which we convert the originaljsi::Value
for every prop.We'd like to pass complex types such as
HostObjects
orjsi::Object
s withNativeState
attached to our components.The goal of this PoC PR is not to be merged to core but to discuss how we can make such a change happen.
Possible solutions
Expose jsi::Value and jsi::Runtime in
RawProps
RawProps
already holds thejsi::Object
to the original prop object which we could simply expose to access the real underlyingjsi::Value
of a prop, which is what this PoC does:https://github.com/hannojg/react-native/blob/e186024d43bb7f8ed70e73fe4ed334bc534eb9af/packages/react-native/ReactCommon/react/renderer/core/RawProps.h#L97-L101
and then when creating the props for our specific fabric component we can do:
https://github.com/hannojg/react-native/blob/e186024d43bb7f8ed70e73fe4ed334bc534eb9af/packages/rn-tester/ManualComponent/ManualFabricComponentView.mm#L27-L42
Have jsi::Value and jsi::Runtime in
RawValue
We could have a pair of jsi::Value and jsi::Runtime in
RawValue
. Then for the prop implementation for a fabric native component view we could use this value during parsing to convert it to our desired complex type:https://github.com/hannojg/react-native/blob/e186024d43bb7f8ed70e73fe4ed334bc534eb9af/packages/react-native/ReactCommon/react/renderer/core/RawValue.h#L75-L88
Problems:
RawPropParser
to decide when we should parse tofolly::dynamic
or when to usejsi::Value
during parsing (here we'd need to decide whether to use afolly::dynamic
arg orjsi::Value
)Make
RawProps
hybrid / genericThe actual answer seems to be to make the
RawPropsParser
generic. A PoC explanation can be found here:#44966 (comment)
Alternative path to
RawProps
In the
UIManager
add a second way here for example:react-native/packages/react-native/ReactCommon/react/renderer/uimanager/UIManagerBinding.cpp
Line 258 in 0d5c026
Where based on some criteria we wouldn't create
RawProps
but an alternative wrapper (that gives us access to the originaljsi
types)Problems:
RawProps
are used / assumed in a lot of placesChangelog:
Test Plan: