项目不难,就是文件摆放位置跟别的不一样
https://github.com/chenji336/github_popular

//定义入口是app.js
///** @format */import {AppRegistry} from 'react-native';
import App from './App';
import {name as appName} from './app.json';AppRegistry.registerComponent(appName, () => App);
//app.js
//app.js对应的是page/setup
/*** Sample React Native App* https://github.com/facebook/react-native** @format* @flow*/import React, { Component } from 'react';
import setup from './js/page/setup'export default setup;
//github_popular/js/page/setup.js
import React, { Component } from 'react'
import { SafeAreaView } from 'react-native'
import { Navigator } from 'react-native-deprecated-custom-components'
import WelcomePage from './WelcomePage'import { YellowBox } from 'react-native';
YellowBox.ignoreWarnings(['Remote debugger']); // 忽略黄色提醒class Root extends Component {renderScene(route, navigator) {let Component = route.component;return <Component {...route.params} navigator={navigator} />}render() {return <NavigatorinitialRoute={{ component: WelcomePage }}renderScene={(route, navigator) => this.renderScene(route, navigator)}/>}
}
function setup() {//进行一些初始化配置return (<SafeAreaView style={{flex:1}}><Root /></SafeAreaView>);
}
// module.exports = setup; // 这里不能setup(),因为AppRegistry.registerComponent(appName, () => App);的App应该是function或则class
export default setup;
//github_popular/js/page/WelcomePage.js
//启动页那个
//在welcomePage中定义的是跳转到HomePage
import React, { Component } from 'react';
import {View,StyleSheet,Text,
} from 'react-native'
import NavigationBar from '../common/NavigationBar'
import HomePage from './HomePage'
export default class WelcomePage extends Component {constructor(props) {super(props);}componentDidMount() {this.timer = setTimeout(() => {this.props.navigator.resetTo({component: HomePage,});}, 0);}componentWillUnmount() {this.timer && clearTimeout(this.timer);}render() {return (<View style={styles.container}><NavigationBartitle='欢迎'style={{ backgroundColor: '#6495ED' }}/><Text style={styles.tips}>欢迎</Text></View>)}
}
const styles = StyleSheet.create({container: {flex: 1,},tips: {fontSize: 29}
})

