diff --git a/apps/mobile/App.js b/apps/mobile/App.js index 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,19 +9,49 @@ 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(() => { + if (Platform.OS === 'android') { + StatusBar.setBackgroundColor('transparent'); + StatusBar.setTranslucent(true); + StatusBar.setBarStyle('dark-content'); + } + }, []); + + useEffect(() => { + DeviceEventEmitter.addListener('openSidebar', () => { + setSidebar('30%'); + }); + DeviceEventEmitter.addListener('closeSidebar', () => { + setSidebar('0%'); + }); + + return () => { + DeviceEventEmitter.removeListener('openSidebar', () => { + setSidebar('30%'); + }); + DeviceEventEmitter.removeListener('closeSidebar', () => { + setSidebar('0%'); + }); + }; + }, []); + useEffect(() => { DeviceEventEmitter.addListener('hide', () => { setFab(false); @@ -29,18 +59,7 @@ const App = () => { DeviceEventEmitter.addListener('show', () => { setFab(true); }); - DeviceEventEmitter.addListener('openSidebar', () => { - setSidebar('30%'); - }); - DeviceEventEmitter.addListener('closeSidebar', () => { - setSidebar('0%'); - }); - if (Platform.OS === 'android') { - StatusBar.setBackgroundColor('transparent'); - StatusBar.setTranslucent(true); - StatusBar.setBarStyle('dark-content'); - } return () => { DeviceEventEmitter.removeListener('hide', () => { setFab(false); @@ -48,12 +67,6 @@ const App = () => { DeviceEventEmitter.removeListener('show', () => { setFab(true); }); - DeviceEventEmitter.removeListener('openSidebar', () => { - setSidebar('30%'); - }); - DeviceEventEmitter.removeListener('closeSidebar', () => { - setSidebar('0%'); - }); }; }, []); @@ -80,8 +93,8 @@ const App = () => { : undefined ) : ( - undefined - )} + undefined + )} { }} /> + + {fab ? ( { ) : ( - undefined - )} + undefined + )} ); }; - - 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.js new file mode 100644 index 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 ( + + Hello + + ); +}; diff --git a/apps/mobile/src/utils/utils.js b/apps/mobile/src/utils/utils.js index 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.js index 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';