2016-02-27 57 views
0

升級了我們的陣營本地項目0.20和我們所有的AlertIOS的對話正在打破。正在發生的事情是將tap事件傳遞到組件,並且AlertIOS上的按鈕從未被觸摸。點擊事件傳遞到下面的對話框父組件(陣營母語)

這裏有一個簡單的例子和​​截圖:

class TabOption extends Component { 
    constructor(props) { 
    super(props); 
    } 

    resetData =() => { 
    AlertIOS.alert('Reset Data', 
     'Are you sure you want to reset your data?', 
     [{text:'Yes', onPress:() => console.log('FIRE')}, 
     {text:'No'}]) 
    }; 

    render() { 
    return(
     <View style={{flex: 1,flexDirection: 'column',backgroundColor: 'white'}}> 
     <TouchableHighlight onPress={this.resetData} style={styles.tabOptionContainer}> 
      <Text> Disconnect </Text> 
     </TouchableHighlight> 
     </View> 
    ); 
    }; 
} 

const styles = StyleSheet.create({ 
    tabOptionContainer: { 
    width:Dimensions.width, 
    height:50, 
    justifyContent:'center', 
    alignItems:'center', 
    backgroundColor:'white', 
    } 
}); 

下面的截圖,如果我單擊YesNo水龍頭事件被傳送到警報下的組件。我實際上可以完全與組件交互,而在警報本身上不會觸發輕擊事件。

Alert fail

注:這是一個相當大的提升。我們將React從0.14撞到0.20。升級之前,一切正常。這裏發生了什麼?

回答

0

如果我理解您的問題,竊聽是或否不會關閉該警告框,而是被下面敲擊組件。

我用你的例子,並調整了一下here

警示框上的按鍵正常工作。一探究竟。

代碼

var React = require('react-native'); 
var { 
    AlertIOS, 
    AppRegistry, 
    Dimensions, 
    StyleSheet, 
    TouchableHighlight, 
    Component, 
    Text, 
    View, 
} = React; 

class StackOverflowApp extends Component { 
    constructor(props) { 
    super(props); 

    this.state = { 
     color: 'pink' 
    }; 
    } 

    resetData =() => { 
    AlertIOS.alert('Reset Data', 
     'Are you sure you want to reset your data?', 
     [{text:'Yes', onPress:() => this.setState({color: 'red'})}, 
     {text:'No', onPress:() => this.setState({color: 'blue'})}]) 
    }; 

    render() { 
    return(
     <View style={{flex: 1,flexDirection: 'column',backgroundColor: this.state.color}}> 
     <TouchableHighlight onPress={this.resetData} style={styles.tabOptionContainer}> 
      <Text> Disconnect </Text> 
     </TouchableHighlight> 
     </View> 
    ); 
    }; 
} 

const styles = StyleSheet.create({ 
    tabOptionContainer: { 
    width:Dimensions.width, 
    height:50, 
    justifyContent:'center', 
    alignItems:'center', 
    backgroundColor:'white', 
    } 
}); 

AppRegistry.registerComponent('StackOverflowApp',() => StackOverflowApp); 
+0

嘿@GHamaide我感謝您抽出寶貴的時間來作出迴應,但我這是如何解決這個問題很困惑?我知道你有一個工作組件,在我們的情況下它通常也可以工作,那麼你能解釋一下這將如何解決觸摸事件問題嗎? – crockpotveggies

+0

我的觀點主要是告訴你,錯誤不是來自你給我們的代碼,而是來自別的東西。您的代碼的複製按預期的方式工作。 –

+0

好的,謝謝。我不確定這是否會被視爲「答案」,因爲它可以爲原始問題提供解決方案。不過,我的確會在這裏發佈一個解決方案時,我發現一個(到目前爲止,我們剛剛重建的應用程序)。 – crockpotveggies