convert SplashScreen to a Modal

This commit is contained in:
ammarahm-ed
2021-04-10 08:59:08 +05:00
parent 221ce526c1
commit 7d1c8cfc90

View File

@@ -24,6 +24,7 @@ import Paragraph from '../Typography/Paragraph';
import Icon from 'react-native-vector-icons/MaterialCommunityIcons'; import Icon from 'react-native-vector-icons/MaterialCommunityIcons';
import {DDS} from '../../services/DeviceDetection'; import {DDS} from '../../services/DeviceDetection';
import {openLinkInBrowser} from '../../utils/functions'; import {openLinkInBrowser} from '../../utils/functions';
import {Modal} from 'react-native';
const features = [ const features = [
{ {
@@ -70,11 +71,9 @@ const SplashScreen = () => {
const [isNext, setIsNext] = useState(true); const [isNext, setIsNext] = useState(true);
const opacity = useValue(0); const opacity = useValue(0);
const translateY = useValue(20);
const translateY2 = useValue(0);
useEffect(() => { useEffect(() => {
Storage.read('introCompleted').then(async (r) => { Storage.read('introCompleted').then(async r => {
requestAnimationFrame(() => { requestAnimationFrame(() => {
if (!r) { if (!r) {
setVisible(true); setVisible(true);
@@ -83,41 +82,23 @@ const SplashScreen = () => {
duration: 500, duration: 500,
easing: Easing.in(Easing.ease), easing: Easing.in(Easing.ease),
}).start(); }).start();
timing(translateY, {
toValue: 0,
duration: 500,
easing: Easing.in(Easing.ease),
}).start();
} }
}); });
}); });
}, []); }, []);
const hide = async () => { const hide = async () => {
timing(translateY2, {
toValue: dHeight * 2,
duration: 500,
easing: Easing.in(Easing.ease),
}).start();
await sleep(500);
setVisible(false); setVisible(false);
}; };
return ( return (
visible && ( visible && (
<Modal animationType="slide" statusBarTranslucent visible>
<Animated.View <Animated.View
style={{ style={{
zIndex: 999,
...getElevation(10),
width: '100%', width: '100%',
height: '100%', height: '100%',
position: 'absolute',
backgroundColor: colors.bg, backgroundColor: colors.bg,
transform: [
{
translateY: translateY2,
},
],
}}> }}>
<Animated.View <Animated.View
style={{ style={{
@@ -127,11 +108,6 @@ const SplashScreen = () => {
alignItems: 'center', alignItems: 'center',
padding: 12, padding: 12,
opacity: opacity, opacity: opacity,
transform: [
{
translateY: translateY,
},
],
}}> }}>
<View> <View>
<Carousel <Carousel
@@ -140,6 +116,10 @@ const SplashScreen = () => {
itemWidth={dWidth} itemWidth={dWidth}
sliderWidth={dWidth} sliderWidth={dWidth}
loop={false} loop={false}
onSnapToItem={i => {
currentIndex = i;
}}
activeAnimationType="timing"
shouldOptimizeUpdates shouldOptimizeUpdates
renderItem={({item, index}) => ( renderItem={({item, index}) => (
<View <View
@@ -169,7 +149,11 @@ const SplashScreen = () => {
}} }}
/> />
) : item.type === 'icon' ? ( ) : item.type === 'icon' ? (
<Icon color={item.color} name={item.icon} size={170} /> <Icon
color={item.color}
name={item.icon}
size={170}
/>
) : ( ) : (
<SvgXml <SvgXml
xml={ xml={
@@ -245,7 +229,11 @@ const SplashScreen = () => {
width={isNext ? null : '100%'} width={isNext ? null : '100%'}
onPress={async () => { onPress={async () => {
if (isNext) { if (isNext) {
carouselRef.current?.snapToItem(currentIndex + 1,true,true); carouselRef.current?.snapToItem(
currentIndex + 1,
true,
true,
);
currentIndex++; currentIndex++;
if (currentIndex === 4) { if (currentIndex === 4) {
setIsNext(false); setIsNext(false);
@@ -262,6 +250,7 @@ const SplashScreen = () => {
</View> </View>
</Animated.View> </Animated.View>
</Animated.View> </Animated.View>
</Modal>
) )
); );
}; };