项目不难,就是文件摆放位置跟别的不一样

https://github.com/chenji336/github_popular

  1. //定义入口是app.js
  2. ///** @format */
  3. import {AppRegistry} from 'react-native';
  4. import App from './App';
  5. import {name as appName} from './app.json';
  6. AppRegistry.registerComponent(appName, () => App);
  1. //app.js
  2. //app.js对应的是page/setup
  3. /**
  4. * Sample React Native App
  5. * https://github.com/facebook/react-native
  6. *
  7. * @format
  8. * @flow
  9. */
  10. import React, { Component } from 'react';
  11. import setup from './js/page/setup'
  12. export default setup;
  1. //github_popular/js/page/setup.js
  2. import React, { Component } from 'react'
  3. import { SafeAreaView } from 'react-native'
  4. import { Navigator } from 'react-native-deprecated-custom-components'
  5. import WelcomePage from './WelcomePage'
  6. import { YellowBox } from 'react-native';
  7. YellowBox.ignoreWarnings(['Remote debugger']); // 忽略黄色提醒
  8. class Root extends Component {
  9. renderScene(route, navigator) {
  10. let Component = route.component;
  11. return <Component {...route.params} navigator={navigator} />
  12. }
  13. render() {
  14. return <Navigator
  15. initialRoute={{ component: WelcomePage }}
  16. renderScene={(route, navigator) => this.renderScene(route, navigator)}
  17. />
  18. }
  19. }
  20. function setup() {
  21. //进行一些初始化配置
  22. return (
  23. <SafeAreaView style={{flex:1}}>
  24. <Root />
  25. </SafeAreaView>
  26. );
  27. }
  28. // module.exports = setup; // 这里不能setup(),因为AppRegistry.registerComponent(appName, () => App);的App应该是function或则class
  29. export default setup;
  1. //github_popular/js/page/WelcomePage.js
  2. //启动页那个
  3. //在welcomePage中定义的是跳转到HomePage
  4. import React, { Component } from 'react';
  5. import {
  6. View,
  7. StyleSheet,
  8. Text,
  9. } from 'react-native'
  10. import NavigationBar from '../common/NavigationBar'
  11. import HomePage from './HomePage'
  12. export default class WelcomePage extends Component {
  13. constructor(props) {
  14. super(props);
  15. }
  16. componentDidMount() {
  17. this.timer = setTimeout(() => {
  18. this.props.navigator.resetTo({
  19. component: HomePage,
  20. });
  21. }, 0);
  22. }
  23. componentWillUnmount() {
  24. this.timer && clearTimeout(this.timer);
  25. }
  26. render() {
  27. return (
  28. <View style={styles.container}>
  29. <NavigationBar
  30. title='欢迎'
  31. style={{ backgroundColor: '#6495ED' }}
  32. />
  33. <Text style={styles.tips}>欢迎</Text>
  34. </View>)
  35. }
  36. }
  37. const styles = StyleSheet.create({
  38. container: {
  39. flex: 1,
  40. },
  41. tips: {
  42. fontSize: 29
  43. }
  44. })

  1. //接下来是HomePage页面
  2. //github_popular/js/page/HomePage.js
  3. //定义的是下面的切换页面
  4. import React, { Component } from 'react';
  5. import {
  6. StyleSheet,
  7. Text,
  8. Image,
  9. View
  10. } from 'react-native';
  11. import TabNavigator from 'react-native-tab-navigator';
  12. import PopularPage from './PopularPage';
  13. export default class HomePage extends Component {
  14. constructor(props) {
  15. super(props);
  16. this.state = {
  17. selectedTab: 'tb_popular',
  18. }
  19. }
  20. render() {
  21. return (
  22. <View style={styles.container}>
  23. <TabNavigator>
  24. <TabNavigator.Item
  25. selected={this.state.selectedTab === 'tb_popular'}
  26. selectedTitleStyle={{ color: 'red' }}
  27. title="最热"
  28. renderIcon={() => <Image style={styles.image} source={require('../../res/images/ic_polular.png')} />}
  29. renderSelectedIcon={() => <Image style={[styles.image, { tintColor: 'red' }]} source={require('../../res/images/ic_polular.png')} />}
  30. onPress={() => this.setState({ selectedTab: 'tb_popular' })}>
  31. <PopularPage></PopularPage>
  32. </TabNavigator.Item>
  33. <TabNavigator.Item
  34. selected={this.state.selectedTab === 'tb_trending'}
  35. title="趋势"
  36. selectedTitleStyle={{ color: 'yellow' }}
  37. renderIcon={() => <Image style={styles.image} source={require('../../res/images/ic_trending.png')} />}
  38. renderSelectedIcon={() => <Image style={[styles.image, { tintColor: 'yellow' }]} source={require('../../res/images/ic_trending.png')} />}
  39. onPress={() => this.setState({ selectedTab: 'tb_trending' })}>
  40. <View style={{ backgroundColor: 'yellow', flex: 1 }}></View>
  41. </TabNavigator.Item>
  42. <TabNavigator.Item
  43. selected={this.state.selectedTab === 'tb_favorite'}
  44. title="收藏"
  45. selectedTitleStyle={{ color: 'green' }}
  46. renderIcon={() => <Image style={styles.image} source={require('../../res/images/ic_favorite.png')} />}
  47. renderSelectedIcon={() => <Image style={[styles.image, { tintColor: 'green' }]} source={require('../../res/images/ic_favorite.png')} />}
  48. onPress={() => this.setState({ selectedTab: 'tb_favorite' })}>
  49. <View style={{ backgroundColor: 'green', flex: 1 }}></View>
  50. </TabNavigator.Item>
  51. <TabNavigator.Item
  52. selected={this.state.selectedTab === 'tb_my'}
  53. title="我的"
  54. selectedTitleStyle={{ color: 'blue' }}
  55. renderIcon={() => <Image style={styles.image} source={require('../../res/images/ic_my.png')} />}
  56. renderSelectedIcon={() => <Image style={[styles.image, { tintColor: 'blue' }]} source={require('../../res/images/ic_my.png')} />}
  57. onPress={() => this.setState({ selectedTab: 'tb_my' })}>
  58. <View style={{ backgroundColor: 'blue', flex: 1 }}></View>
  59. </TabNavigator.Item>
  60. </TabNavigator>
  61. </View>
  62. );
  63. }
  64. }
  65. const styles = StyleSheet.create({
  66. container: {
  67. flex: 1,
  68. },
  69. image: {
  70. height: 22,
  71. width: 22,
  72. }
  73. });
  1. //github_popular/js/page/PopularPage.js
  2. //定义了与后端请求数据的方法
  3. import React, { Component } from 'react';
  4. import {
  5. StyleSheet,
  6. Text,
  7. Image,
  8. View,
  9. TextInput
  10. } from 'react-native';
  11. import NavigationBar from '../common/NavigationBar'
  12. import DataRepository from '../expand/dao/DataRepository'
  13. const URL = 'https://api.github.com/search/repositories?q=';
  14. const QUERY_STR = '&sort=stars';
  15. export default class PopularPage extends Component {
  16. constructor(props) {
  17. super(props);
  18. this.dataRespository = new DataRepository();
  19. this.state = {
  20. result: '',
  21. }
  22. }
  23. loadData() {
  24. let url = URL + this.key + QUERY_STR;
  25. this.dataRespository
  26. .fetchNetRepository(url)
  27. .then(result => {
  28. this.setState({
  29. result: JSON.stringify(result),
  30. });
  31. }).catch(error => {
  32. console.log(error);
  33. })
  34. }
  35. render() {
  36. return <View style={styles.container}>
  37. <NavigationBar
  38. title={'最热'}
  39. />
  40. <Text
  41. style={styles.tips}
  42. onPress={() => this.loadData()}
  43. >加载数据</Text>
  44. <TextInput style={{ height: 40, borderWidth: 1 }}
  45. onChangeText={(text) => {
  46. this.key = text;
  47. }}
  48. />
  49. <Text style={{ height: 800 }}>{this.state.result}</Text>
  50. </View>
  51. }
  52. }
  53. const styles = StyleSheet.create({
  54. container: {
  55. flex: 1,
  56. },
  57. tips: {
  58. fontSize: 20
  59. }
  60. })
  1. //封装获取数据的方法
  2. //github_popular/js/expand/dao/DataRepository.js
  3. export default class DataRepository {
  4. fetchNetRepository(url) {
  5. return new Promise((resolve, reject) => {
  6. fetch(url)
  7. .then(response => response.json())
  8. .then(result => resolve(result))
  9. .catch(err => reject(err))
  10. })
  11. }
  12. }
  1. //github_popular/js/common/NavigationBar.js
  2. //切换的navigationBar
  3. import React, { Component } from 'react'
  4. import { Text, View, StyleSheet, StatusBar, Platform, } from 'react-native'
  5. import PropTypes from 'prop-types';
  6. const NAV_BAR_HEIGHT_IOS = 44;
  7. const NAV_BAR_HEGIHT_ANDROID = 50;
  8. const STATUS_BAR_HEIGHT = 20;
  9. const StatusBarShape = {
  10. barStyle: PropTypes.oneOf(['light-content', 'dark-content', 'default']),
  11. hidden: PropTypes.bool,
  12. backgroundColor: PropTypes.string,
  13. };
  14. export default class NavigationBar extends Component {
  15. static propTypes = {
  16. // style: PropTypes.style,
  17. hidden: PropTypes.bool,
  18. title: PropTypes.string,
  19. titleView: PropTypes.element,
  20. leftButton: PropTypes.element,
  21. rightButton: PropTypes.element,
  22. statusBar: PropTypes.shape(StatusBarShape)
  23. }
  24. static defaultProps = {
  25. statusBar: {
  26. hidden: false,
  27. barStyle: 'default',
  28. // backgroundColor: 'red' // 对ios不起作用
  29. }
  30. }
  31. constructor(props) {
  32. super(props);
  33. }
  34. render() {
  35. const statusBar = !this.props.statusBar.hidden ? (
  36. <View>
  37. <StatusBar {...this.props.statusBar}></StatusBar>
  38. </View>
  39. ) : null;
  40. const titleView = this.props.titleView ?
  41. this.props.titleView
  42. : <Text ellipsizeMode='head' numberOfLines={1}>{this.props.title}</Text>;
  43. const content = <View style={[styles.navBar, this.props.style]}>
  44. {this.props.leftButton}
  45. <View style={styles.navBarTitleContainer}>
  46. {titleView}
  47. </View>
  48. {this.props.rightButton}
  49. </View>
  50. return (
  51. <View>
  52. {statusBar}
  53. {content}
  54. </View>
  55. )
  56. }
  57. }
  58. const styles = StyleSheet.create({
  59. container: {
  60. backgroundColor: 'gray',
  61. },
  62. navBar: {
  63. flexDirection: 'row',
  64. justifyContent: 'space-between',
  65. alignItems: 'center',
  66. height: Platform.OS === 'ios' ? NAV_BAR_HEIGHT_IOS : NAV_BAR_HEGIHT_ANDROID
  67. },
  68. statusBar: {
  69. height: Platform.OS === 'ios' ? STATUS_BAR_HEIGHT : 0,
  70. },
  71. navBarTitleContainer: {
  72. position: 'absolute',
  73. justifyContent: 'center',
  74. alignItems: 'center',
  75. left: 40,
  76. right: 40,
  77. top: 0,
  78. bottom: 0
  79. }
  80. })

