ReactNative page Jump instance code, reactnative jump

Source: Internet
Author: User

ReactNative page Jump instance code, reactnative jump

As follows:

Go to the working directory and run

React-native init NavigatorProject

Create a project NavigatorProject

Import React, {Component} from 'react '; import {AppRegistry, StyleSheet, Text, View, TouchableHighlight, Image, Navigator} from 'react-native '; class navigatorProject extends Component {render () {let defaultName = 'firstpagename '; let defaultComponent = FirstPageComponent; return (<NavigatorinitialRoute = {name: defaultName, component: defaultComponent }}// initialize the Navigator and specify the default page configureScene = {(route) =>{ return Navigator. sceneConfigs. floatFromRight; // configure the scene animation. The animation is displayed when the page jumps.} renderScene = {(route, navigator) =>{ let Component = route. component; return <Component {... route. params} navigator = {navigator}/> // Rendering scenario}/>) ;}// the first page class FirstPageComponent extends Component {clickJump () {const {navigator} = this. props; if (navigator) {navigator. push ({// navigator. push incoming name and the component Page name you want to jump to: "SecondPageComponent", component: SecondPageComponent}) ;}} render () {return (<View style = {styles. container }> <Text> I am the first page </Text> <TouchableHighlightunderlayColor = "rgb (180,135,250)" activeOpacity = {0.5} style = {borderRadius: 8, padding: 8, marginTop: 8, backgroundColor: "# F30"} onPress = {this. clickJump. bind (this) }>< Text> click to enter the second page </Text> </TouchableHighlight> </View> );}} // second page class SecondPageComponent extends Component {clickJump () {const {navigator} = this. props; if (navigator) {navigator. pop (); // navigator. pop uses the current page to exit the stack and displays the previous page in the stack .}} render () {return (<View style = {styles. container }> <Text> I am the second page </Text> <TouchableHighlightunderlayColor = "rgb (180,135,250)" activeOpacity = {0.5} style = {borderRadius: 8, padding: 8, marginTop: 5, backgroundColor: "# F30"} onPress = {this. clickJump. bind (this) }>< Text> click to return to the first page </Text> </TouchableHighlight> </View>) ;}} const styles = StyleSheet. create ({container: {flex: 1, justifyContent: 'center', alignItems: 'center', backgroundColor: '# ffff',},}); AppRegistry. registerComponent ('navigatorproject', () => navigatorProject );

The above is the ReactNative page Jump instance Code introduced by the editor. I hope it will be helpful to you. If you have any questions, please leave a message and the editor will reply to you in time. Thank you very much for your support for the help House website!

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.