Modal上没有指针事件

Ans*_*oka 16 pointer-events react-native

有没有一种方法来设置pointerEventsnone一个Modal?我试图在父母范围之外渲染一个子视图,我能做到这一点的唯一方法是使用一个Modal.忽视pointerEvents孩子似乎不起作用.

<View>
  <View style={{flex: 1, backgroundColor: 'red'}}></View>
  <Modal
    animationType='fade'
    transparent={true}
    visible={true}
    pointerEvents='none'>
    <View style={{flex:1, alignItems: 'center', justifyContent: 'center'}} pointerEvents='none'>
    </View>
  </Modal>
</View>
Run Code Online (Sandbox Code Playgroud)

sut*_*her 1

我不知道你是否是这个意思,因为你的描述对我来说不够清楚......但我前段时间也需要一个模态,如果我点击应用程序中的任何地方,它不应该关闭,但前提是我执行给定的操作(对我来说,这是在给定的单击路线之后模态中的按钮单击)。

这是我解决这个问题的方法:我使用react-native-modalbox,它做得非常好。

通过大量可能的选项,您还可以处理模态框的点击行为。

一个小例子:

import Modal from 'react-native-modalbox';
 ... 
 ...
        <Modal
          style={[styles.audioToolbarModal, styles.audioToolbarBottomModal]}
          position="bottom"
          backdrop
          swipeToClose={false}
          coverScreen
          onOpened={() => this.startRecording()}
          isDisabled={modalIsDisabled}
          ref={(ref) => { this.audioToolbar = ref; }}
        >
Run Code Online (Sandbox Code Playgroud)

您可能需要的属性是“isDisabled”(通过 State 设置此属性以切换它),并且swipeToClose={false}

我希望,这对你有帮助。