1- import React , { useState } from 'react' ;
2- import { View , ViewProps , Image , ImageProps , StyleSheet , ActivityIndicator } from 'react-native' ;
1+ import React from 'react' ;
2+ import { View , ViewProps , Image , ImageProps , StyleSheet , ActivityIndicator , Text } from 'react-native' ;
33
44const styles = StyleSheet . create ( {
55 default : {
@@ -30,12 +30,20 @@ export interface AvatarProps extends ViewProps {
3030 * @default square
3131 */
3232 shape ?: 'circle' | 'square' ;
33+ loading ?: boolean ;
3334}
3435
3536const Avatar : React . FC < AvatarProps > = ( props ) => {
36- const { style, src = defaultImage , size = 40 , shape = 'square' , rounded = 3 , imageProps, ...otherProps } = props ;
37- const [ imageLoaded , setImageLoaded ] = useState ( false ) ;
38-
37+ const {
38+ style,
39+ src = defaultImage ,
40+ size = 40 ,
41+ shape = 'square' ,
42+ rounded = 3 ,
43+ imageProps,
44+ loading = false ,
45+ ...otherProps
46+ } = props ;
3947 return (
4048 < View
4149 style = { [
@@ -48,15 +56,22 @@ const Avatar: React.FC<AvatarProps> = (props) => {
4856 < View
4957 style = { [
5058 styles . default ,
51- { justifyContent : 'center' , alignItems : 'center' , flexDirection : 'row' , width : size , height : size } ,
59+ {
60+ justifyContent : 'center' ,
61+ alignItems : 'center' ,
62+ flexDirection : 'row' ,
63+ width : size ,
64+ height : size ,
65+ zIndex : loading ? 2023 : 0 ,
66+ } ,
5267 ] }
5368 >
54- { ! imageLoaded && < ActivityIndicator size = "small" color = "gray" /> }
69+ { loading && < ActivityIndicator size = "small" color = "gray" /> }
5570 </ View >
71+
5672 < Image
5773 style = { { width : size , height : size , position : 'absolute' , top : 0 , left : 0 } }
5874 source = { typeof src === 'number' ? src : { uri : src as string } }
59- onLoad = { ( ) => setImageLoaded ( true ) }
6075 { ...imageProps }
6176 />
6277 </ View >
0 commit comments