2017-04-10 56 views
0

我試圖建立一個登錄頁面,使用此代碼:陣營本地TouchableHighlight不工作

<View style={styles.formContainer}> 
    <TouchableHighlight onPress={this.props.authentication}> 
     <Icon.Button name="facebook" style={styles.loginIconButton}> 
      <Text style={styles.loginButtonText}>Login with Facebook</Text> 
     </Icon.Button> 
    </TouchableHighlight> 
</View> 
運行此它給「 可觸摸的孩子必須是本地或轉發setNativeProps到本地組件」時

,所以我包圖標在視圖中,作爲建議的其他職位:

<TouchableHighlight onPress={this.props.authentication.bind(this)}> 
    <View> 
     <Icon.Button name="facebook" style={styles.loginIconButton}> 
      <Text style={styles.loginButtonText}>Login with Facebook</Text> 
     </Icon.Button> 
    </View> 
</TouchableHighlight> 

現在在新聞發佈會不會被觸發了。但是,如果我刪除Icon.Button標籤,並保持文本,它工作正常。我該如何解決這個佈局?

回答

1

爲什麼不嘗試擺脫外部TouchableHighlight,只需將onPress事件添加到Icon.Button

如果你看看能否Icon.Button這裏的代碼(我猜你使用react-native-vector-icons),實際上你可以看到,它創建了一個TouchableHighlight元素作爲元素固有的一部分:https://github.com/oblador/react-native-vector-icons/blob/master/lib/icon-button.js

嘗試將onPress移動到Icon.Button,刪除多餘的包裝視圖,並讓我們知道它是如何工作的!

+0

是的,它的功能就像一個魅力 - 應該先看看源頭:) –