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

292 lines
9.2 KiB
JavaScript
Raw Normal View History

2021-02-15 12:58:54 +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-15 12:58:54 +05:00
import {SvgXml} from 'react-native-svg';
import {
NOTE_SVG,
SYNC_SVG,
ORGANIZE_SVG,
PRIVACY_SVG,
COMMUNITY_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-15 12:58:54 +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';
2021-02-15 12:58:54 +05:00
import Icon from 'react-native-vector-icons/MaterialCommunityIcons';
import {DDS} from '../../services/DeviceDetection';
import {openLinkInBrowser} from '../../utils/functions';
2021-04-10 08:59:08 +05:00
import {Modal} from 'react-native';
2021-04-11 10:34:01 +05:00
import {SafeAreaView} from 'react-native';
import {SvgToPngView} from '../ListPlaceholders';
2021-06-08 12:26:55 +05:00
import {MMKV} from '../../utils/mmkv';
2021-02-20 15:03:02 +05:00
const features = [
{
title: 'Notesnook',
description: 'A safe place to write and stay organized.',
icon: require('../../assets/images/notesnook-logo-png.png'),
type: 'image',
},
{
title: 'Made to protect your privacy',
description:
'Your data is encrypted on your device. No one but you can read your notes.',
icon: PRIVACY_SVG,
link: 'https://notesnook.com',
2021-06-08 12:26:55 +05:00
img: 'privacy',
2021-02-20 15:03:02 +05:00
},
{
icon: SYNC_SVG,
title: 'While keeping you in sync',
description:
'Everything is automatically synced to all your devices in a safe and secure way. Notesnook is available on all major platforms.',
link: 'https://notesnook.com',
2021-06-08 12:26:55 +05:00
img: 'sync',
2021-02-20 15:03:02 +05:00
},
{
icon: ORGANIZE_SVG,
title: 'And helping you stay organized',
description:
'Add your notes in notebooks and topics or simply assign tags or colors to find them easily.',
link: 'https://notesnook.com',
2021-06-08 12:26:55 +05:00
img: 'sync',
2021-02-20 15:03:02 +05:00
},
{
icon: COMMUNITY_SVG,
title: 'Join our community',
description:
'We are not ghosts, chat with us and share your experience. Give suggestions, report issues and meet other people using Notesnook',
link: 'https://discord.gg/zQBK97EE22',
2021-06-08 12:26:55 +05:00
img: 'community',
2021-02-20 15:03:02 +05:00
},
];
let currentIndex = 0;
2021-02-08 12:55:12 +05:00
const SplashScreen = () => {
const [state, dispatch] = useTracked();
const {colors} = state;
const [visible, setVisible] = useState(false);
const carouselRef = useRef();
const [isNext, setIsNext] = useState(true);
2021-02-08 12:55:12 +05:00
const opacity = useValue(0);
const translateY = useValue(20);
const translateY2 = useValue(0);
2021-02-08 12:55:12 +05:00
useEffect(() => {
2021-06-08 12:26:55 +05:00
MMKV.getStringAsync('introCompleted').then(async r => {
setTimeout(() => {
2021-04-11 14:04:14 +05:00
if (!r) {
2021-02-20 15:03:02 +05:00
setVisible(true);
2021-02-10 21:57:08 +05:00
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-10 21:57:08 +05:00
}
2021-06-08 12:26:55 +05:00
}, 1);
2021-02-08 12:55:12 +05:00
});
}, []);
2021-06-08 12:26:55 +05:00
const hide = async () => {
timing(translateY2, {
toValue: dHeight * 2,
duration: 500,
easing: Easing.in(Easing.ease),
}).start();
await sleep(500);
2021-02-08 12:55:12 +05:00
setVisible(false);
};
return (
visible && (
<Animated.View
style={{
zIndex: 999,
...getElevation(10),
width: '100%',
height: '100%',
position: 'absolute',
backgroundColor: colors.bg,
transform: [
{
translateY: translateY2,
},
],
}}>
2021-04-11 10:34:01 +05:00
<SafeAreaView
2021-02-08 12:55:12 +05:00
style={{
width: '100%',
height: '100%',
2021-04-10 08:59:08 +05:00
backgroundColor: colors.bg,
2021-02-08 12:55:12 +05:00
}}>
2021-04-10 08:59:08 +05:00
<Animated.View
style={{
width: '100%',
height: '100%',
justifyContent: 'center',
alignItems: 'center',
padding: 12,
opacity: opacity,
}}>
<View>
<Carousel
ref={carouselRef}
data={features}
itemWidth={dWidth}
sliderWidth={dWidth}
loop={false}
onSnapToItem={i => {
currentIndex = i;
}}
2021-04-11 10:34:01 +05:00
maxToRenderPerBatch={10}
2021-04-10 08:59:08 +05:00
renderItem={({item, index}) => (
2021-02-08 12:55:12 +05:00
<View
style={{
2021-04-10 08:59:08 +05:00
height: '100%',
justifyContent: 'center',
2021-02-08 12:55:12 +05:00
}}>
2021-02-15 12:58:54 +05:00
<View
2021-04-10 08:59:08 +05:00
key={item.description}
2021-02-15 12:58:54 +05:00
style={{
2021-04-10 08:59:08 +05:00
paddingVertical: 5,
marginBottom: 10,
alignSelf: 'center',
2021-02-15 12:58:54 +05:00
}}>
2021-04-10 08:59:08 +05:00
<View
style={{
flexWrap: 'wrap',
width: '100%',
alignItems: 'center',
}}>
{item.type === 'image' ? (
<Image
source={item.icon}
style={{
width: 170,
height: 170,
}}
/>
) : item.type === 'icon' ? (
<Icon
color={item.color}
name={item.icon}
size={170}
/>
) : (
<SvgXml
xml={
2021-04-10 08:59:08 +05:00
item.icon
? item.icon(colors.accent)
: NOTE_SVG(colors.accent)
}
//img={item.img}
//color={colors.accent}
2021-04-10 08:59:08 +05:00
width={250}
height={250}
/>
)}
2021-02-15 12:58:54 +05:00
2021-04-10 08:59:08 +05:00
{item.title && (
<Heading
size={SIZE.xl}
style={{
textAlign: 'center',
alignSelf: 'center',
marginTop: 10,
}}>
{item.title}
</Heading>
)}
2021-02-08 12:55:12 +05:00
2021-04-10 08:59:08 +05:00
{item.description && (
<Paragraph
size={SIZE.md}
color={colors.icon}
textBreakStrategy="balanced"
style={{
fontWeight: 'normal',
textAlign: 'center',
alignSelf: 'center',
maxWidth: DDS.isTab ? 350 : '80%',
}}>
{item.description}
</Paragraph>
)}
2021-02-08 12:55:12 +05:00
2021-04-10 08:59:08 +05:00
{item.link && (
<Button
title="Learn more"
fontSize={SIZE.md}
onPress={() => {
try {
openLinkInBrowser(item.link, colors);
} catch (e) {
console.log(e, 'ERROR');
}
}}
/>
)}
</View>
2021-02-15 12:58:54 +05:00
</View>
2021-02-08 12:55:12 +05:00
</View>
2021-04-10 08:59:08 +05:00
)}
/>
</View>
2021-02-08 12:55:12 +05:00
2021-04-10 08:59:08 +05:00
<View
style={{
width: '100%',
position: 'absolute',
bottom: 25,
}}>
<Button
fontSize={SIZE.md}
height={50}
2021-06-08 12:26:55 +05:00
width={isNext ? null : DDS.isTab ? 250 : '100%'}
2021-04-10 08:59:08 +05:00
onPress={async () => {
if (isNext) {
carouselRef.current?.snapToItem(
currentIndex + 1,
true,
true,
);
currentIndex++;
if (currentIndex === 4) {
setIsNext(false);
}
} else {
await hide();
await Storage.write('introCompleted', 'true');
}
2021-04-10 08:59:08 +05:00
}}
2021-06-08 12:26:55 +05:00
style={{
paddingHorizontal: 24,
alignSelf: !isNext ? 'center' : 'flex-end',
}}
2021-04-10 08:59:08 +05:00
type="accent"
title={isNext ? 'Next' : 'Start taking notes'}
/>
</View>
</Animated.View>
2021-04-11 10:34:01 +05:00
</SafeAreaView>
</Animated.View>
2021-02-08 12:55:12 +05:00
)
);
};
export default SplashScreen;