javascript - 问 - React Native App 介绍中的路由

标签 javascript ios react-native

所以我正在玩这个组件:react-native-app-intro

这是我的代码(index.ios.js):

import React, { Component } from 'react';
import { AppRegistry, Alert } from 'react-native';
import AppIntro from 'react-native-app-intro';

import Main from './main';


class coba_reactIntro extends Component {
  onSkipBtnHandle = (index) => {
    Alert.alert('Skip');
    console.log(index);
  }
  doneBtnHandle = () => {
    Alert.alert('Done!');

  }
  nextBtnHandle = (index) => {
    Alert.alert('Next');
    console.log(index);
  }
  onSlideChangeHandle = (index, total) => {
    console.log(index, total);
  }
  render() {
    const pageArray = [{
      title: 'Page 1',
      description: 'Description 1', 
      imgStyle: {
        height: 80 * 2.5,
        width: 109 * 2.5,
      },
      backgroundColor: '#fa931d',
      fontColor: '#fff',
      level: 10,
    }, {
      title: 'Page 2',
      description: 'Description 2', 
      imgStyle: {
        height: 93 * 2.5,
        width: 103 * 2.5,
      },
      backgroundColor: '#a4b602',
      fontColor: '#fff',
      level: 10,
    }];
    return (
      <AppIntro
        onNextBtnClick={this.nextBtnHandle}
        onDoneBtnClick={this.doneBtnHandle}
        onSkipBtnClick={this.onSkipBtnHandle}
        onSlideChange={this.onSlideChangeHandle}
        pageArray={pageArray}
      />
    );
  }
}

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

这是模拟器的结果: enter image description here

这是我的 main.js

import React, { Component } from 'react';
import {
  View,
  Text,
  TextInput,
  TouchableOpacity,
  StyleSheet
} from 'react-native';

const styles = StyleSheet.create({
  container:{
    flex: 1,
    justifyContent: 'center',
    alignItems: 'center',
    padding: 40
  },
  button:{
    textAlign: 'center'
  },
});


module.exports = React.createClass({ 
  render(){
    return(
      <View style={styles.container}>
          <Text style={styles.button}>Hello</Text>
        </View>
      </View>
    )
  }
})

我想连接起来,当用户点击按钮完成(图片:红色标记)时,页面将更改为我的 main.js
我怎样才能在 React Native 中做到这一点?
抱歉这个菜鸟问题

最佳答案

如果你只想在 iOS 上使用,你可以使用 navigatorIOS ( https://facebook.github.io/react-native/docs/navigatorios.html )

或者你可以使用 router flux 来导航(我在我的大部分项目中都使用这个) https://github.com/aksonov/react-native-router-flux

所以你可以使用类似的东西:

export default class PageOne extends Component {
  render() {
    return (
       <Text onPress={Actions.pageTwo}>This is PageOne!</Text>
    )
  }
}

非常简单的教程如何使用它:

https://github.com/aksonov/react-native-router-flux/blob/master/docs/MINI_TUTORIAL.md

希望这就是您要找的:)

关于javascript - 问 - React Native App 介绍中的路由,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39179913/

相关文章:

javascript - jquery中如何将字符串转换为xml对象

javascript - 如何使用图像的特定索引打开 fancybox

iphone - 更改 Storyboard 中的开始 View

javascript - 在 React Native 中创建一个简单的标签格式化程序

javascript - 为 React-Native 应用开 Jest 测试 Animated.View

javascript - 如何在 html 页面上找到涉及 PDF 的链接,然后在链接的前面附加绝对路径?

javascript - d3.js - 更新 GeoJSON 元素

ios - 如何根据屏幕宽度动态设置具有不同字符串长度的多个按钮?

iphone - 如何使用 iOS 和 Objective-C/Xcode 加速 TDD 流程

node.js - react native : Debug and Release builds don't work the same