Skip to content

Commit bbf89e6

Browse files
committed
feat: [:art:] update styles
1 parent 0bb19ec commit bbf89e6

File tree

1 file changed

+35
-30
lines changed

1 file changed

+35
-30
lines changed

src/component/Dot.tsx

Lines changed: 35 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
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';
@@ -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
);

0 commit comments

Comments
 (0)