2017-10-17 2 views
0

보기 바깥 쪽에서 탭을 감지하는 방법 (보기는 너비가 1이며 너비는 200입니다). 예를 들어, 사용자 정의보기 (모달과 같은)가 있고 가시성은 상태에 의해 제어됩니다. 그러나 그것을 위해 setState가 수행되지 않았기 때문에 아무 것도 바뀌지 않았습니다. 모달을 제외하고는 사용자가 모든 곳을 탭해야합니다. React Native에서 어떻게 가능합니까?보기의 바깥 부분을 감지하십시오. 네이티브로 반응하십시오.

답변

0

귀하의 모달 주위에 TouchableOpacity를 사용하고 onPress가 맞는지 확인하십시오. 이 예를보십시오.

const { opacity, open, scale, children,offset } = this.state; 
let containerStyles = [ styles.absolute, styles.container, this.props.containerStyle ]; 
let backStyle= { flex: 1, opacity, backgroundColor: this.props.overlayBackground }; 

<View 
    pointerEvents={open ? 'auto' : 'none'} 
    style={containerStyles}> 
    <TouchableOpacity 
     style={styles.absolute} 
     disabled={!this.props.closeOnTouchOutside} 
     onPress={this.close.bind(this)} 
     activeOpacity={0.75}> 
     <Animated.View style={backStyle}/> 
    </TouchableOpacity> 
    <Animated.View> 
     {children} 
    </Animated.View> 
    </View> 

const styles = StyleSheet.create({ 
    absolute: { 
    position: 'absolute', 
    top: 0, 
    left: 0, 
    right: 0, 
    bottom: 0, 
    backgroundColor: 'transparent' 
    }, 
    container: { 
    justifyContent: 'center', 
    elevation: 10, 
    } 
});