Skip to content

Commit 8401f55

Browse files
authored
Merge pull request #520 from panbibi/dev
refactor(Tooltip): 使用函数组件替换Class组件
2 parents 0edb15d + d9f6a03 commit 8401f55

File tree

7 files changed

+180
-170
lines changed

7 files changed

+180
-170
lines changed

packages/core/src/Empty/index.tsx

Lines changed: 11 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -2,19 +2,18 @@ import React, { Component } from 'react';
22
import { StyleSheet, Text, TextProps } from 'react-native';
33
import Icon from '../Icon';
44
import Flex, { FlexProps } from '../Flex';
5-
import { iconStr } from './svg';
65

7-
// export const iconStr = `
8-
// <svg width="64" height="41" viewBox="0 0 64 41">
9-
// <g transform="translate(0 1)" fill="none" fill-rule="evenodd">
10-
// <ellipse fill="#F5F5F5" cx="32" cy="33" rx="32" ry="7"></ellipse>
11-
// <g fill-rule="nonzero" stroke="#D9D9D9">
12-
// <path fill="#FFF" d="M55 12.76L44.854 1.258C44.367.474 43.656 0 42.907 0H21.093c-.749 0-1.46.474-1.947 1.257L9 12.761V22h46v-9.24z"></path>
13-
// <path fill="#FAFAFA" d="M41.613 15.931c0-1.605.994-2.93 2.227-2.931H55v18.137C55 33.26 53.68 35 52.05 35h-40.1C10.32 35 9 33.259 9 31.137V13h11.16c1.233 0 2.227 1.323 2.227 2.928v.022c0 1.605 1.005 2.901 2.237 2.901h14.752c1.232 0 2.237-1.308 2.237-2.913v-.007z"></path>
14-
// </g>
15-
// </g>
16-
// </svg>
17-
// `;
6+
export const iconStr = `
7+
<svg width="64" height="41" viewBox="0 0 64 41">
8+
<g transform="translate(0 1)" fill="none" fill-rule="evenodd">
9+
<ellipse fill="#F5F5F5" cx="32" cy="33" rx="32" ry="7"></ellipse>
10+
<g fill-rule="nonzero" stroke="#D9D9D9">
11+
<path fill="#FFF" d="M55 12.76L44.854 1.258C44.367.474 43.656 0 42.907 0H21.093c-.749 0-1.46.474-1.947 1.257L9 12.761V22h46v-9.24z"></path>
12+
<path fill="#FAFAFA" d="M41.613 15.931c0-1.605.994-2.93 2.227-2.931H55v18.137C55 33.26 53.68 35 52.05 35h-40.1C10.32 35 9 33.259 9 31.137V13h11.16c1.233 0 2.227 1.323 2.227 2.928v.022c0 1.605 1.005 2.901 2.237 2.901h14.752c1.232 0 2.237-1.308 2.237-2.913v-.007z"></path>
13+
</g>
14+
</g>
15+
</svg>
16+
`;
1817

1918
export interface EmptyProps extends FlexProps {
2019
/**

packages/core/src/Empty/svg.tsx

Lines changed: 0 additions & 11 deletions
This file was deleted.

packages/core/src/Tile/index.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ export type TileProps = TouchableOpacityProps &
4949
/** 继承image的api */
5050
imageProps?: Partial<ImageProps>;
5151
/** Custom ImageComponent for Tile. */
52-
ImageComponent?: typeof React.Component;
52+
ImageComponent?: Function;
5353
};
5454

5555
const Tile = ({

packages/core/src/Tooltip/Cloud.tsx

Lines changed: 32 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -17,41 +17,39 @@ interface CloudProps extends ViewProps {
1717
borderRadius?: number;
1818
}
1919

20-
export default class Cloud extends React.Component<CloudProps> {
21-
render() {
22-
const { title, isDown, isStart, triangle, backgroundColor, borderRadius } = this.props;
23-
const style: ViewStyle = {
24-
flexDirection: isDown ? 'column-reverse' : 'column',
25-
alignItems: isStart,
26-
};
27-
const TextContainerStyle: ViewStyle = {
28-
position: triangle ? 'absolute' : 'relative',
29-
marginVertical: triangle ? 10 : 0,
30-
backgroundColor,
31-
borderRadius,
32-
paddingHorizontal: 10,
33-
paddingVertical: 10,
34-
};
35-
return (
36-
<View style={[style]}>
37-
<View
38-
style={[
39-
styles.cloudFoot,
40-
{
41-
transform: [{ rotateX: isDown ? '180deg' : '0deg' }],
42-
position: triangle ? 'absolute' : 'relative',
43-
left: triangle,
44-
zIndex: 9999,
45-
borderBottomColor: backgroundColor,
46-
},
47-
]}
48-
/>
49-
<View testID="RNE__Tooltip__cloud__view" style={[{ ...TextContainerStyle }]}>
50-
<Text style={[styles.cloudText]}>{title}</Text>
51-
</View>
20+
export default function Cloud(props: CloudProps) {
21+
const { title, isDown, isStart, triangle, backgroundColor, borderRadius } = props;
22+
const style: ViewStyle = {
23+
flexDirection: isDown ? 'column-reverse' : 'column',
24+
alignItems: isStart,
25+
};
26+
const TextContainerStyle: ViewStyle = {
27+
position: triangle ? 'absolute' : 'relative',
28+
marginVertical: triangle ? 10 : 0,
29+
backgroundColor,
30+
borderRadius,
31+
paddingHorizontal: 10,
32+
paddingVertical: 10,
33+
};
34+
return (
35+
<View style={[style]}>
36+
<View
37+
style={[
38+
styles.cloudFoot,
39+
{
40+
transform: [{ rotateX: isDown ? '180deg' : '0deg' }],
41+
position: triangle ? 'absolute' : 'relative',
42+
left: triangle,
43+
zIndex: 9999,
44+
borderBottomColor: backgroundColor,
45+
},
46+
]}
47+
/>
48+
<View testID="RNE__Tooltip__cloud__view" style={[{ ...TextContainerStyle }]}>
49+
<Text style={[styles.cloudText]}>{title}</Text>
5250
</View>
53-
);
54-
}
51+
</View>
52+
);
5553
}
5654

5755
const styles = StyleSheet.create({

0 commit comments

Comments
 (0)