Skip to content

Commit 204cf1f

Browse files
author
rulishu
committed
refactor(Spacing): 重构Spacing为函数组件
1 parent a066e3d commit 204cf1f

File tree

1 file changed

+12
-18
lines changed

1 file changed

+12
-18
lines changed

packages/core/src/Spacing/index.tsx

Lines changed: 12 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -6,23 +6,17 @@ export interface SpacingProps extends ViewProps {
66
type?: 'horizontal' | 'vertical';
77
}
88

9-
export default class Spacing extends Component<SpacingProps> {
10-
static defaultProps: SpacingProps = {
11-
size: 'default',
12-
type: 'vertical',
13-
};
14-
render() {
15-
const { size, style, type, ...otherProps } = this.props;
16-
const sty: SpacingProps['style'] = {};
17-
const keyName = type === 'vertical' ? 'height' : 'width';
18-
sty[keyName] = 10;
19-
if (size === 'small') {
20-
sty[keyName] = 5;
21-
} else if (size === 'large') {
22-
sty[keyName] = 15;
23-
} else if (typeof size === 'number') {
24-
sty[keyName] = size;
25-
}
26-
return <View style={[sty, style]} {...otherProps} />;
9+
export default function Spacing(props: SpacingProps) {
10+
const { size = 'default', style, type = 'vertical', ...otherProps } = props;
11+
const sty: SpacingProps['style'] = {};
12+
const keyName = type === 'vertical' ? 'height' : 'width';
13+
sty[keyName] = 10;
14+
if (size === 'small') {
15+
sty[keyName] = 5;
16+
} else if (size === 'large') {
17+
sty[keyName] = 15;
18+
} else if (typeof size === 'number') {
19+
sty[keyName] = size;
2720
}
21+
return <View style={[sty, style]} {...otherProps} />;
2822
}

0 commit comments

Comments
 (0)