- 内容简介
- 译者序
- 前言
- 第 1 章 安装配置新项目
- 第 2 章 Flexbox 布局介绍
- 第 3 章 用 React Native 开发一个应用
- 第 4 章 在 React Native 中使用导航
- 第 5 章 动画和滑动菜单
- 第 6 章 用 React Native 绘制 Canvas
- 第 7 章 使用 React Native 播放音频
- 第 8 章 你的第一个自定义视图
- 第 9 章 Flux 介绍
- 第 10 章 处理复杂的应用程序状态
- 第 11 章 使用 Node 来实现服务端 API
- 第 12 章 在 React Native 中使用文件上传
- 第 13 章 理解 JavaScript Promise
- 第 14 章 fetch 简介
- 第 15 章 在 iOS 中使用 SQLite
- 第 16 章 集成 Google Admob
- 第 17 章 React Native 组件国际化
- 附录 A React.js 快速介绍
- 附录 B Objective-C Primer
- 附录 C webpack 入门
文章来源于网络收集而来,版权归原创者所有,如有侵权请及时联系!
最终代码
修改完最终的样式后,我们就算完成 GithubFinder 应用了!我们最终的代码看起来是这样的:
/** * Sample React Native App * https://github.com/facebook/react-native */ 'use strict'; var React = require('react-native'); var BASE_URL = "https://api.github.com/search/repositories? q="; var { AppRegistry, Image, ListView, StyleSheet, Text, TextInput, View, } = React; var GithubFinder = React.createClass({ getInitialState: function() { return { dataSource: new ListView.DataSource({ rowHasChanged: (row1, row2) => row1 ! == row2, }), }; }, render: function() { if (this.state.dataSource.getRowCount() === 0) { console.log("YES"); } var content = this.state.dataSource.getRowCount() === 0 ? <Text style={styles.blanktext}> Please enter a search term to see results. </Text> : <ListView ref="listview" dataSource={this.state.dataSource} renderRow={this.renderRow} automaticallyAdjustContentInsets={false} keyboardDismissMode="onDrag" keyboardShouldPersistTaps={true} showsVerticalScrollIndicator={false}/>; return ( <View style={styles.container}> <TextInput autoCapitalize="none" autoCorrect={false} placeholder="Search for a project..." style={styles.searchBarInput} onEndEditing={this.onSearchChange}/> {content} </View> ); }, onSearchChange: function(event: Object) { var searchTerm = event.nativeEvent.text.toLowerCase(); var queryURL = BASE_URL + encodeURIComponent(searchTerm); fetch(queryURL) .then((response) => response.json()) .then((responseData) => { if (responseData.items) { this.setState({ dataSource: this.state.dataSource. cloneWithRows(responseData.items), }); } }).done(); }, renderRow: function(repo: Object) { return ( <View> <View style={styles.row}> <Image source={{uri: repo.owner.avatar_url}} style={styles.profpic}/> <View style={styles.textcontainer}> <Text style={styles.title}>{repo.name}</ Text> <Text style={styles.subtitle}>{repo.owner. login}</Text> </View> </View> <View style={styles.cellBorder} /> </View> ); }, }); var styles = StyleSheet.create({ container: { flex: 1, backgroundColor: 'white', }, searchBarInput: { marginTop: 30, padding: 5, fontSize: 15, height: 30, backgroundColor: '#EAEAEA', }, row: { alignItems: 'center', backgroundColor: 'white', flexDirection: 'row', padding: 5, }, cellBorder: { backgroundColor: 'rgba(0, 0, 0, 0.1)', height: 1, marginLeft: 4, }, profpic: { width: 50, height: 50, }, title: { fontSize: 20, marginBottom: 8, fontWeight: 'bold' }, subtitle: { fontSize: 16, marginBottom: 8, }, textcontainer: { paddingLeft: 10, }, blanktext: { padding: 10,
fontSize: 20, } }); AppRegistry.registerComponent('GithubFinder', () => GithubFinder);
我们完成了应用程序的功能,演示了很多 React Native 开发中的概念。我们看到的模块化组件、精确的样式及其他功能,React 都能够支持。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论