Skip to content

Commit d5d7816

Browse files
committed
fix(Avatar): 组件修改为function组件
1 parent 30f2295 commit d5d7816

File tree

1 file changed

+20
-28
lines changed

1 file changed

+20
-28
lines changed

packages/core/src/Avatar/index.tsx

Lines changed: 20 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import React, { Component } from 'react';
1+
import React from 'react';
22
import { View, ViewProps, Image, ImageProps, StyleSheet } from 'react-native';
33

44
const styles = StyleSheet.create({
@@ -36,31 +36,23 @@ export interface AvatarProps extends ViewProps {
3636
shape?: 'circle' | 'square';
3737
}
3838

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+
);
6658
}

0 commit comments

Comments
 (0)