Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
4.3k views
in Technique[技术] by (71.8m points)

React Native Navigation: Pass component to screen in passProps

I'm using react-native-navigation and trying to pass a component to a modal screen in passProps. It works but gives me a warning:

Possible Unhandled Promise Rejection (id: 0):
Invariant Violation:
["ModalScreen",{"ContentComponent":{"type":"RCTView","key":null,"ref":null,"props":{},"_owner":null,"_store":{"validated":true}}},{},{"library":{"name":"analytics-react-native","version":"1.2.1"}}] is not usable as a native method argument

and also:

Possible Unhandled Promise Rejection (id: 1):
Error: Exception in HostFunction: Malformed calls from JS: field sizes are different.

[[91,21,21,21,4,92],[2,2,0,0,2,0] (..... very long log, see here ?? https://gist.github.com/LaVielle/288b48548387399f5247482634795297)

This is happening on both iOS and Android.

The modal screen is defined like this:

interface Props extends NavigationComponentProps {
  ContentComponent: React.ElementType | React.ReactElement | null;
}

export const ModalScreen: React.FC<Props> = ({ componentId, ContentComponent }) => (
  <View>
    {ContentComponent}
  </View>
)


ModalScreen.options = {
  topBar: {
    visible: false,
    drawBehind: true,
  },
  layout: {
    backgroundColor: 'transparent',
    componentBackgroundColor: 'transparent',
  },
  modalPresentationStyle: OptionsModalPresentationStyle.overCurrentContext,
}

and this is how I navigate to it (passing a simple View as ContentComponent):

await Navigation.showModal({
  stack: {
    children: [{
      component: {
        name: navRoutes.ModalScreen,
        passProps: {
          ContentComponent: <View />,
        },
      },
    }],
  },
})

I'm guessing it is not recommended to pass a component or JSX in passProps, but I cannot find any mention of that in the the RNN docs and issues. Can I ignore this warning? Is there a better way to pass a component in passProps?

Thx :)


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)
等待大神答复

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...