zoukankan      html  css  js  c++  java
  • 【水滴石穿】bstmy-blend-app

    这个项目是一个简单的底部导航切换页面
    项目的地址为:https://github.com/Bstmy/bstmy-blend-app
    先看效果

    点击首页是首页面,点击个人中心是个人中心页面
    先看代码

    //index.js
    //引用的是根app.js
    import {AppRegistry} from 'react-native';
    import App from './app/App';
    import {name as appName} from './app.json';
    AppRegistry.registerComponent(appName, () => App);
    
    //app/App.js
    //这个里面不仅有防止闪屏的,还有倒计时为3的启动页,还有定义了首页
    import React, { Component } from 'react';
    //闪屏
    import SplashScreen from 'react-native-splash-screen';
    //导航
    import {createAppContainer, createStackNavigator} from 'react-navigation';
    
    //显示首页
    import Home from "./Home";
    //这个是很好看的启动页很美腻
    import GuideView from "./guide/GuideView";
    const RootStack = createStackNavigator(
        {
            homes: Home,
            guideView: GuideView
        },
        {
            initialRouteName: 'guideView'   ,
            defaultNavigationOptions: {
                headerStyle: {
                    backgroundColor: '#f4511e',
                    height:0,
                },
                headerTintColor: '#fff',
                headerTitleStyle: {
                    fontWeight: 'bold',
                },
            },
        }
    );
    const AppContainer = createAppContainer(RootStack);
    //定义首页
    //渲染AppConta
    export default class App extends Component {
    
        constructor(props) {
            super(props);
            SplashScreen.hide(); // 关闭启动屏幕
        }
    
        render() {
            return (
                <AppContainer />
            );
        }
    
    }
    
    //app/guide/GuideView.js
    //配置的启动页
    import React, {Component} from 'react';
    import {
        Image,
        StyleSheet,
        View,
        Text
    } from 'react-native';
    import Swiper from 'react-native-swiper';
    import AutoSize from '../utils/AutoSize';
    class GuideView extends Component {
        constructor() {
            super();
            this.state = { invertedTime: 5 };
        }
        componentDidMount() {
            this.timer1=setInterval(() => {
                this.setState(previousState => {
                    return {invertedTime: (previousState.invertedTime-1)};
                })
                console.log("启动倒计时"+this.state.invertedTime );
                if(this.state.invertedTime == 0){
                    this.openHomePage();
                    clearInterval(this.timer1)
                }
            } ,1000);
        }
        openHomePage(){
            this.props.navigation.navigate('homes');
        }
    
        //卸载计时器
        componentWillUnmount() {
            this.timer1 && clearInterval(this.timer1);
        }
        render() {
            return (
                <View style={styles.container}>
                    <Text style={styles.next} onPress={this.openHomePage.bind(this)}>{this.state.invertedTime}</Text>
                    <Swiper style={styles.wrapper}
                        showsButtons={false}       //为false时不显示控制按钮
                        paginationStyle={{      //小圆点位置
                            bottom: 30
                        }}
                        loop={true}        //如果设置为false,那么滑动到最后一张时,再次滑动将不会滑到第一张图片。
                        autoplay={true}          //自动轮播
                        autoplayTimeout={3}      //每隔3秒切换
                        >
                        <Image style={styles.image} source={require('../img/guide/geoude2.jpg')}/>
                        <Image style={styles.image} source={require('../img/guide/geoude3.jpg')}/>
                        <Image style={styles.image} source={require('../img/guide/geoude1.jpg')}/>
                    </Swiper>
                </View>
            );
        }
    };
    
    let styles = StyleSheet.create({
        container: {
            flex: 1,//必写
            flexDirection: 'column',
        },
        image: {
            AutoSize.size.width,//等于width
            height:AutoSize.size.height,
        },
        next:{
             30,
            height: 30,
            borderRadius:15,
            fontSize:15,
            textAlign:"center",
            textAlignVertical: 'center',
            backgroundColor: "#D4237A",
            zIndex:1,
            position: 'absolute',
            color:"#fff",
            right: 20,
            top: 20,
        }
    });
    
    export default GuideView;
    
    //app/utils/AutoSize.js
    //这个里面进行的就是屏幕适配
    import React from 'react';
    import Dimensions from 'Dimensions';
    
    const AutoSize = {
        size: {
             Dimensions.get('window').width,
            height: Dimensions.get('window').height
        },
    };
    
    export default AutoSize;
    
    //app/route/RootStack.js
    //定义的是首页
    import { createStackNavigator } from 'react-navigation';
    import Home from '../Home'
    import GuideView from '../guide/GuideView'
    export const RootStack = createStackNavigator(
        {
            home: Home,
            guideView: GuideView,
        },
        {
            initialRouteName: 'guideView',
            defaultNavigationOptions: {
                headerStyle: {
                    backgroundColor: '#f4511e',
                },
                headerTintColor: '#fff',
                headerTitleStyle: {
                    fontWeight: 'bold',
                },
            },
        }
    );
    
    //和index页面类似,不过具体怎么控制的?
    //app/pages/User.js
    import React, { Component } from 'react';
    
    import {
        View,
        Text
    } from 'react-native';
    
    class User extends Component {
    
        render() {
            return (
                <View>
    
                    <Text>
                        我是用户
                    </Text>
    
                </View>
            );
        }
    }
    
    export default User;
    

    上面有一点点的不理解
    不知道是什么控制的切换的页面的,因为那个是同时引用的
    不过这个项目我喜欢~~哭唧唧,在这个水平这里~~

  • 相关阅读:
    07 oracle 非归档模式 inactive/active/current redo log损坏的恢复
    07 归档模式 Active redo log丢失或损坏的恢复
    07 oracle 归档模式 inactive/current redo log损坏修复--以及错误ORA-00600: internal error code, arguments: [2663], [0], [9710724], [0], [9711142], [], [], [], [], [], [], []
    rac的一次问题 ORA-01565: error in identifying file '+DATA/bol/spfilebol.ora'
    44 答疑(三)--join的写法/Simple nested loop join的性能问题/Distinct和group by的性能/备库自增主键问题
    43 使用分区表
    5 centos 6.10 三节点安装apache hadoop 2.9.1
    java -jar参数携带问题
    解决Spring Boot集成Shiro,配置类使用Autowired无法注入Bean问题
    @Autowired注解与@Qualifier注解搭配使用----解决多实现选择注入问题
  • 原文地址:https://www.cnblogs.com/smart-girl/p/10882254.html
Copyright © 2011-2022 走看看