【水滴石穿】github_popular的更多相关文章

  1. iOS 开发笔记 -- 各种细枝末节的知识(水滴石穿)

    在此总结整理,遇到的各种的小问题: 1.通过从字典(数组)中取出的NSString的length==0 作为if的判断条件导致的carsh: 由于在字典中通过Key取出值之后直接做了length相关操 ...

  2. 【水滴石穿】react-native-book

    先推荐一个学习的地址:https://ke.qq.com/webcourse/index.html#cid=203313&term_id=100240778&taid=12778558 ...

  3. 【水滴石穿】rnTest

    其实就是一个小的demo,不过代码分的挺精巧的 先放地址:https://github.com/linchengzzz/rnTest 来看看效果 确实没有什么可以说的,不过代码部分还行 先入口文件 / ...

  4. 【水滴石穿】rn_statusbar

    先放项目地址https://github.com/hezhii/rn_statusbar 来看一下效果 咩有感觉很怎么样,看代码 根入口文件 //index.js //看代码我们知道入口是app.js ...

  5. 【水滴石穿】react-native-ble-demo

    项目的话,是想打开蓝牙,然后连接设备 点击已经连接的设备,我们会看到一些设备 不过我这边在开启蓝牙的时候报错了 先放作者的项目地址: https://github.com/hezhii/react-n ...

  6. 【水滴石穿】ReactNative-Redux-Thunk

    老实说,运行出来的项目让人失望,毕竟我想看各种有趣的demo啊- 先放上源码地址:https://github.com/ludejun/ReactNative-Redux-Thunk 我们来一起看看代 ...

  7. 【水滴石穿】mobx-todos

    我觉得代码在有些程序员手里,就好像是画笔,可以创造很多东西 不要觉得创意少就叫没有创意,每天进步一点点,世界更美好 首先源码地址为:https://github.com/byk04712/mobx-t ...

  8. 【水滴石穿】ReactNativeMobxFrame

    项目地址如下:https://github.com/FTD-ZF/ReactNativeMobxFrame 应该可以说的是,项目也只是一个花架子,不过底部的tab稍微改变了 我们一起来看代码 //in ...

  9. 【水滴石穿】react-native-aze

    说个题外话,早上打开电脑的时候,电脑变成彩色的了,锅是我曾经安装的一个chrome扩展,没有经过我的同意开启了 (也许是昨天迷迷糊糊开启了) 上午运行项目都不成功,还以为被黑客攻击了---然后下午就排 ...

