今天在写 RN 的项目的时候,用了 Modal 组件可是出现了如下警告:

Warning: Failed prop type: The prop `onRequestClose` is marked as required in `Modal`, but its value is `undefined`.
    in Modal (at Main.js:27)
    in Main (at SceneView.js:9)
    in SceneView (at StackViewLayout.tsx:888)
    in RCTView (at View.js:45)
    in View (at StackViewLayout.tsx:887)
    in RCTView (at View.js:45)
    in View (at StackViewLayout.tsx:886)
    in RCTView (at View.js:45)
    in View (at createAnimatedComponent.js:153)
    in AnimatedComponent (at StackViewCard.tsx:93)
    in RCTView (at View.js:45)
    in View (at createAnimatedComponent.js:153)
    in AnimatedComponent (at screens.native.js:59)
    in Screen (at StackViewCard.tsx:80)
    in Card (at createPointerEventsContainer.tsx:95)
    in Container (at StackViewLayout.tsx:971)
    in RCTView (at View.js:45)
    in View (at screens.native.js:83)
    in ScreenContainer (at StackViewLayout.tsx:383)
    in RCTView (at View.js:45)
    in View (at createAnimatedComponent.js:153)
    in AnimatedComponent (at StackViewLayout.tsx:379)
    in PanGestureHandler (at StackViewLayout.tsx:372)
    in StackViewLayout (at withOrientation.js:30)
    in withOrientation (at StackView.tsx:103)
    in RCTView (at View.js:45)
    in View (at Transitioner.tsx:267)
    in Transitioner (at StackView.tsx:40)
    in StackView (at createNavigator.js:61)
    in Navigator (at createKeyboardAwareNavigator.js:12)
    in KeyboardAwareNavigator (at createAppContainer.js:429)
    in NavigationContainer (at App.js:15)
    in App (at renderApplication.js:34)
    in RCTView (at View.js:45)
    in View (at AppContainer.js:98)
    in RCTView (at View.js:45)
    in View (at AppContainer.js:115)
    in AppContainer (at renderApplication.js:33)

我是这样写的:

<Modal
    animationType={'none'}
    transparent={false} visible={this.state.ModalVisible}
    style={{ flex: 1, backgroundColor: '#F5FCFF' }}
    onShow={() => { this.setState({ MianVisible: 'flex' }) }}
>
</Modal>

虽然是警告,但是我还是想解决它,它大概是说没有传 onRequestClose 这个属性吧,虽然我现在不知道这是干嘛用的,但是先传一个吧…

<Modal
    animationType={'none'}
    transparent={false} visible={this.state.ModalVisible}
    style={{ flex: 1, backgroundColor: '#F5FCFF' }}
    onShow={() => { this.setState({ MianVisible: 'flex' }) }}
    onRequestClose={() => { }}
>
</Modal>