0

我試過react-nativeButton這是工作正常。我想自定義Button,所以這讓我去TouchableOpacity。我正在嘗試設置反應原始導航,如下圖,現在不工作。反應原生導航不能在TouchableOpacity

我使用這個導航https://reactnavigation.org/

index.android.js

/** 
* https://github.com/facebook/react-native 
* @flow 
*/ 

import React, { Component } from "react"; 
import { 
    AppRegistry, 
    Image, 
    View, 
    Text, 
    Button, 
    StyleSheet, 
    TouchableOpacity 
} from "react-native"; 
import { StackNavigator } from "react-navigation"; 
import EnableNotificationScreen from "./EnableNotificationScreen"; 
import styles from "./Styles"; 
import * as strings from "./Strings"; 

class SplashScreen extends Component { 
    render() { 
    console.disableYellowBox = true; 
    const { navigate } = this.props.navigation; 
    return (
     <View style={styles.container}> 
     <Image source={require("./img/talk_people.png")} /> 
     <Text style={styles.textStyle}> {strings.talk_people} </Text> 

     <TouchableOpacity> 
      <View 
      style={{ 
       backgroundColor: "#FE434C", 
       alignItems: "center", 
       justifyContent: "center", 
       borderRadius: 10, 
       width: 240, 
       marginTop: 30, 
       height: 40 
      }} 
      onPress={() => { 
       this.navigate("EnableNotifcation"); 
      }} 
      > 
      <Text style={{ color: "white" }}>CONTINUE</Text> 
      </View> 
     </TouchableOpacity> 
     </View> 
    ); 
    } 
} 

const ScheduledApp = StackNavigator(
    { 
    Splash: { 
     screen: SplashScreen, 
     navigationOptions: { 
     header: { 
      visible: false 
     } 
     } 
    }, 
    EnableNotification: { 
     screen: EnableNotificationScreen, 
     navigationOptions: { 
     header: { 
      visible: false 
     } 
     } 
    } 
    }, 
    { 
    initialRouteName: "Splash" 
    } 
); 

AppRegistry.registerComponent("Scheduled",() => ScheduledApp); 
+0

(不是答案)我用我的項目(大)https://github.com/aksonov/react-native-router-flux,它真的很棒 –

回答

1

正是在這條線this.navigate("EnableNotifcation");

一個tpyo錯誤

我改正了它,現在它正在工作。 this.navigate("EnableNotification");

0

的onPress道具應該是裏面TouchableOpacity,而不是裏面的道具觀像你擁有了它。看到下面的僞代碼

<TouchableOpacity onPress = {...}> 
    <View style = {{}}> 
    //Rest of the code 

這應該解決它。在一個旁註,我會建議增加對您的視圖分量的新的風格,那裏有在有很多的元素:P

編輯:

  <TouchableOpacity onPress = {/*do this*/}> 
       <View style={{ backgroundColor: "#FE434C", 
           alignItems: "center", 
           justifyContent: "center", 
           borderRadius: 10, 
           width: 240, marginTop: 30, 
           height: 40 }}> 
        <Text style={{ color: "white" }}> 
         {"CONTINUE"} 
        </Text> 
       </View> 
      </TouchableOpacity> 
+0

我的錯誤,我編輯了上一個問題的答案。 –

+0

嗯'導航( 「EnableNotifcation」)}> <查看 風格= {{ 的backgroundColor: 「#FE434C」, alignItems: 「中心」, justifyContent: 「中心」, borderRadius:10, 寬度:240, marginTop:30, 高度:40 }} > <文本樣式= {{顏色: 「白」}}>繼續 '仍然不工作 –

+0

繼續是一個關鍵字,我已經更正了你的代碼,它適用於我。我建議在提問時提供錯誤。更正後的代碼發佈在原始答案中。 –