When pushing new screen with passProps with array of function the app will freeze
this.props.navigator.push({
screen: 'myScreen',
passProps: {myFunctions: [() => null, () => null]},
});
Every unserializable data causes this?
What about passing a single function, does that cause a freeze as well?
If I pass just single function like this it does not freeze:
this.props.navigator.push({
screen: 'myScreen',
passProps: {myFunctions: () => null},
});
I ran to this problem when passing array of validators to my component when using redux-form https://redux-form.com/7.3.0/examples/fieldlevelvalidation/
hmm... this is strange. You think RN fails to serialize array of functions before going over the bridge?
What about converting the array to an object, something like:
function arrToObj(arr) {
const result = {};
for (let i = 0; i < arr.length; i++) {
result[i] = arr[i];
}
return result;
}
Yeah I actually did function which converts my array to object as workaround:
const validatorsToObject = validators =>
validators.reduce((acc, validator, index) => ({ ...acc, [index]: validator }), {});
@henrikra I'm going to close the issue as we probably will never get to it and it doesn't exist in v2.
Sorry for the inconvenience
So I can remove my hack function when I start using v2?
Yes, in v2 props are never passed over the bridge and are not used by rnn.
Please can someone give example on how to passProps json objects to another screen in RNN v2
@guyca
Yes, in v2 props are never passed over the bridge and are not used by rnn.
Are you sure? We seem to be having an issue with something similar in V2 with passProps when opening a modal. Basically, it looks something like
(component) => Navigation.showModal({
title: title,
stack: {
children: [{
component: {
name: 'modal',
passProps: {
component
}
}
}]
});
This crashes with the “field sizes are different” red screen from https://github.com/wix/react-native-navigation/issues/3226 – if the component is wrapped with React.forwardRef() (either directly or via react-forwardref-utils). Remove the ref forwarding and the error goes away.
We’re still investigating the nature of this problem, but it seems to be related to RNN and passProps.
A small workaround we used:
component:
name: 'NewScreen'
passProps:
getNonSerializableObjectHere: => nonSerializableObjectHere
It is interesting that you cannot pass complex objects, but you can pass functions that return whatever you want.
Most helpful comment
@guyca
Are you sure? We seem to be having an issue with something similar in V2 with
passPropswhen opening a modal. Basically, it looks something likeThis crashes with the “field sizes are different” red screen from https://github.com/wix/react-native-navigation/issues/3226 – if the component is wrapped with
React.forwardRef()(either directly or viareact-forwardref-utils). Remove the ref forwarding and the error goes away.We’re still investigating the nature of this problem, but it seems to be related to RNN and
passProps.