Skip to content

Commit 8ce6753

Browse files
WIP: Migrate components to TS
1 parent 8cfbd7e commit 8ce6753

File tree

21 files changed

+870
-1856
lines changed

21 files changed

+870
-1856
lines changed

package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,7 @@
111111
"@types/invariant": "^2.2.35",
112112
"@types/jest": "^26.0.0",
113113
"@types/react": "^16.9.19",
114-
"@types/react-native": "0.62.13",
114+
"@types/react-native": "^0.69.5",
115115
"babel-eslint": "^10.0.0",
116116
"babel-jest": "^24.9.0",
117117
"commitlint": "^11.0.0",
@@ -127,7 +127,7 @@
127127
"pod-install": "^0.1.0",
128128
"prettier": "^2.0.5",
129129
"react": "16.13.1",
130-
"react-native": "0.63.4",
130+
"react-native": "^0.69.4",
131131
"react-native-builder-bob": "^0.18.0",
132132
"react-test-renderer": "16.10.2",
133133
"release-it": "^14.2.2",

src/components/affix/index.js

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

src/components/affix/index.tsx

Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
import React from 'react';
2+
import {
3+
Animated,
4+
ColorValue,
5+
StyleProp,
6+
StyleSheet,
7+
TextStyle,
8+
ViewStyle,
9+
} from 'react-native';
10+
11+
interface AffixProps {
12+
labelAnimation: Animated.Value;
13+
style?: StyleProp<TextStyle>;
14+
children?: string;
15+
type: 'prefix' | 'suffix';
16+
fontSize: number;
17+
color: ColorValue;
18+
}
19+
20+
const Affix = ({
21+
labelAnimation,
22+
style,
23+
children,
24+
type,
25+
fontSize,
26+
color,
27+
}: AffixProps) => {
28+
let containerStyle: Animated.AnimatedProps<StyleProp<ViewStyle>> = {
29+
height: fontSize * 1.5,
30+
opacity: labelAnimation,
31+
};
32+
33+
let textStyle: StyleProp<TextStyle> = {
34+
includeFontPadding: false,
35+
textAlignVertical: 'top',
36+
fontSize,
37+
color,
38+
};
39+
40+
switch (type) {
41+
case 'prefix':
42+
containerStyle.paddingRight = 8;
43+
textStyle.textAlign = 'left';
44+
break;
45+
46+
case 'suffix':
47+
containerStyle.paddingLeft = 8;
48+
textStyle.textAlign = 'right';
49+
break;
50+
}
51+
52+
return (
53+
<Animated.View style={[styles.container, containerStyle]}>
54+
<Animated.Text style={[style, textStyle]}>{children}</Animated.Text>
55+
</Animated.View>
56+
);
57+
};
58+
59+
export default Affix;
60+
61+
const styles = StyleSheet.create({
62+
container: {
63+
top: 2,
64+
justifyContent: 'center',
65+
},
66+
});

src/components/affix/styles.js

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

src/components/counter/index.js

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

src/components/counter/index.tsx

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
import React from 'react';
2+
import {
3+
ColorValue,
4+
StyleProp,
5+
StyleSheet,
6+
Text,
7+
TextStyle,
8+
} from 'react-native';
9+
10+
interface CounterProps {
11+
count: number;
12+
limit?: number;
13+
baseColor: ColorValue;
14+
errorColor: ColorValue;
15+
style?: StyleProp<TextStyle>;
16+
}
17+
18+
const Counter = ({
19+
count,
20+
limit,
21+
baseColor,
22+
errorColor,
23+
style,
24+
}: CounterProps) => {
25+
if (!limit) {
26+
return null;
27+
}
28+
29+
return (
30+
<Text
31+
style={[
32+
styles.text,
33+
style,
34+
{
35+
color: count > limit ? errorColor : baseColor,
36+
},
37+
]}
38+
>{`${count} / ${limit}`}</Text>
39+
);
40+
};
41+
42+
export default Counter;
43+
44+
const styles = StyleSheet.create({
45+
text: {
46+
fontSize: 12,
47+
lineHeight: 16,
48+
textAlign: 'right',
49+
backgroundColor: 'transparent',
50+
paddingVertical: 2,
51+
marginLeft: 8,
52+
},
53+
});
File renamed without changes.

src/components/counter/test.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import 'react-native';
22
import React from 'react';
33
import renderer from 'react-test-renderer';
44

5-
import Counter from '.';
5+
import Counter from './index';
66

77
/* eslint-env jest */
88

File renamed without changes.
File renamed without changes.

0 commit comments

Comments
 (0)