2022-05-03 20:15:16 +00:00
|
|
|
import React, { useEffect } from 'react';
|
|
|
|
import { Modal, StyleSheet, View, PixelRatio } from 'react-native';
|
|
|
|
import Animated, {
|
|
|
|
cancelAnimation,
|
|
|
|
Extrapolate,
|
|
|
|
interpolate,
|
|
|
|
useAnimatedStyle,
|
|
|
|
useSharedValue,
|
|
|
|
withRepeat,
|
|
|
|
withSequence,
|
|
|
|
withTiming
|
|
|
|
} from 'react-native-reanimated';
|
|
|
|
|
|
|
|
import { useTheme } from '../theme';
|
2018-04-24 19:34:03 +00:00
|
|
|
|
|
|
|
const styles = StyleSheet.create({
|
|
|
|
container: {
|
|
|
|
flex: 1,
|
|
|
|
alignItems: 'center',
|
2021-08-16 21:14:56 +00:00
|
|
|
justifyContent: 'center'
|
2018-04-24 19:34:03 +00:00
|
|
|
},
|
|
|
|
image: {
|
2022-05-03 20:15:16 +00:00
|
|
|
width: PixelRatio.get() * 40,
|
|
|
|
height: PixelRatio.get() * 40,
|
2018-04-24 19:34:03 +00:00
|
|
|
resizeMode: 'contain'
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2021-09-13 20:41:05 +00:00
|
|
|
interface ILoadingProps {
|
|
|
|
visible: boolean;
|
2022-03-18 15:02:04 +00:00
|
|
|
}
|
|
|
|
|
2022-05-03 20:15:16 +00:00
|
|
|
const Loading = ({ visible }: ILoadingProps): React.ReactElement => {
|
|
|
|
const opacity = useSharedValue(0);
|
|
|
|
const scale = useSharedValue(1);
|
|
|
|
const { colors } = useTheme();
|
2018-04-24 19:34:03 +00:00
|
|
|
|
2022-05-03 20:15:16 +00:00
|
|
|
useEffect(() => {
|
2018-09-25 19:28:42 +00:00
|
|
|
if (visible) {
|
2022-05-03 20:15:16 +00:00
|
|
|
opacity.value = withTiming(1, {
|
|
|
|
duration: 200
|
|
|
|
});
|
|
|
|
scale.value = withRepeat(withSequence(withTiming(0, { duration: 1000 }), withTiming(1, { duration: 1000 })), -1);
|
2018-08-01 19:35:06 +00:00
|
|
|
}
|
2022-05-03 20:15:16 +00:00
|
|
|
return () => {
|
|
|
|
cancelAnimation(scale);
|
|
|
|
};
|
|
|
|
}, [opacity, scale, visible]);
|
|
|
|
|
|
|
|
const animatedOpacity = useAnimatedStyle(() => ({
|
|
|
|
opacity: interpolate(opacity.value, [0, 1], [0, colors.backdropOpacity], Extrapolate.CLAMP)
|
|
|
|
}));
|
|
|
|
const animatedScale = useAnimatedStyle(() => ({ transform: [{ scale: interpolate(scale.value, [0, 0.5, 1], [1, 1.1, 1]) }] }));
|
|
|
|
|
|
|
|
return (
|
|
|
|
<Modal visible={visible} transparent onRequestClose={() => {}}>
|
|
|
|
<View style={styles.container} testID='loading'>
|
|
|
|
<Animated.View
|
|
|
|
style={[
|
|
|
|
{
|
|
|
|
...StyleSheet.absoluteFillObject,
|
|
|
|
backgroundColor: colors.backdropColor
|
|
|
|
},
|
|
|
|
animatedOpacity
|
|
|
|
]}
|
|
|
|
/>
|
|
|
|
<Animated.Image source={require('../static/images/logo.png')} style={[styles.image, animatedScale]} />
|
|
|
|
</View>
|
|
|
|
</Modal>
|
|
|
|
);
|
|
|
|
};
|
|
|
|
|
|
|
|
export default Loading;
|