2016-08-21 75 views
0

例如,如果你想關閉該模式時,灰色的背景下(外中間的白色框中的任意位置)被點擊:你怎麼知道當一個視圖被挖掘,但它的孩子不是?

enter image description here

containerOnClick(e) { 
    if (isNotInsideChildView(e)) { 
     closeModal() 
    } 
    } 

<TouchableWithoutFeedback 
    onPress={this.containerOnClick} 
    > 
    <View 
    style={{ 
     backgroundColor: 'rgba(0, 0, 0, 0.5)', 
     flex: 1, 
     justifyContent: 'center', 
    }} 
    > 
    <View 
     style={{ 
     backgroundColor: 'white', 
     padding: 10, 
     }} 
     > 
     <Text>dkfj</Text> 
    </View> 
    </View> 
</TouchableWithoutFeedback> 

回答

0

包裹孩子在<Touchable*>組件。後裔Touchables(即使沒有onPress道具)阻止onPress發生在祖先Touchables內部的後代的邊界。

相關問題