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

372 lines
11 KiB
JavaScript
Raw Normal View History

2021-07-29 14:16:47 +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-29 14:16:47 +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,
2021-07-29 14:16:47 +05:00
PRIVATE_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-29 14:16:47 +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';
2022-01-20 00:13:33 +05:00
import umami from '../../utils/umami';
2021-07-29 14:16:47 +05:00
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-29 14:16:47 +05:00
{
title: 'Welcome to Notesnook',
description:
'Did you know that the best note taking apps can secretly read all your notes? But Notesnook is different. How?',
icon: require('../../assets/images/notesnook-logo-png.png'),
type: 'image'
},
2021-02-20 15:03:02 +05:00
{
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-29 14:16:47 +05:00
'All your notes are encrypted on your device. No one except you can read your notes.',
icon: PRIVATE_SVG,
2021-07-25 13:22:03 +05:00
link: 'https://docs.notesnook.com/how-is-my-data-encrypted/',
2021-07-29 14:16:47 +05:00
linkText: 'Learn how we encrypt your data',
2021-07-25 13:22:03 +05:00
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:
2021-07-29 14:16:47 +05:00
'Notesnook works 100% offline and you can install it on all your mobile, tablet and PC. Your notes are always with you where ever you go.',
2021-07-25 13:22:03 +05:00
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-29 14:16:47 +05:00
'Edit your notes the way you want. You can add images, videos, tables and even use markdown.',
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-29 14:16:47 +05:00
linkText: 'Join now',
2021-07-25 13:22:03 +05:00
img: 'community'
2021-07-28 11:57:03 +05:00
},
{
2021-07-29 14:16:47 +05:00
icon: require('../../assets/images/to_the_stars.png'),
title: 'Get started',
2021-07-28 11:57:03 +05:00
description: 'Ready to start taking private notes?',
2021-07-29 14:16:47 +05:00
img: 'community',
type: 'image',
size: 320
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) {
2022-01-20 00:13:33 +05:00
umami.pageView('/welcome', '', []);
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
2021-12-06 12:52:55 +05:00
testID="notesnook.splashscreen"
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-29 14:16:47 +05:00
backgroundColor: colors.nav
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',
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-07-29 14:16:47 +05:00
if (currentIndex === 6) {
setIsNext(false);
}
2021-04-10 08:59:08 +05:00
}}
2021-04-11 10:34:01 +05:00
maxToRenderPerBatch={10}
2021-04-10 08:59:08 +05:00
renderItem={({item, index}) => (
2021-07-29 14:16:47 +05:00
<RenderItem item={item} index={index} />
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-29 14:16:47 +05:00
bottom: 25,
paddingHorizontal: 12
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-29 14:16:47 +05:00
if (currentIndex === 6) {
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);
2022-01-20 00:13:33 +05:00
umami.pageView('/signup', '/welcome');
}
2021-04-10 08:59:08 +05:00
}}
2021-06-08 12:26:55 +05:00
style={{
paddingHorizontal: 24,
2022-01-20 00:13:33 +05:00
alignSelf: 'center'
2021-06-08 12:26:55 +05:00
}}
2021-04-10 08:59:08 +05:00
type="accent"
2021-07-29 14:16:47 +05:00
title={isNext ? 'Next' : 'Sign up'}
2021-04-10 08:59:08 +05:00
/>
2021-09-14 11:15:04 +05:00
{isNext ? null : (
<Button
fontSize={SIZE.md}
height={50}
width={DDS.isTab ? 350 : '100%'}
2021-09-14 11:15:04 +05:00
onPress={async () => {
await hide();
await MMKV.setItem('introCompleted', 'true');
2022-01-20 00:13:33 +05:00
umami.pageView('/home', '/welcome');
2021-09-14 11:15:04 +05:00
}}
style={{
paddingHorizontal: 24,
2022-01-20 00:13:33 +05:00
alignSelf: 'center',
2021-09-14 11:15:04 +05:00
marginTop: 10
}}
type="grayBg"
buttonType={{
color: '#808080',
selected: '#808080',
2022-01-20 00:13:33 +05:00
opacity: 0.15
2021-09-14 11:15:04 +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;
2021-07-29 14:16:47 +05:00
const RenderItem = ({item, index}) => {
const [state] = useTracked();
const {colors} = state;
const translateY = useValue(0);
const dimensions = useSettingStore(state => state.dimensions);
let itemWidth = dimensions.width > 400 ? 320 : 260;
useEffect(() => {
if (index === 0) return;
let value = 0;
setInterval(() => {
value = value === 0 ? 5 : 0;
timing(translateY, {
toValue: value,
duration: 2000,
easing: Easing.inOut(Easing.ease)
}).start();
}, 2000);
}, []);
return (
<View
style={{
justifyContent: 'center',
backgroundColor: colors.bg,
alignSelf: 'center',
width: '90%',
borderBottomRightRadius: 10,
borderBottomLeftRadius: 10,
height: '80%'
}}>
<View
key={item.description}
style={{
paddingVertical: 5,
marginBottom: 10,
alignSelf: 'center'
}}>
<View
style={{
flexWrap: 'wrap',
width: '100%',
alignItems: 'center'
}}>
<Animated.View
style={{
transform: [
{
translateY: translateY
}
]
}}>
{item.type === 'image' ? (
<Image
source={item.icon}
style={{
width: item.size || 170,
height: item.size || 170
}}
/>
) : item.type === 'icon' ? (
<Icon color={item.color} name={item.icon} size={170} />
) : (
<SvgXml
xml={
item.icon ? item.icon(colors.accent) : NOTE_SVG(colors.accent)
}
width={itemWidth}
height={itemWidth}
/>
)}
</Animated.View>
{item.title && (
<Heading
size={SIZE.xxl}
textBreakStrategy="balanced"
style={{
textAlign: 'center',
alignSelf: 'center',
marginTop: 10,
maxWidth: '90%',
marginBottom: 10
}}>
{item.title}
</Heading>
)}
{item.description && (
<Paragraph
size={SIZE.md}
style={{
fontWeight: 'normal',
textAlign: 'center',
alignSelf: 'center',
maxWidth: DDS.isTab ? 350 : '90%',
lineHeight: SIZE.md + 7
}}>
{item.description}
</Paragraph>
)}
{item.link && (
<Button
title={item.linkText || 'Learn more'}
fontSize={SIZE.md}
onPress={() => {
try {
openLinkInBrowser(item.link, colors);
} catch (e) {
console.log(e, 'ERROR');
}
}}
/>
)}
</View>
</View>
</View>
);
};