2017-06-30 52 views
1

當我點擊一個按鈕時,我如何進入下一個屏幕?單擊按鈕時如何在原生反應中重定向?

這裏是我的代碼

import React, { Component } from 'react'; 
import { 
    AppRegistry, 
    StyleSheet, 
    Text, 
    View, 
    Button, 
} from 'react-native'; 
import Test from './android/components/Test' 


export default class ReactTest extends Component { 


    render() { 

    return (

     <View style={styles.container}> 
     <Text style={styles.welcome}> 
      Welcome click the button to register. 
     </Text> 
     <Button 
        style={styles.cancelButton} 
        onPress={this.editUser} 
        title="Register" 
        color="#343434" 
        accessibilityLabel="Register a User."/> 
     </View> 


    ); 
    } 
} 

我是新來的反應母語。當按下注冊按鈕時,我試圖從一個屏幕導航到另一個屏幕。

回答

2

您可以使用以下任一API的

但我建議你使用React Navigation。這裏是一個示例如何使用React Navigation

import { 
    StackNavigator, 
} from 'react-navigation'; 

const App = StackNavigator({ 
    Home: { screen: HomeScreen }, 
    Profile: { screen: ProfileScreen }, 
}); 

class HomeScreen extends React.Component { 
    static navigationOptions = { 
    title: 'Welcome', 
    }; 
    render() { 
    const { navigate } = this.props.navigation; 
    return (
     <Button 
     title="Go to Jane's profile" 
     onPress={() => 
      navigate('Profile') 
     } 
     /> 
    ); 
    } 
} 
+0

@kurokocrunch你可以關注這個嗎? –

+1

謝謝@Jeffrey Rajan – anup

相關問題