React-Native进阶_2.加载指示动画 ActivityIndicator
2017-07-29 02:41
549 查看
在安卓原始 App中使用的加载框 ProgressBar 在React -Native 中也是有相对应的视图,叫做ActivityIndicator,对应ios 中React-Native 提供的是 ActivityIndicatorIos
带动画的加载指示 android 使用 ActivityIndicator ios 使用 ActivityIndicatorIos
size = 'large'
color ='#6435c9'
设置大小和颜色
/**
* Sample React Native App
* https://github.com/facebook/react-native * @flow
*/
'use strict'
import React, {Component} from 'react';
import styles from '../Styles/Main';
import {
Text,
Image,
View,
ListView,
ActivityIndicator,
} from 'react-native';
let REQUEST_URL = 'https://api.douban.com/v2/movie/top250';
export default class Day0718 extends Component {
constructor(props) {
super(props);
this.state = {
dataSource:new ListView.DataSource({rowHasChanged: (r1, r2) => r1 !== r2}),
loaded: false,
};
}
componentDidMount(){
this._fetchData();
}
_fetchData(){
fetch(REQUEST_URL)
.then(response => response.json())
.then(responseData =>{
this.setState({
movies:this.state.dataSource.cloneWithRows(responseData.subjects),
// loaded: true,
});
})
.done();
}
render() {
if(!this.state.loaded){
return this._renderLoadingView();
}
return (
<View style={styles.Container}>
<ListView
dataSource={this.state.movies}
renderRow={this._renderMovieList}
style={styles.listView}
/>
</View>
);
}
_renderMovieList(movie){
return(
<View style = {styles.item}>
<View style = {styles.itemImage}>
<Image
style ={styles.image}
source ={{uri:movie.images.large}}/>
</View>
<View style = {styles.itemContent}>
<Text style ={styles.itemHeader}>{movie.title}</Text>
<Text style ={styles.itemMeta}>{movie.original_title}({movie.year})</Text>
<Text style ={styles.redText}>{movie.rating.average}</Text>
</View>
</View>
);
};
_renderLoadingView(){
return (
<View style ={styles.loading}>
<ActivityIndicator
size = 'large'
color ='#6435c9'
/>
</View>
);
};
}
效果图:
带动画的加载指示 android 使用 ActivityIndicator ios 使用 ActivityIndicatorIos
size = 'large'
color ='#6435c9'
设置大小和颜色
/**
* Sample React Native App
* https://github.com/facebook/react-native * @flow
*/
'use strict'
import React, {Component} from 'react';
import styles from '../Styles/Main';
import {
Text,
Image,
View,
ListView,
ActivityIndicator,
} from 'react-native';
let REQUEST_URL = 'https://api.douban.com/v2/movie/top250';
export default class Day0718 extends Component {
constructor(props) {
super(props);
this.state = {
dataSource:new ListView.DataSource({rowHasChanged: (r1, r2) => r1 !== r2}),
loaded: false,
};
}
componentDidMount(){
this._fetchData();
}
_fetchData(){
fetch(REQUEST_URL)
.then(response => response.json())
.then(responseData =>{
this.setState({
movies:this.state.dataSource.cloneWithRows(responseData.subjects),
// loaded: true,
});
})
.done();
}
render() {
if(!this.state.loaded){
return this._renderLoadingView();
}
return (
<View style={styles.Container}>
<ListView
dataSource={this.state.movies}
renderRow={this._renderMovieList}
style={styles.listView}
/>
</View>
);
}
_renderMovieList(movie){
return(
<View style = {styles.item}>
<View style = {styles.itemImage}>
<Image
style ={styles.image}
source ={{uri:movie.images.large}}/>
</View>
<View style = {styles.itemContent}>
<Text style ={styles.itemHeader}>{movie.title}</Text>
<Text style ={styles.itemMeta}>{movie.original_title}({movie.year})</Text>
<Text style ={styles.redText}>{movie.rating.average}</Text>
</View>
</View>
);
};
_renderLoadingView(){
return (
<View style ={styles.loading}>
<ActivityIndicator
size = 'large'
color ='#6435c9'
/>
</View>
);
};
}
效果图:
相关文章推荐
- React Native Animated 动画之 加载中loading
- React Native进阶之Animated动画库详解
- 【React Native开发】React Native 进阶之原生混合与数据通信开发详解-适配iOS开发(61)
- react-native实现搜索栏渐过渡动画
- React Native入门(十四)之动画(1)Animated详解
- 加载一个react native 页面
- React Native开源特效动画封装库模块(lottie-react-native)
- Android React Native加载图片资源的正确姿势
- ReactNative ListView + 上拉加载更多
- React-Native系列Android——SoLoader加载动态链接库
- react-native-Art动画基础
- ReactNative——动画学习
- react native listView(1) 加载网络数据简单版
- react-native-动画
- RN(react native)入坑指南-08,如何加载远程数据
- react native FlatList使用详解以及上拉刷新下拉加载带可运行demo
- React Native SVG Animated 绘制动画
- react native webView 加载没反应和基本使用
- ReactNative ListView + 上拉加载更多 + 下拉刷新
- React Native两种加载图片的方式