With React Native you use ActivityIndicatorIOS to show or hide a spinner. In this lesson we combine ActivityIndicatorIOS with our HTTP requests in order to give the user feedback about data loading.

What you want is when calling the fetch api, showing the loading spinner. If success or not found user will hide the loadin spinner. For user not found, will show the error message.

import React, { Component, PropTypes } from 'react';
import { View, Text, StyleSheet, TextInput, TouchableHighlight, ActivityIndicatorIOS } from 'react-native';
import api from '../utils/api';
import Dashboard from './Dashboard'; var style = StyleSheet.create({
mainContainer: {
flex: ,
padding: ,
marginTop: ,
flexDirection: 'column',
justifyContent: 'center',
backgroundColor: '#48BBEC'
},
title: {
marginBottom: ,
fontSize: ,
textAlign: 'center',
color: '#fff'
},
searchInput: {
height: ,
padding: ,
marginRight: ,
fontSize: ,
borderWidth: ,
borderColor: 'white',
borderRadius: ,
color: 'white'
},
buttonText: {
fontSize: ,
color: '#111',
alignSelf: 'center'
},
button: {
height: ,
flexDirection: 'row',
backgroundColor:'#8fefcc',
borderColor:'white',
borderWidth:,
borderRadius:,
marginBottom:,
alignSelf:'stretch',
justifyContent:'center'
}
}); export default class Main extends Component{
constructor(props){
super(props)
this.state = {
username: '',
isLoading: false,
error: false
};
}
handleChange(event){
this.setState({
username: event.nativeEvent.text
})
}
handleSubmit(event){
//update our indicatorIOS spinner
this.setState({
isLoading: true
});
//fetch data from github
api.getBio(this.state.username)
.then( (res) => {
if(res.message === "Not Found"){
this.setState({
error: 'User not found',
isLoading: false
})
}else{
//Pass in a new router component
this.props.navigator.push({
title: res.name || 'Selet an Option',
component: Dashboard,
passProps: {userInfo: res}
});
//Clean the search input and loading
this.setState({
isLoading: false,
error: false,
username: 'User not found'
});
}
})
}
render(){
const showError = (
this.state.error ? <Text>User not found</Text>: <View></View>
);
return (
<View style={style.mainContainer}>
<Text style={style.title}>Search for a Github User</Text>
<TextInput
style={style.searchInput}
value={this.state.username}
onChange={this.handleChange.bind(this)}
/>
<TouchableHighlight
style={style.button}
onPress={this.handleSubmit.bind(this)}
underlayColor="white"
>
<Text style={style.buttonText}>SEARCH USER</Text>
</TouchableHighlight>
<ActivityIndicatorIOS
animating={this.state.isLoading}
size="large"
color="#111"
/>
{showError}
</View>
)
}
}

[React Native] Error Handling and ActivityIndicatorIOS的更多相关文章

  1. [react native] Error loading page

    如上图显示的错误,解决方法如下: 在react native ios项目的info.plist文件中,新增一个属性. 在Info.plist中添加NSAppTransportSecurity类型Dic ...

  2. [RN] React Native :Error: Cannot find module 'asap/raw'

    今天在使用 react-native-dropdownmenus 的时候,安装没问题,但Link的时候 报: Error: Cannot find module 'asap/raw' 朋友们莫慌,一步 ...

  3. 解决React Native:Error: Cannot find module 'asap/raw'

    本来想做个底部切换的tab的,安装完 npm i react-native-tab-navigator --save 后跑项目就报错了,如下图 和我一样报这个错的朋友们莫慌,一步就可以解决了,执行命令 ...

  4. React Native开发技术周报2

    (1).资讯 1.React Native 0.22_rc版本发布 添加了热自动重载功能 (2).技术文章 1.用 React Native 设计的第一个 iOS 应用 我们想为用户设计一款移动端的应 ...

  5. React Native专题

    转载注明出处:地址:http://www.lcode.org本文出自:[江清清的技术专栏]本React Native讲解专题:主要讲解了React Native开发,由基础环境搭建配置入门,基础,进阶 ...

  6. React Native专题-江清清

    本React Native讲解专题:主要讲解了React Native开发,由基础环境搭建配置入门,基础,进阶相关讲解. 刚创建的React Native交流8群:533435865  欢迎各位大牛, ...

  7. React Native 常用插件案例

    (二).基础入门: 1.React Native For Android环境配置以及第一个实例 2.React Native开发IDE安装及配置 3.React Native应用设备运行(Runnin ...

  8. Flipper & React Native

    Flipper & React Native Flipper Flipper是一款用于调试移动应用程序的出色开发人员工具,在Android和iOS社区中颇受欢迎. Flipper is a g ...

  9. react native中一次错误排查 Error:Error: Duplicate resources

    最近一直在使用react native中,遇到了很多的坑,同时也学习到了一些移动端的开发经验. 今天在做一个打包的测试时,遇到了一个问题,打包过程中报错“Error:Error: Duplicate ...

随机推荐

  1. HDOJ多校联合第五场

    1001 Inversion 题意:求逆序对,然后交换k次相邻的两个数,使得剩下的逆序对最少. 分析:题目用到的结论是:数组中存在一对逆序对,那么可以通过交换相邻两个数使得逆序对减少1,交换k次,可以 ...

  2. [wikioi]线段覆盖

    http://wikioi.com/problem/1214/ 这道题也归为贪心了.我也不是很能分辨,但想法确实是:1.有阶段最优化性:2.前一状态和后一状态有关系. 想法:1.排个序是很自然的想法, ...

  3. ubuntu使用中的一些问题

    ubuntu如何修改计算机名? sudo gedit /etc/hostname 如何查看ubuntu操作系统位数 方法1: #查看long的位数,返回32或64 getconf LONG_BIT 方 ...

  4. VC 无标题栏对话框移动(在OnLButtonDown里再次发送消息)

    操作系统:Windows 7软件环境:Visual C++ 2008 SP1本次目的:实现无框移动 所谓的无标题栏对话框,是基于对话框的工程,对话框属性Border设置为None,对话框如下所示: 为 ...

  5. hihocoder #1289 : 403 Forbidden (2016 微软编程笔试第二题)

    #1289 : 403 Forbidden 时间限制:10000ms 单点时限:1000ms 内存限制:256MB 描述 Little Hi runs a web server. Sometimes ...

  6. amaze UI的使用

    1.放置在独立的位置 2.引入核心css与js <link href="{sh::PUB}amaze-ui/css/amazeui.min.css" rel="st ...

  7. 7 个面向Web开发者的实用CSS3教程推荐

    通过CSS来创建精细.复杂的效果,成为了Web前端开发的未来趋势.世界各地的设计师认为CSS3是一项非常具有潜力的技术,未来将会创造更多不可思议的美妙设计. 本文为Web开发者带来了一些与CSS3相关 ...

  8. 【转】在Xcode中使用Git进行源码版本控制 -- 不错

    原文网址:http://www.cocoachina.com/ios/20140524/8536.html 本文翻译自Understanding Git Source Control in Xcode ...

  9. [BILL.WEI]stimulsoft reports ,巧用关系,简化sql语句

    stimulsoft reports关系的2大有点 1,跨数据库. 在做报表的时候,我们可能会从不同的数据库中取数据,这个时候,我们就可以利用关系 通过关联的字段,将2者关联起来,然后就可以在报表里面 ...

  10. python __enter__ 与 __exit__的作用,以及与 with 语句的关系

    转载自:http://linbo.github.io/2013/01/08/python-with/ (一直不知道博客园哪里发转载文章) With语句是什么? 有一些任务,可能事先需要设置,事后做清理 ...