Files
notesnook/apps/mobile/src/components/SplashScreen/index.js

237 lines
6.9 KiB
JavaScript
Raw Normal View History

2021-02-10 21:57:08 +05:00
import React, { useEffect, useRef, useState } from 'react';
import { Image, View } from 'react-native';
import Animated, { Easing, timing, useValue } from 'react-native-reanimated';
2021-02-08 12:55:12 +05:00
import Carousel from 'react-native-snap-carousel';
2021-02-10 21:57:08 +05:00
import { SvgXml } from 'react-native-svg';
import { NOTE_SVG, SYNC_SVG } from '../../assets/images/assets';
import { useTracked } from '../../provider';
import { eSendEvent } from '../../services/EventManager';
import { dHeight, dWidth, getElevation } from '../../utils';
import { eOpenLoginDialog } from '../../utils/Events';
import { SIZE } from '../../utils/SizeUtils';
2021-02-08 12:55:12 +05:00
import Storage from '../../utils/storage';
2021-02-10 21:57:08 +05:00
import { sleep } from '../../utils/TimeUtils';
import { Button } from '../Button';
2021-02-08 12:55:12 +05:00
import Heading from '../Typography/Heading';
import Paragraph from '../Typography/Paragraph';
const SplashScreen = () => {
const [state, dispatch] = useTracked();
const {colors} = state;
const [visible, setVisible] = useState(false);
const carouselRef = useRef();
const [isNext, setIsNext] = useState(true);
const opacity = useValue(0);
const translateY = useValue(20);
const translateY2 = useValue(0);
const features = [
{
title: 'Notesnook',
2021-02-10 21:57:08 +05:00
description: 'A safe place to write and stay organized.',
2021-02-08 12:55:12 +05:00
icon: require('../../assets/images/notesnook-logo-png.png'),
type: 'image',
},
{
title: 'Zero Knowledge',
description: 'Write without fear, no tracking.',
icon: SYNC_SVG,
},
{
title: 'Zero Knowledge',
description:
'No sneaking, no stealing. We give all the keys for your data to you. Privacy is not just a word to us. We use industry-grade XChaChaPoly1305 and Argon2 which is miles ahead other solutions making sure your data is secure and private even a million years from now.',
},
];
useEffect(() => {
2021-02-10 21:57:08 +05:00
return;
Storage.read('introCompleted').then(async (r) => {
setVisible(true);
await sleep(500);
requestAnimationFrame(() => {
if (!r) {
timing(opacity, {
toValue: 1,
duration: 500,
easing: Easing.in(Easing.ease),
}).start();
timing(translateY, {
toValue: 0,
duration: 500,
easing: Easing.in(Easing.ease),
}).start();
}
});
2021-02-08 12:55:12 +05:00
});
}, []);
const hide = async () => {
timing(translateY2, {
toValue: dHeight * 2,
duration: 500,
easing: Easing.in(Easing.ease),
}).start();
await sleep(500);
setVisible(false);
};
return (
visible && (
<Animated.View
style={{
zIndex: 999,
2021-02-10 21:57:08 +05:00
...getElevation(10),
2021-02-08 12:55:12 +05:00
width: '100%',
height: '100%',
position: 'absolute',
backgroundColor: colors.bg,
transform: [
{
translateY: translateY2,
},
],
}}>
<Animated.View
style={{
width: '100%',
height: '100%',
justifyContent: 'center',
alignItems: 'center',
padding: 12,
opacity: opacity,
transform: [
{
translateY: translateY,
},
],
}}>
<View
style={{
height: 300,
}}>
<Carousel
ref={carouselRef}
data={features}
itemWidth={dWidth}
sliderWidth={dWidth}
autoplay={false}
loop={false}
2021-02-10 21:57:08 +05:00
shouldOptimizeUpdates
2021-02-08 12:55:12 +05:00
autoplayInterval={5000}
autoplayDelay={3000}
onEndReached={() => {
setIsNext(false);
}}
renderItem={({item, index}) => (
<View
key={item.description}
style={{
paddingVertical: 5,
marginBottom: 10,
alignSelf: 'center',
}}>
<View
style={{
flexWrap: 'wrap',
width: '100%',
alignItems: 'center',
}}>
{item.type === 'image' ? (
<Image
source={item.icon}
style={{
width: 170,
height: 170,
}}
/>
) : (
<SvgXml
xml={
item.icon
? item.icon(colors.accent)
: NOTE_SVG(colors.accent)
}
width={170}
height={170}
/>
)}
{item.title && (
<Heading
size={SIZE.xl}
style={{
textAlign: 'center',
alignSelf: 'center',
marginTop: 10,
}}>
{item.title}
</Heading>
)}
{item.description && (
<Paragraph
size={SIZE.md}
color={colors.icon}
textBreakStrategy="balanced"
style={{
fontWeight: 'normal',
textAlign: 'center',
alignSelf: 'center',
}}>
{item.description}
</Paragraph>
)}
</View>
</View>
)}
/>
</View>
<View
style={{
flexDirection: 'row',
justifyContent: 'space-between',
width: '100%',
position: 'absolute',
bottom: 25,
}}>
{isNext ? (
<View />
) : (
<Button
fontSize={SIZE.md}
onPress={async () => {
await hide();
}}
height={50}
type="grayBg"
style={{paddingHorizontal: 24}}
title="Skip"
/>
)}
<Button
fontSize={SIZE.md}
height={50}
onPress={async () => {
if (isNext) {
carouselRef.current?.snapToNext();
} else {
await hide();
eSendEvent(eOpenLoginDialog, 1);
}
}}
style={{paddingHorizontal: 24}}
type="accent"
title={isNext ? 'Next' : 'Sign Up'}
/>
</View>
</Animated.View>
</Animated.View>
)
);
};
export default SplashScreen;