React Native change view onPress

杀马特。学长 韩版系。学妹 提交于 2019-12-13 02:42:56

问题


I have searched on google but I don't know react.

When I click on the button 'Connexion' I would like to be forwarded to the page About.js.

My app.js :

import React from 'react';
import {View, TextInput, StyleSheet, Text } from 'react-native';
import { Header, Button } from 'react-native-elements';
import About from './component/About';
export default class App extends React.Component {

  render() {
    return (
        <View style={{flex: 1}}>
           
            <Button
                title="CONNEXION"
                buttonStyle={{backgroundColor: "#F1C40F", borderColor: "transparent", marginTop: 20,}}
            />
            
        </View>
    );
  }

}

   

My About.js

import React from 'react';
import {Text, View, StyleSheet } from 'react-native';
export default class About extends React.Component{
    render() {
        return (

            <View style={style.view}>
                <Text style={style.title}> A propos de moi</Text>
                
            </View>
        );
    }
}


});

回答1:


  1. install react-navigation,

yarn add react-navigation

or with npm

npm install --save react-navigation

  1. Inside your index.js, import StackNavigator

    import App from './components/app; import About1 from './components/About; import {StackNavigator} from 'react-navigation';

  2. Then add below code to the last of index.js

    export default StackNavigator({ Home: {

    screen: App,

    },

    Aboutsss:{ screen: About1, },

});

  1. Inside app.js, inside button give,

    onPress = {this.props.navigation.navigate('Aboutsss')}

Hope you understand and if any doubt feel free to comment. note:- when I try to install using npm I got some error in windows, but no problem with yarn.




回答2:


To navigate between the screens you can use stackNavigator.

https://facebook.github.io/react-native/docs/navigation.html



来源:https://stackoverflow.com/questions/48872641/react-native-change-view-onpress

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!