首页 > 其他 > 详细

ReactNative: 使用活动指示器组件ActivityIndicator组件

时间:2019-12-31 15:11:46      阅读:98      评论:0      收藏:0      [点我收藏+]

一、简介

在App开发中,当某一个耗时的活动或者事件被触发后,经常需要显示一个loading,表示正在等待过程中。除了第三方提供的比较完善的吐司框架外,还可以使用原生的活动指示器显示。在ReactNative中提供了ActivityIndicator组件,可以用来显示一个loading。

 

二、API

这个组件比较简单,只提供了几个比较常用的属性,如下:

//表示是否执行动画
animating: PropTypes.bool

//设置指示器的颜色
color: ColorPropType

//设置指示器大小,模式是samll。第二个参数仅支持安卓使用,通过设置一个数来表示大小。
size: PropTypes.oneOfType([
  PropTypes.oneOf([ small, large ]),
  PropTypes.number,
])

//当动画停止时,是否隐藏
hidesWhenStopped: PropTypes.bool

 

三、使用

现在来简单使用一下这个组件,示例如下:

/**
 * Sample React Native App
 * https://github.com/facebook/react-native
 * @flow
 */

import React, { Component } from react;

import {
    AppRegistry,
    StyleSheet,
    View,
    Text,
    ActivityIndicator
} from react-native;


export default class ReactNativeDemo extends Component {

    render() {
        return (
            <View style={[styles.flex,styles.bgColor,styles.center]}>
                <ActivityIndicator
                    animating={true}
                    color={red}
                    size={large}
                    hidesWhenStopped={true}
                />
                <Text/>
            </View>
        );
    }
}

const styles = StyleSheet.create({
    flex: {
        flex: 1
    },
    bgColor: {
      backgroundColor: #1FB9FF
    },
    center: {
        alignItems: center,
        justifyContent: center
    }
});

AppRegistry.registerComponent(ReactNativeDemo, () => ReactNativeDemo);

技术分享图片

 

ReactNative: 使用活动指示器组件ActivityIndicator组件

原文:https://www.cnblogs.com/XYQ-208910/p/12124519.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!