Skip to content

Commit f11d3d0

Browse files
authored
Merge pull request #22 from Soomgo-Mobile/feature/remove-unused-types
Feature/remove unused types
2 parents 966bfbd + bbf89e6 commit f11d3d0

File tree

3 files changed

+42
-37
lines changed

3 files changed

+42
-37
lines changed

src/component/Dot.tsx

Lines changed: 37 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,11 @@
44
* Converted to Typescript on 14/07/2020.
55
* Converted to Functional component. on 21/09/2021
66
*/
7-
import React, { useEffect, useState } from 'react';
7+
import React, { useEffect, useMemo, useState } from 'react';
88
import { Animated } from 'react-native';
99
import { usePrevious } from 'react-use';
1010
import EmptyDot from './EmptyDot';
11-
import { getDotStyle, IDotStyle } from '../util/DotUtils';
11+
import { getDotStyle } from '../util/DotUtils';
1212

1313
const Dot: React.FC<{
1414
idx: number;
@@ -26,7 +26,7 @@ const Dot: React.FC<{
2626
maxPage: props.maxPage,
2727
})
2828
);
29-
const prevType = usePrevious<IDotStyle>(type);
29+
const prevType = usePrevious(type);
3030

3131
useEffect(() => {
3232
const nextType = getDotStyle({
@@ -60,47 +60,52 @@ const Dot: React.FC<{
6060
}).start();
6161
}, [animVal, animate, prevType, type]);
6262

63+
const animStyle = useMemo(() => {
64+
const size = animVal.interpolate({
65+
inputRange: [0, 1],
66+
outputRange: [
67+
(prevType?.size || 3) * props.sizeRatio,
68+
type.size * props.sizeRatio,
69+
],
70+
});
71+
return {
72+
width: size,
73+
height: size,
74+
borderRadius: animVal.interpolate({
75+
inputRange: [0, 1],
76+
outputRange: [
77+
(prevType?.size || 3) * props.sizeRatio * 0.5,
78+
type.size * props.sizeRatio * 0.5,
79+
],
80+
}),
81+
opacity: animVal.interpolate({
82+
inputRange: [0, 1],
83+
outputRange: [prevType?.opacity || 0.2, type.opacity],
84+
}),
85+
};
86+
}, [
87+
animVal,
88+
prevType?.opacity,
89+
prevType?.size,
90+
props.sizeRatio,
91+
type.opacity,
92+
type.size,
93+
]);
94+
6395
if (props.curPage < 3) {
6496
if (props.idx >= 5) return <EmptyDot sizeRatio={props.sizeRatio} />;
6597
} else if (props.curPage < 4) {
6698
if (props.idx > 5) return <EmptyDot sizeRatio={props.sizeRatio} />;
6799
}
68100

69-
const opacity = animVal.interpolate({
70-
inputRange: [0, 1],
71-
outputRange: [prevType?.opacity || 0.2, type.opacity],
72-
});
73-
74-
const size = animVal.interpolate({
75-
inputRange: [0, 1],
76-
outputRange: [
77-
(prevType?.size || 3) * props.sizeRatio,
78-
type.size * props.sizeRatio,
79-
],
80-
});
81-
82-
const borderRadius = animVal.interpolate({
83-
inputRange: [0, 1],
84-
outputRange: [
85-
(prevType?.size || 3) * props.sizeRatio * 0.5,
86-
type.size * props.sizeRatio * 0.5,
87-
],
88-
});
89-
const { activeColor } = props;
90-
91101
return (
92102
<Animated.View
93103
style={[
94104
{
95-
backgroundColor: activeColor,
105+
backgroundColor: props.activeColor,
96106
margin: 3 * props.sizeRatio,
97107
},
98-
{
99-
width: size,
100-
height: size,
101-
borderRadius: borderRadius,
102-
opacity: opacity,
103-
},
108+
animStyle,
104109
]}
105110
/>
106111
);

src/index.tsx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ const DotContainer: React.FC<IDotContainerProps> = (props) => {
3232

3333
const scrollTo = useCallback<(index: number, animated?: boolean) => void>(
3434
(index, animated = true) => {
35-
if (!refScrollView) return;
35+
if (!refScrollView.current) return;
3636

3737
const sizeRatio = getSizeRatio();
3838
const FIRST_EMPTY_DOT_SPACE = ONE_EMPTY_DOT_SIZE * 2;
@@ -44,15 +44,15 @@ const DotContainer: React.FC<IDotContainerProps> = (props) => {
4444
);
4545

4646
if (props.vertical) {
47-
refScrollView.current?.scrollTo({
47+
refScrollView.current.scrollTo({
4848
x: 0,
4949
y: moveTo,
5050
animated,
5151
});
5252
return;
5353
}
5454

55-
refScrollView.current?.scrollTo({
55+
refScrollView.current.scrollTo({
5656
x: moveTo,
5757
y: 0,
5858
animated,

src/util/DotUtils.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
1-
export type IDotStyle = {
1+
type IDotStyle = {
22
size: number;
33
opacity: number;
44
};
55

6-
export enum EnumDotType {
6+
enum EnumDotType {
77
ACTIVE,
88
INACTIVE,
99
MEDIUM,

0 commit comments

Comments
 (0)