ios - react native 按钮单击移动到另一个屏幕

标签 ios reactjs react-native

我是 React Native 的新手。我需要这里的简单场景,方法是单击按钮转到新屏幕。 react native 按钮单击移动到另一个屏幕 我试过了

<TouchableHighlight
onPress={this.register}
style={styles.button1}>
    <Text style={styles.buttontext1}>
        Registration
    </Text>
</TouchableHighlight>

register(){

  //What should I write in here to go to a new layout.

}

最佳答案

例子:

将下一段代码写入 index.ios.js

'use strict';
    import React, {
        AppRegistry,
        Component,
        StyleSheet,
        View,
        NavigatorIOS
    } from 'react-native';

    var rootPage = require('./root.IOS')
    var client = React.createClass({
      render() {
        return (
            <NavigatorIOS
                style = {styles.container}
                initialRoute={{
              title: "Root",
              navigationBarHidden: true,
              component:rootPage
              }}/>
        );
      }
    });

    const styles = StyleSheet.create({
      container: {
        flex: 1,
      }
    });

    AppRegistry.registerComponent('client', () => client);

在文件“root.IOS.js”中

'use strict';

    import React, {
        StyleSheet,
        View,
        TouchableHighlight,
        Text,
        Dimensions,

    } from 'react-native';

    var NextPage = require('./nextPage.IOS.js');

    var rootPage = React.createClass({
        goDerper: function() {
            this.props.navigator.push({
                title: 'nextPage',
                component: NextPage,
                navigationBarHidden: true,
                passProps: {myElement: 'text'}
            });
        },
        render: function(){
            return(
                <View style={styles.container}>
                    <TouchableHighlight
                        onPress={() => this.goDerper()}>
                        <Text>We must go derper</Text>
                    </TouchableHighlight>
                </View>
            );
        }
    })

    var styles = StyleSheet.create({
        container: {
            flex: 1,
            marginTop: 20
        }
    });
    module.exports = rootPage;

文件“nextPage.IOS.js”中的这段代码

'use strict';
var React = require('react-native');
var {
    StyleSheet,
    View,
    Text,
    } = React;
var Register = React.createClass({
    render: function() {
        return (
          <View style={styles.container}>
                <Text style={styles.text}>My value: {this.props.myElement}</Text>
                <Text>any text</Text>
            </View>
        );
    }
})
var styles = StyleSheet.create({
    container: {
        flex: 1
    }
});
module.exports = nextPage;

关于ios - react native 按钮单击移动到另一个屏幕,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35331737/

相关文章:

ios - Swift - 在 UITableView 中组合 UITextfield

iOS 11.0.1 在 vi​​ewDidLayoutSubviews 中崩溃

ios - 向下滑动关闭垂直 ScrollView

javascript - 为从索引文件导入的 React 组件设置样式时出错,但直接从组件文件导入时则不会

ios - 如何在 React Native 中实现 slider 菜单

iphone - 使用echoprint对整个iPhone音乐库进行指纹识别

javascript - 渲染 Prop 与 HOC?

javascript - 传单弹出窗口不会打开( react )

reactjs - npm install react-native-paper 期间出现问题

javascript - 用空字符串 react 受控组件输入值