|
1 | | -import React, { Component } from 'react'; |
| 1 | +import React from 'react'; |
2 | 2 | import { View, ViewProps, Image, ImageProps, StyleSheet } from 'react-native'; |
3 | 3 |
|
4 | 4 | const styles = StyleSheet.create({ |
@@ -36,31 +36,23 @@ export interface AvatarProps extends ViewProps { |
36 | 36 | shape?: 'circle' | 'square'; |
37 | 37 | } |
38 | 38 |
|
39 | | -export default class Avatar extends Component<AvatarProps> { |
40 | | - static defaultProps: AvatarProps = { |
41 | | - src: defaultImage, |
42 | | - shape: 'square', |
43 | | - rounded: 3, |
44 | | - size: 40, |
45 | | - }; |
46 | | - render() { |
47 | | - const { style, src, size, shape, rounded, imageProps, ...otherProps } = this.props; |
48 | | - return ( |
49 | | - <View |
50 | | - style={[ |
51 | | - styles.defalut, |
52 | | - style, |
53 | | - { width: size, height: size }, |
54 | | - { borderRadius: shape === 'circle' ? size! / 2 : rounded }, |
55 | | - ]} |
56 | | - {...otherProps} |
57 | | - > |
58 | | - <Image |
59 | | - style={{ width: size, height: size }} |
60 | | - source={typeof src === 'number' ? src : { uri: src as string }} |
61 | | - {...imageProps} |
62 | | - /> |
63 | | - </View> |
64 | | - ); |
65 | | - } |
| 39 | +export default function Avatar(props: AvatarProps) { |
| 40 | + const { style, src = defaultImage, size = 40, shape = 'square', rounded = 3, imageProps, ...otherProps } = props; |
| 41 | + return ( |
| 42 | + <View |
| 43 | + style={[ |
| 44 | + styles.defalut, |
| 45 | + style, |
| 46 | + { width: size, height: size }, |
| 47 | + { borderRadius: shape === 'circle' ? size! / 2 : rounded }, |
| 48 | + ]} |
| 49 | + {...otherProps} |
| 50 | + > |
| 51 | + <Image |
| 52 | + style={{ width: size, height: size }} |
| 53 | + source={typeof src === 'number' ? src : { uri: src as string }} |
| 54 | + {...imageProps} |
| 55 | + /> |
| 56 | + </View> |
| 57 | + ); |
66 | 58 | } |
0 commit comments