随机推荐

  1. ip-up脚本参数

    pppoe连接建立后,系统自动调用/etc/ppp/ip-up脚本. 其参数如下面文件所示,第4个参数是系统获得的动态ip.#!/bin/bash## Script which handles the ...

  2. windows 遍历目录下的所有文件 FindFirstFile FindNextFile

    Windows下遍历文件时用到的就是FindFirstFile 和FindNextFile 首先看一下定义: HANDLE FindFirstFile( LPCTSTR lpFileName, // ...

  3. HZOI20190903模拟36 字符,蛋糕,游戏

    题面:https://www.cnblogs.com/Juve/articles/11461528.html A:字符 暴力模拟一下,细节很多,但是暴力思路都不大一样 先枚举循环节长度,然后处理一个b ...

  4. 90 k数和 II

    原题网址:https://www.lintcode.com/problem/k-sum-ii/description 描述 Given n unique integers, number k (1&l ...

  5. linux命令行操作mysql数据库明细

    连接数据库==> mysql -uroot -p 输入root密码 进入mysql操作后 下面的命令不要忘了最后结尾的; 1.选择数据库命令: use <数据库名> 2.查看表的引擎 ...

  6. IO流14 --- 打印流的使用 --- 技术搬运工(尚硅谷)

    PrintStream 字节打印流PrintWriter 字符打印流 @Test public void test9() throws Exception { FileOutputStream fos ...

  7. Tensorflow技巧

    1.尽量控制图片大小在1024以内,不然显存会爆炸. 2.尽量使用多GPU并行工作,训练下降速度快. 3.当需要被检测的单张图片里物体太多时,记得修改Region_proposals的个数 4.测试的 ...

  8. 跟我一起做一个vue的小项目(十一)

    接下来我们进行的是详情页动态路由及banner布局 先看页面的效果 下面是代码部分 <template> <div> <div class="banner&qu ...

  9. xshell评,xftp估过期解决办法

    去官网 xshell:https://www.netsarang.com/download/down_form.html?code=522 xftp:https://www.netsarang.com ...

  10. SQL Server分页查询进化史

    分页查询一直SQL Server的一个硬伤,就是是经过一些进化,比起MySql的limit还是有一些差距. 一.条件过滤(适应用所有版本) 条件过滤的方法有很多,而思路就是利用集合的差集选择出目标集合 ...