Skip to content

Commit ed29347

Browse files
committed
Fix loader animation and table key
1 parent 48f811d commit ed29347

2 files changed

Lines changed: 16 additions & 36 deletions

File tree

src/components/Loader/index.tsx

Lines changed: 15 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -1,42 +1,22 @@
1-
import React, { useEffect, useRef } from 'react';
21
import { Animated, Easing, View } from 'react-native';
32

4-
const AnimateState = {
5-
start: 0,
6-
end: 360,
7-
};
8-
93
const Loader = () => {
10-
const value = useRef(new Animated.Value(AnimateState.start)).current;
11-
const inputRange = [AnimateState.start, AnimateState.end];
12-
const rotate = value.interpolate({
13-
inputRange,
14-
outputRange: [0 + 'deg', 360 + 'deg'],
4+
const spinValue = new Animated.Value(0);
5+
6+
Animated.loop(
7+
Animated.timing(spinValue, {
8+
toValue: 1,
9+
duration: 1500,
10+
easing: Easing.linear,
11+
useNativeDriver: true,
12+
})
13+
).start();
14+
15+
const spin = spinValue.interpolate({
16+
inputRange: [0, 1],
17+
outputRange: ['0deg', '360deg'],
1518
});
1619

17-
useEffect(() => {
18-
startAnimate();
19-
20-
return () => {
21-
stopAnimate();
22-
};
23-
}, []);
24-
25-
const startAnimate = () => {
26-
Animated.loop(
27-
Animated.sequence([
28-
Animated.timing(value, {
29-
toValue: AnimateState.end,
30-
useNativeDriver: false,
31-
duration: 1000,
32-
easing: Easing.linear,
33-
}),
34-
])
35-
).start();
36-
};
37-
38-
const stopAnimate = () => value.stopAnimation();
39-
4020
return (
4121
<View
4222
style={{
@@ -51,7 +31,7 @@ const Loader = () => {
5131
<Animated.Image
5232
source={require('../../assets/reload.png')}
5333
style={{
54-
transform: [{ rotate }],
34+
transform: [{ rotate: spin }],
5535
justifyContent: 'center',
5636
marginTop: 'auto',
5737
marginBottom: 'auto',

src/components/Table/index.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -160,7 +160,7 @@ const Table = ({ tableData, onActionSuccess }: TableProps) => {
160160
/>
161161
)}
162162
// TODO как тут быть с ключем? поля id может и не быть
163-
keyExtractor={(item, index) => `row-${item.id ? item.id : index}`}
163+
keyExtractor={(item, index) => `row-${item.id}_${index}`}
164164
bounces={true}
165165
initialNumToRender={20}
166166
style={styles.TableContainer}

0 commit comments

Comments
 (0)