A fully open source & end-to-end encrypted note taking alternative to Evernote.
TypeScript asp-net-coredotnet-coreelectronfosshacktoberfestnote-managmentnote-takingnote-taking-appnotebooknotesnotes-appopen-sourceopensourceprivacyproductivityreactreact-nativereactjsself-hosted
feat: add custom toast
ammarahm-ede34b0db8295b
diff --git a/apps/mobile/App.js b/apps/mobile/App.jsindex 1259efe52..d10d6059b 100644--- a/apps/mobile/App.js+++ b/apps/mobile/App.js@@ -1,4 +1,4 @@-import React, { useState, useEffect } from 'react';+import React, {useState, useEffect} from 'react';import NavigationService, {AppContainer,} from './src/services/NavigationService';@@ -9,26 +9,32 @@ import {TouchableOpacity,DeviceEventEmitter,Platform,+ Text,} from 'react-native';-import { COLOR_SCHEME, SIZE, opacity, WEIGHT } from './src/common/common';+import {COLOR_SCHEME, SIZE, opacity, WEIGHT, pv, ph} from './src/common/common';import Icon from 'react-native-vector-icons/Ionicons';import ActionButton from 'react-native-action-button';import Storage from 'notes-core/api/database';import StorageInterface from './src/utils/storage';-import { RenderSideMenu } from './src/views/Home';+import {RenderSideMenu} from './src/views/Home';import * as Animatable from 'react-native-animatable';+import {h} from './src/utils/utils';+import {Toast} from './src/components/Toast';+const App = () => {const [colors, setColors] = useState(COLOR_SCHEME);const [fab, setFab] = useState(true);const [sidebar, setSidebar] = useState('30%');useEffect(() => {- DeviceEventEmitter.addListener('hide', () => {- setFab(false);- });- DeviceEventEmitter.addListener('show', () => {- setFab(true);- });+ if (Platform.OS === 'android') {+ StatusBar.setBackgroundColor('transparent');+ StatusBar.setTranslucent(true);+ StatusBar.setBarStyle('dark-content');+ }+ }, []);++ useEffect(() => {DeviceEventEmitter.addListener('openSidebar', () => {setSidebar('30%');});@@ -36,18 +42,7 @@ const App = () => {setSidebar('0%');});- if (Platform.OS === 'android') {- StatusBar.setBackgroundColor('transparent');- StatusBar.setTranslucent(true);- StatusBar.setBarStyle('dark-content');- }return () => {- DeviceEventEmitter.removeListener('hide', () => {- setFab(false);- });- DeviceEventEmitter.removeListener('show', () => {- setFab(true);- });DeviceEventEmitter.removeListener('openSidebar', () => {setSidebar('30%');});@@ -57,6 +52,24 @@ const App = () => {};}, []);+ useEffect(() => {+ DeviceEventEmitter.addListener('hide', () => {+ setFab(false);+ });+ DeviceEventEmitter.addListener('show', () => {+ setFab(true);+ });++ return () => {+ DeviceEventEmitter.removeListener('hide', () => {+ setFab(false);+ });+ DeviceEventEmitter.removeListener('show', () => {+ setFab(true);+ });+ };+ }, []);+return (<Viewstyle={{@@ -80,8 +93,8 @@ const App = () => {: undefined</Animatable.View>) : (- undefined- )}+ undefined+ )}<AppContainerstyle={{@@ -93,6 +106,8 @@ const App = () => {}}/>+ <Toast />+{fab ? (<ActionButton elevation={5} buttonColor={colors.accent}><ActionButton.Item@@ -137,14 +152,12 @@ const App = () => {</ActionButton.Item></ActionButton>) : (- undefined- )}+ undefined+ )}</View>);};--export default App;export const storage = new Storage(StorageInterface);diff --git a/apps/mobile/src/components/Toast/index.js b/apps/mobile/src/components/Toast/index.jsnew file mode 100644index 000000000..ea0d97dff--- /dev/null+++ b/apps/mobile/src/components/Toast/index.js@@ -0,0 +1,96 @@+import React, {useState, useEffect} from 'react';++import {DeviceEventEmitter, Text} from 'react-native';+import {COLOR_SCHEME, SIZE, opacity, WEIGHT, pv, ph} from '../../common/common';+import Icon from 'react-native-vector-icons/Feather';+import * as Animatable from 'react-native-animatable';+import {h} from '../../utils/utils';++export const Toast = () => {+ const [colors, setColors] = useState(COLOR_SCHEME);+ const [toast, setToast] = useState(false);+ const [toastStyle, setToastStyle] = useState({+ backgroundColor: colors.errorBg,+ color: colors.errorText,+ });++ useEffect(() => {+ DeviceEventEmitter.addListener('showToast', data => {+ setToast(true);++ if (data.type === 'success') {+ setToastStyle({+ backgroundColor: colors.successBg,+ color: colors.successText,+ });+ } else {+ setToastStyle({+ backgroundColor: colors.errorBg,+ color: colors.errorText,+ });+ }++ setTimeout(() => {+ setToast(false);+ }, data.duration || 1000);+ });+ DeviceEventEmitter.addListener('hideToast', data => {+ setToast(false);+ });++ return () => {+ DeviceEventEmitter.removeListener('showToast', data => {+ setToast(true);+ if (data.type === 'success') {+ setToastStyle({+ backgroundColor: colors.successBg,+ color: colors.successText,+ });+ } else {+ setToastStyle({+ backgroundColor: colors.errorBg,+ color: colors.errorText,+ });+ }++ setTimeout(() => {+ setToast(false);+ }, data.duration || 1000);+ });++ DeviceEventEmitter.removeListener('hideToast', data => {+ setToast(false);+ });+ };+ }, []);++ return (+ <Animatable.View+ transition="translateY"+ duration={250}+ useNativeDriver={true}+ style={{+ ...toastStyle,+ height: 55,+ width: '90%',+ marginHorizontal: '5%',+ marginBottom: h * 0.025,+ position: 'absolute',+ bottom: 0,+ fontFamily: WEIGHT.regular,+ fontSize: SIZE.md,+ zIndex: 999,+ borderRadius: 5,+ paddingHorizontal: ph,+ justifyContent: 'center',+ elevation: 10,+ transform: [+ {+ translateY: toast ? 0 : 150,+ },+ ],+ }}>+ <Text>Hello</Text>+ </Animatable.View>+ );+};diff --git a/apps/mobile/src/utils/utils.js b/apps/mobile/src/utils/utils.jsindex 0a49dc7f0..e779823ea 100755--- a/apps/mobile/src/utils/utils.js+++ b/apps/mobile/src/utils/utils.js@@ -1,4 +1,4 @@-import {Dimensions} from 'react-native';+import {Dimensions, DeviceEventEmitter} from 'react-native';export const getElevation = elevation => {return {elevation,@@ -38,3 +38,12 @@ export function timeSince(date) {export const w = Dimensions.get('window').width;export const h = Dimensions.get('window').height;++export const ToastEvent = {+ show: (message, type, duration = 1000, func = null) => {+ DeviceEventEmitter.emit('showToast', {message, type, duration, func});+ },+ hide: (message, type, duration = 1000, func = null) => {+ DeviceEventEmitter.emit('hideToast', {message, type, duration, func});+ },+};diff --git a/apps/mobile/src/views/Home/index.js b/apps/mobile/src/views/Home/index.jsindex 142e2b128..04ccec486 100755--- a/apps/mobile/src/views/Home/index.js+++ b/apps/mobile/src/views/Home/index.js@@ -29,7 +29,7 @@ import Icon from 'react-native-vector-icons/Feather';import {Search} from '../../components/SearchInput';import {Reminder} from '../../components/Reminder';import {RecentList} from '../../components/Recents';-import {getElevation, w, h} from '../../utils/utils';+import {getElevation, w, h, Toast} from '../../utils/utils';import {Header} from '../../components/header';import {tsPropertySignature} from '@babel/types';import {NavigationEvents} from 'react-navigation';