Details about js interface redirection and value transfer

Source: Internet
Author: User
Details about how to jump to the js interface and pass the value. The functions of this example are as follows: Register page (Register. js), click registration, and jump to the registration result page (RegisterResult. js), and pass the registered mobile phone number to the past, indicating that xx registration is successful.

Index. Android. js

'Use strict 'import React, {Component} from 'react'; import {AppRegistry, Navigator, BackAndroid} from 'react-native '; var Register = require ('. /study/Register '); let RegisterResult = require ('. /study/registerresult'); var NaviModule = React. createClass ({// inform Navigator module about the effect configureScene: function (route) {return Navigator when switching views. sceneConfigs. fadeAndroid;}, // inform the Navigator module about how to mount the current view renderScene: function (router, navigator) {this. _ navigator = navigator; switch (router. name) {case "register": return
 
  
Case "registerResult": return
  
   
}, // Life Cycle function of React --- when a component is attached, componentDidMount: function () {var navigator = this. _ navigator; BackAndroid. addEventListener ('navimodulelistener ', () => {if (navigator & navigator. getCurrentRoutes (). length> 1) {navigator. pop (); return true;} return false;}) ;}, // Life Cycle function of React --- Call componentWillUnmount: function () {BackAndroid when the component is removed. removeEventListener ('navimodulelistener ');}, render: function () {return (
   ) ;}}); AppRegistry. registerComponent ('firstdemo', () => NaviModule );
  
 

Registration page (Register. js)

'Use strict 'import React, {Component} from 'react'; import {AppRegistry, StyleSheet, Text, View, TextInput} from 'react-native '; let Dimensions = require ('dimensions '); let totalWidth = Dimensions. get ('window '). width; let leftStartPoint = totalWidth * 0.1; let componetWidth = totalWidth * 0.8; let Register = React. createClass ({getInitialState: function () {return {inputedNum: '', inputedPW:'',}, updatePW: function (newText) {this. setState ({inputedPW: newText}) ;}, render: function () {return (
     
  
   
This. setState ({inputedNum: aa})}/>
   
    
The mobile phone number you entered: {this. state. inputedNum}
       
   
    
This. updatePW (newText)}/>
    
     
Note volume
       
   
  
 );}, UserRegister: function () {this. props. navigator. replace ({telephoneNumber: this. state. inputedNum, name: 'registerresult',}) ;}}); const styles = StyleSheet. create ({container: {flex: 1, flexDirection: 'column', justifyContent: 'center', backgroundColor: '# F5FCFF',}, numberInputStyle: {top: 20, left: leftStartPoint, width: componetWidth, backgroundColor: 'Gray ', fontSize: 20}, textPromptStyle: {top: 30, left: leftStartPoint, width: componetWidth, fontSize: 20}, passwordInputStyle: {top: 50, left: leftStartPoint, width: componetWidth, backgroundColor: 'Gray ', fontSize: 20}, bigTextPrompt: {top: 70, left: leftStartPoint, width: componetWidth, backgroundColor: 'Gray ', color: 'white', textAlign: 'center', fontSize: 60}); module. exports = Register;

Registry result. js

'Use strict 'import React, {Component} from 'react'; import {AppRegistry, StyleSheet, Text, View, TextInput} from 'react-native '; let RegisterResult = react. createClass ({render: function () {return (
         
  
   
{This. props. telephoneNumber} registered successfully
        
 ) ;}}); Const styles = StyleSheet. create ({container: {flex: 1, flexDirection: 'column', justifyContent: 'center', alignItems: 'center', backgroundColor: '# f5fcff',}, text: {flexWrap: 'wrap', backgroundColor: 'Gray ', fontSize: 20, paddingTop: 10, paddingBottom: 10, paddingLeft: 25, paddingRight: 25 },}); module. exports = RegisterResult;
Related Article

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.