//接下来是HomePage页面
//github_popular/js/page/HomePage.js
//定义的是下面的切换页面
import React, { Component } from 'react';
import {StyleSheet,Text,Image,View
} from 'react-native';
import TabNavigator from 'react-native-tab-navigator';
import PopularPage from './PopularPage';
export default class HomePage extends Component {constructor(props) {super(props);this.state = {selectedTab: 'tb_popular',}}render() {return (<View style={styles.container}><TabNavigator><TabNavigator.Itemselected={this.state.selectedTab === 'tb_popular'}selectedTitleStyle={{ color: 'red' }}title="最热"renderIcon={() => <Image style={styles.image} source={require('../../res/images/ic_polular.png')} />}renderSelectedIcon={() => <Image style={[styles.image, { tintColor: 'red' }]} source={require('../../res/images/ic_polular.png')} />}onPress={() => this.setState({ selectedTab: 'tb_popular' })}><PopularPage></PopularPage></TabNavigator.Item><TabNavigator.Itemselected={this.state.selectedTab === 'tb_trending'}title="趋势"selectedTitleStyle={{ color: 'yellow' }}renderIcon={() => <Image style={styles.image} source={require('../../res/images/ic_trending.png')} />}renderSelectedIcon={() => <Image style={[styles.image, { tintColor: 'yellow' }]} source={require('../../res/images/ic_trending.png')} />}onPress={() => this.setState({ selectedTab: 'tb_trending' })}><View style={{ backgroundColor: 'yellow', flex: 1 }}></View></TabNavigator.Item><TabNavigator.Itemselected={this.state.selectedTab === 'tb_favorite'}title="收藏"selectedTitleStyle={{ color: 'green' }}renderIcon={() => <Image style={styles.image} source={require('../../res/images/ic_favorite.png')} />}renderSelectedIcon={() => <Image style={[styles.image, { tintColor: 'green' }]} source={require('../../res/images/ic_favorite.png')} />}onPress={() => this.setState({ selectedTab: 'tb_favorite' })}><View style={{ backgroundColor: 'green', flex: 1 }}></View></TabNavigator.Item><TabNavigator.Itemselected={this.state.selectedTab === 'tb_my'}title="我的"selectedTitleStyle={{ color: 'blue' }}renderIcon={() => <Image style={styles.image} source={require('../../res/images/ic_my.png')} />}renderSelectedIcon={() => <Image style={[styles.image, { tintColor: 'blue' }]} source={require('../../res/images/ic_my.png')} />}onPress={() => this.setState({ selectedTab: 'tb_my' })}><View style={{ backgroundColor: 'blue', flex: 1 }}></View></TabNavigator.Item></TabNavigator></View>);}
}const styles = StyleSheet.create({container: {flex: 1,},image: {height: 22,width: 22,}
});
//github_popular/js/page/PopularPage.js
//定义了与后端请求数据的方法
import React, { Component } from 'react';
import {StyleSheet,Text,Image,View,TextInput
} from 'react-native';
import NavigationBar from '../common/NavigationBar'
import DataRepository from '../expand/dao/DataRepository'
const URL = 'https://api.github.com/search/repositories?q=';
const QUERY_STR = '&sort=stars';
export default class PopularPage extends Component {constructor(props) {super(props);this.dataRespository = new DataRepository();this.state = {result: '',}}loadData() {let url = URL + this.key + QUERY_STR;this.dataRespository.fetchNetRepository(url).then(result => {this.setState({result: JSON.stringify(result),});}).catch(error => {console.log(error);})}render() {return <View style={styles.container}><NavigationBartitle={'最热'}/><Textstyle={styles.tips}onPress={() => this.loadData()}>加载数据</Text><TextInput style={{ height: 40, borderWidth: 1 }}onChangeText={(text) => {this.key = text;}}/><Text style={{ height: 800 }}>{this.state.result}</Text></View>}
}
const styles = StyleSheet.create({container: {flex: 1,},tips: {fontSize: 20}
})
//封装获取数据的方法
//github_popular/js/expand/dao/DataRepository.js
export default class DataRepository {fetchNetRepository(url) {return new Promise((resolve, reject) => {fetch(url).then(response => response.json()).then(result => resolve(result)).catch(err => reject(err))})}
}
//github_popular/js/common/NavigationBar.js
//切换的navigationBar
import React, { Component } from 'react'
import { Text, View, StyleSheet, StatusBar, Platform, } from 'react-native'
import PropTypes from 'prop-types';const NAV_BAR_HEIGHT_IOS = 44;
const NAV_BAR_HEGIHT_ANDROID = 50;
const STATUS_BAR_HEIGHT = 20;const StatusBarShape = {barStyle: PropTypes.oneOf(['light-content', 'dark-content', 'default']),hidden: PropTypes.bool,backgroundColor: PropTypes.string,
};export default class NavigationBar extends Component {static propTypes = {// style: PropTypes.style,hidden: PropTypes.bool,title: PropTypes.string,titleView: PropTypes.element,leftButton: PropTypes.element,rightButton: PropTypes.element,statusBar: PropTypes.shape(StatusBarShape)}static defaultProps = {statusBar: {hidden: false,barStyle: 'default',// backgroundColor: 'red' // 对ios不起作用}}constructor(props) {super(props);}render() {const statusBar = !this.props.statusBar.hidden ? (<View><StatusBar {...this.props.statusBar}></StatusBar></View>) : null;const titleView = this.props.titleView ?this.props.titleView: <Text ellipsizeMode='head' numberOfLines={1}>{this.props.title}</Text>;const content = <View style={[styles.navBar, this.props.style]}>{this.props.leftButton}<View style={styles.navBarTitleContainer}>{titleView}</View>{this.props.rightButton}</View>return (<View>{statusBar}{content}</View>)}
}const styles = StyleSheet.create({container: {backgroundColor: 'gray',},navBar: {flexDirection: 'row',justifyContent: 'space-between',alignItems: 'center',height: Platform.OS === 'ios' ? NAV_BAR_HEIGHT_IOS : NAV_BAR_HEGIHT_ANDROID},statusBar: {height: Platform.OS === 'ios' ? STATUS_BAR_HEIGHT : 0,},navBarTitleContainer: {position: 'absolute',justifyContent: 'center',alignItems: 'center',left: 40,right: 40,top: 0,bottom: 0}
})

转载于:https://www.cnblogs.com/smart-girl/p/10899372.html

【水滴石穿】github_popular相关推荐

  1. 做人晶莹剔透,做事水滴石穿

    看了余世维的讲座,在最后的闭幕中,出现了这样的文字:做人晶莹剔透,做事水滴石穿.晶莹剔透意味着诚信光明,水滴石穿意味着用心坚持.让我心一惊,真是说得太对了.我要用他来鼓舞激励自己. 现在很多人都很虚伪 ...

  2. Redis 水滴石穿之(六)哨兵

    Redis-水滴石穿之(六)哨兵 目录 Redis-水滴石穿之(六)哨兵 一.概述 二.哨兵应用 2.1.主从及哨兵配置 2.2.依次启动主.从.哨兵 2.3.主从节点验证 2.4.故障迁移演示 2. ...

  3. 水滴石穿、坚持不懈,必能有所精进

    在跟随这门课程学习的过程中,我增长了很多大数据相关的知识,对于大数据技术和相关开源组件,也有了更深的了解.今天正好可以借着这个机会,来记录下自己的一点心得体会,也跟你分享一下我的学习思路,咱们一起聊一 ...

  4. 2.4 找准位置,水滴石穿

            考试时的方法多数不是"灵机一动"现场创造出来的,而是平时刻苦训练中积累出来的. 俗话说得好,"水滴石穿",但"水滴未必石穿" ...

  5. Redis 水滴石穿之(四)持久化

    Redis 水滴石穿之(四)持久化 目录 Redis 水滴石穿之(四)持久化 一.概述 二.RDB 1.RDB快照触发时机 1.1 手动触发 (save & bgsave) 1.2 自动触发 ...

  6. 不会-Redis 水滴石穿之(七)集群

    Redis 水滴石穿之(七)集群 目录 Redis 水滴石穿之(七)集群 一.概述 二.集群搭建 2.1.手动搭建集群 1.修改配置文件 2.启动节点 3.节点握手 4.分配槽 5.指定主从关系 2. ...

  7. 期货开户水滴石穿知行合一

    上千年来,人生价值一直都在改变,唯一没有改变的就是价值本身的规律.如果从另一个角度去观察,或许会有另外一番心境,有句老话叫做后生可畏,也许后生并不可畏,真正让人可畏可敬的或许是代表一个时代的思想和精神 ...

  8. 2022-1-14持之以恒,水滴石穿

    1.读到曾文正公修身之难皆因无恒,刚过30的我深有体会,回想往事从幼时读书学习开始总是3分钟热度,学习总浮于表面,老师布置的作业草草了事,出社会参加工作后书倒是买了一大堆,每本书总是翻完几页又想去读其 ...

  9. 水滴石穿oracle之脚本安装

    水滴石穿oracle之脚本安装 上一篇文章带领大家在redhat5.5上一步一步安装了oracle10g,并且详细讲解了每一步操作,图文并茂相信可以帮到一些有需要朋友! 成功动手搭建过一次的朋友们有没 ...

最新文章

  1. mysql 定时计划_MYSQL定时任务
  2. iOS - UISearchController
  3. 【奖】《密码信》破解者们,快来领奖啦!
  4. SQLLite (一)基本介绍
  5. 实习日志_实习律师实习日志第十八篇(连载30篇)
  6. AMD平台下在Windows虚拟机中安装Mac10.8.3的注意事项
  7. 线索二叉树算法 - 草根编程网
  8. IDEA 设置背景颜色为黑色
  9. Android四大组件——BroadcastReceiver详解
  10. SPI协议学习Cubmx——读写Flash W25Q64
  11. 如何修改pdf文件内容
  12. CoAP协议学习笔记 3.2 CoAP协议翻译 DTLS加密
  13. 手游传奇架设教程_传奇手游战神引擎架设教程
  14. 北京内推 | Hulu机器学习应用平台团队招聘推荐大数据方向暑期实习生
  15. MATLAB指纹识别文献综述
  16. 给我一段《巫师3》的核心代码
  17. wordpress插件_您应该知道的2018年10个高级WordPress插件
  18. 「游戏开发」游戏服务器端开发的一些经验
  19. Python练习题——coffee
  20. SNIP的升级版SNIPER(效果比Mosaic更佳)

热门文章

  1. python实现调用搜狗号码通返回查询内容
  2. 计算机科学与技术实验题代做,计算机科学与技术专业代写(本科)毕业设计(论文)要求...
  3. 清华申请退学博士作品:完全用Linux工作
  4. C语言编译执行的全过程
  5. BugZhu抽抽抽!!(已知三角形三点坐标,求外接圆半径及三角面积)
  6. Kubernetes 150 个操作练习 (中)
  7. 【原创】连连看Flex版设计与实现
  8. 为你的网页添加深色模式
  9. PySpark TopK 问题(分组TopK)(4)
  10. 开启火狐浏览器的账号密码导入功能