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

314 lines
10 KiB
JavaScript
Raw Normal View History

2021-07-28 11:57:03 +05:00
import React, { useEffect, useRef, useState } from 'react';
import { Image, SafeAreaView, 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-07-28 11:57:03 +05:00
import { SvgXml } from 'react-native-svg';
2021-06-26 08:47:52 +05:00
import Icon from 'react-native-vector-icons/MaterialCommunityIcons';
2021-02-15 12:58:54 +05:00
import {
2021-06-26 08:47:52 +05:00
COMMUNITY_SVG,
2021-02-15 12:58:54 +05:00
NOTE_SVG,
ORGANIZE_SVG,
PRIVACY_SVG,
2021-07-25 13:22:03 +05:00
RICH_TEXT_SVG,
SYNC_SVG
2021-02-15 12:58:54 +05:00
} from '../../assets/images/assets';
2021-07-28 11:57:03 +05:00
import { useTracked } from '../../provider';
import { useSettingStore } from '../../provider/stores';
import { DDS } from '../../services/DeviceDetection';
import { eSendEvent } from '../../services/EventManager';
import { dHeight, dWidth, getElevation } from '../../utils';
import { eOpenLoginDialog } from '../../utils/Events';
import { openLinkInBrowser } from '../../utils/functions';
import { MMKV } from '../../utils/mmkv';
import { SIZE } from '../../utils/SizeUtils';
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-20 15:03:02 +05:00
const features = [
{
2021-07-28 11:57:03 +05:00
title: '100% end-to-end encrypted notes',
2021-02-20 15:03:02 +05:00
description:
2021-07-25 13:22:03 +05:00
'Your data is encrypted on your device. No one except you can read your notes.',
2021-02-20 15:03:02 +05:00
icon: PRIVACY_SVG,
2021-07-25 13:22:03 +05:00
link: 'https://docs.notesnook.com/how-is-my-data-encrypted/',
img: 'privacy'
2021-02-20 15:03:02 +05:00
},
{
icon: SYNC_SVG,
2021-07-25 13:22:03 +05:00
title: 'Sync to unlimited devices',
description:
'You can download Notesnook on your laptop/pc, tablet and mobile. Your notes are with you where ever you go.',
link: 'https://notesnook.com',
img: 'sync'
},
{
icon: RICH_TEXT_SVG,
title: 'Write better. Faster. Smarter.',
2021-02-20 15:03:02 +05:00
description:
2021-07-25 13:22:03 +05:00
'Edit your notes the way you want. You can add images, videos, tables and so much more.',
2021-02-20 15:03:02 +05:00
link: 'https://notesnook.com',
2021-07-25 13:22:03 +05:00
img: 'sync'
2021-02-20 15:03:02 +05:00
},
{
icon: ORGANIZE_SVG,
2021-07-25 13:22:03 +05:00
title: 'Organize to remember, not to put away',
2021-02-20 15:03:02 +05:00
description:
2021-07-25 13:22:03 +05:00
'With notebooks, tags and colors you can find your notes easily.',
2021-02-20 15:03:02 +05:00
link: 'https://notesnook.com',
2021-07-25 13:22:03 +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-07-25 13:22:03 +05:00
img: 'community'
2021-07-28 11:57:03 +05:00
},
{
title: 'Welcome to Notesnook',
description: 'Ready to start taking private notes?',
icon: require('../../assets/images/notesnook-logo-png.png'),
type: 'image'
2021-07-25 13:22:03 +05:00
}
2021-02-20 15:03:02 +05:00
];
let currentIndex = 0;
2021-02-08 12:55:12 +05:00
const SplashScreen = () => {
2021-07-28 11:57:03 +05:00
const [state] = useTracked();
2021-02-08 12:55:12 +05:00
const {colors} = state;
const carouselRef = useRef();
const [isNext, setIsNext] = useState(true);
2021-06-26 08:47:52 +05:00
const isIntroCompleted = useSettingStore(state => state.isIntroCompleted);
const setIntroCompleted = useSettingStore(state => state.setIntroCompleted);
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-26 08:47:52 +05:00
if (!isIntroCompleted) {
setTimeout(() => {
2021-06-26 08:47:52 +05:00
timing(opacity, {
toValue: 1,
duration: 500,
2021-07-25 13:22:03 +05:00
easing: Easing.in(Easing.ease)
2021-06-26 08:47:52 +05:00
}).start();
timing(translateY, {
toValue: 0,
duration: 500,
2021-07-25 13:22:03 +05:00
easing: Easing.in(Easing.ease)
2021-06-26 08:47:52 +05:00
}).start();
}, 15);
}
}, [isIntroCompleted]);
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,
2021-07-25 13:22:03 +05:00
easing: Easing.in(Easing.ease)
}).start();
await sleep(500);
2021-06-26 08:47:52 +05:00
setIntroCompleted(true);
2021-02-08 12:55:12 +05:00
};
return (
2021-06-26 08:47:52 +05:00
!isIntroCompleted && (
<Animated.View
style={{
zIndex: 999,
...getElevation(10),
width: '100%',
height: '100%',
position: 'absolute',
backgroundColor: colors.bg,
transform: [
{
2021-07-25 13:22:03 +05:00
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-07-25 13:22:03 +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,
2021-07-25 13:22:03 +05:00
opacity: opacity
2021-04-10 08:59:08 +05:00
}}>
<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%',
2021-07-25 13:22:03 +05:00
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,
2021-07-25 13:22:03 +05:00
alignSelf: 'center'
2021-02-15 12:58:54 +05:00
}}>
2021-04-10 08:59:08 +05:00
<View
style={{
flexWrap: 'wrap',
width: '100%',
2021-07-25 13:22:03 +05:00
alignItems: 'center'
2021-04-10 08:59:08 +05:00
}}>
{item.type === 'image' ? (
<Image
source={item.icon}
style={{
width: 170,
2021-07-25 13:22:03 +05:00
height: 170
2021-04-10 08:59:08 +05:00
}}
/>
) : 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)
}
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',
2021-07-28 11:57:03 +05:00
marginTop: 10,
maxWidth: '90%'
2021-04-10 08:59:08 +05:00
}}>
{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',
2021-07-25 13:22:03 +05:00
maxWidth: DDS.isTab ? 350 : '80%'
2021-04-10 08:59:08 +05:00
}}>
{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',
2021-07-25 13:22:03 +05:00
bottom: 25
2021-04-10 08:59:08 +05:00
}}>
<Button
fontSize={SIZE.md}
height={50}
2021-07-25 13:22:03 +05:00
width={DDS.isTab ? 350 : '100%'}
2021-04-10 08:59:08 +05:00
onPress={async () => {
if (isNext) {
carouselRef.current?.snapToItem(
currentIndex + 1,
true,
2021-07-25 13:22:03 +05:00
true
2021-04-10 08:59:08 +05:00
);
currentIndex++;
2021-07-25 13:22:03 +05:00
if (currentIndex === 5) {
2021-04-10 08:59:08 +05:00
setIsNext(false);
}
} else {
await hide();
2021-07-28 11:57:03 +05:00
await MMKV.setItem('introCompleted', 'true');
2021-07-25 13:22:03 +05:00
await sleep(300);
eSendEvent(eOpenLoginDialog, 1);
}
2021-04-10 08:59:08 +05:00
}}
2021-06-08 12:26:55 +05:00
style={{
paddingHorizontal: 24,
2021-07-25 13:22:03 +05:00
alignSelf: !isNext ? 'center' : 'flex-end'
2021-06-08 12:26:55 +05:00
}}
2021-04-10 08:59:08 +05:00
type="accent"
2021-07-25 13:22:03 +05:00
title={isNext ? 'Next' : 'Start your 14 day free trial'}
2021-04-10 08:59:08 +05:00
/>
2021-07-25 13:22:03 +05:00
{isNext ? null : (
<Button
fontSize={SIZE.md}
height={50}
width={DDS.isTab ? 350 : '100%'}
onPress={async () => {
await hide();
2021-07-28 11:57:03 +05:00
await MMKV.setItem('introCompleted', 'true');
2021-07-25 13:22:03 +05:00
}}
style={{
paddingHorizontal: 24,
alignSelf: !isNext ? 'center' : 'flex-end',
marginTop: 10
}}
2021-07-28 11:57:03 +05:00
type="grayBg"
2021-07-25 13:22:03 +05:00
title="I want to try the app first"
/>
)}
2021-04-10 08:59:08 +05:00
</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;