Skip to content

A fully open source & end-to-end encrypted note taking alternative to Evernote.

shift theme loading to context

ammarahm-edfd0f4f599815
diff --git a/apps/mobile/App.js b/apps/mobile/App.js
index 96ff418d0..2a6e59a72 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, useContext} from 'react';
import NavigationService, {
AppContainer,
} from './src/services/NavigationService';
@@ -15,6 +15,7 @@ import {
onThemeUpdate,
clearThemeUpdateListener,
getColorScheme,
+ COLOR_SCHEME_DARK,
} from './src/common/common';
import Icon from 'react-native-vector-icons/Ionicons';
import ActionButton from 'react-native-action-button';
@@ -25,14 +26,16 @@ import {Menu} from './src/components/Menu';
import SideMenu from 'react-native-side-menu';
import Storage from 'notes-core/api/database';
import StorageInterface from './src/utils/storage';
-import {AppProvider} from './src/provider';
+import {AppProvider, AppContext} from './src/provider';
import {DeviceDetectionService} from './src/utils/deviceDetection';
+import {useAppContext} from './src/provider/useAppContext';
export const DDS = new DeviceDetectionService();
export const db = new Storage(StorageInterface);
const App = () => {
- const [colors, setColors] = useState(COLOR_SCHEME);
+ const {colors} = useAppContext();
+
const [fab, setFab] = useState(true);
const [sidebar, setSidebar] = useState(w * 0.3);
const [isOpen, setOpen] = useState(false);
@@ -40,10 +43,6 @@ const App = () => {
const [buttonHide, setButtonHide] = useState(false);
const [isIntialized, setIsInitialized] = useState(false);
- useEffect(() => {
- getColorScheme(colors);
- }, []);
-
useEffect(() => {
DeviceEventEmitter.addListener('openSidebar', () => {
DDS.isTab ? setSidebar(w * 0.3) : setOpen(true);
@@ -125,17 +124,6 @@ const App = () => {
}
}, []);
- useEffect(() => {
- onThemeUpdate(() => {
- StatusBar.setBarStyle(colors.night ? 'light-content' : 'dark-content');
- });
- return () => {
- clearThemeUpdateListener(() => {
- StatusBar.setBarStyle(colors.night ? 'light-content' : 'dark-content');
- });
- };
- }, []);
-
useEffect(() => {
db.init().then(() => {
setIsInitialized(true);
@@ -187,6 +175,7 @@ const App = () => {
bounceBackOnOverdraw={false}
contentContainerStyle={{
opacity: 0,
+ backgroundColor: colors.bg,
}}
animationFunction={(prop, value) =>
Animated.spring(prop, {
@@ -212,6 +201,7 @@ const App = () => {
style={{
width: DDS.isTab ? '70%' : '100%',
height: '100%',
+ backgroundColor: colors.bg,
}}
ref={navigatorRef => {
NavigationService.setTopLevelNavigator(navigatorRef);
diff --git a/apps/mobile/src/common/common.js b/apps/mobile/src/common/common.js
index 68e463d06..78c9e4769 100755
--- a/apps/mobile/src/common/common.js
+++ b/apps/mobile/src/common/common.js
@@ -1,5 +1,6 @@
import {DeviceEventEmitter, StatusBar, PixelRatio} from 'react-native';
import AsyncStorage from '@react-native-community/async-storage';
+import {useAppContext} from '../provider/useAppContext';
//COLOR SCHEME
export const ACCENT = {
color: '#0560FF',
@@ -17,37 +18,39 @@ export function setColorScheme(colors = COLOR_SCHEME, accent = ACCENT.color) {
COLOR_SCHEME.icon = colors.icon;
DeviceEventEmitter.emit('onThemeUpdate');
+
+ return COLOR_SCHEME;
}
-export function getColorScheme(colors) {
- let theme = colors;
- AsyncStorage.getItem('accentColor').then(accentColor => {
- if (typeof accentColor !== 'string') {
- AsyncStorage.setItem('accentColor', colors.accent);
- } else {
- setAccentColor(accentColor);
- }
- });
- AsyncStorage.getItem('theme').then(t => {
- if (typeof t !== 'string') {
- AsyncStorage.setItem('theme', JSON.stringify(theme));
-
- setColorScheme(COLOR_SCHEME_LIGHT);
- } else {
- let themeToSet = JSON.parse(t);
- themeToSet.night
- ? setColorScheme(COLOR_SCHEME_DARK)
- : setColorScheme(COLOR_SCHEME_LIGHT);
- StatusBar.setBarStyle(
- themeToSet.night ? 'light-content' : 'dark-content',
- );
- }
- });
+export async function getColorScheme(colors) {
+ let accentColor = await AsyncStorage.getItem('accentColor');
+ let t = await AsyncStorage.getItem('theme');
+
+ if (typeof accentColor !== 'string') {
+ AsyncStorage.setItem('accentColor', colors.accent);
+ } else {
+ setAccentColor(accentColor);
+ }
+
+ if (typeof t !== 'string') {
+ AsyncStorage.setItem('theme', JSON.stringify(colors));
+ setColorScheme(COLOR_SCHEME_LIGHT);
+ } else {
+ let themeToSet = JSON.parse(t);
+ themeToSet.night
+ ? setColorScheme(COLOR_SCHEME_DARK)
+ : setColorScheme(COLOR_SCHEME_LIGHT);
+ StatusBar.setBarStyle(themeToSet.night ? 'light-content' : 'dark-content');
+ }
+
+ DeviceEventEmitter.emit('onThemeUpdate');
+ return COLOR_SCHEME;
}
export function setAccentColor(color) {
ACCENT.color = color;
- DeviceEventEmitter.emit('onThemeUpdate');
+
+ return ACCENT;
}
export const onThemeUpdate = (func = () => {}) => {
diff --git a/apps/mobile/src/components/AddNotebookDialog/index.js b/apps/mobile/src/components/AddNotebookDialog/index.js
index 6544b5185..317be9ae4 100644
--- a/apps/mobile/src/components/AddNotebookDialog/index.js
+++ b/apps/mobile/src/components/AddNotebookDialog/index.js
@@ -28,11 +28,12 @@ import {getElevation, h, w, timeSince, ToastEvent} from '../../utils/utils';
import {FlatList, TextInput} from 'react-native-gesture-handler';
import {useForceUpdate} from '../../views/ListsEditor';
import {db, DDS} from '../../../App';
+import {useAppContext} from '../../provider/useAppContext';
let refs = [];
export const AddNotebookDialog = ({visible, close}) => {
- const [colors, setColors] = useState(COLOR_SCHEME);
+ const {colors} = useAppContext();
const [topics, setTopics] = useState(['']);
const [title, setTitle] = useState(null);
const forceUpdate = useForceUpdate();
diff --git a/apps/mobile/src/components/AddTopicDialog/index.js b/apps/mobile/src/components/AddTopicDialog/index.js
index dc5a69abe..9df6bfa67 100644
--- a/apps/mobile/src/components/AddTopicDialog/index.js
+++ b/apps/mobile/src/components/AddTopicDialog/index.js
@@ -27,6 +27,7 @@ import {getElevation, h, w, timeSince, ToastEvent} from '../../utils/utils';
import {FlatList, TextInput} from 'react-native-gesture-handler';
import {useForceUpdate} from '../../views/ListsEditor';
import {db} from '../../../App';
+import {useAppContext} from '../../provider/useAppContext';
export const AddTopicDialog = ({
visible,
@@ -34,7 +35,7 @@ export const AddTopicDialog = ({
notebookID,
toEdit = null,
}) => {
- const [colors, setColors] = useState(COLOR_SCHEME);
+ const {colors} = useAppContext();
const [topics, setTopics] = useState(['']);
const forceUpdate = useForceUpdate();
const setTitleRef = createRef();
diff --git a/apps/mobile/src/components/Dialog/index.js b/apps/mobile/src/components/Dialog/index.js
index b1bcb7396..9e07f95a1 100644
--- a/apps/mobile/src/components/Dialog/index.js
+++ b/apps/mobile/src/components/Dialog/index.js
@@ -14,6 +14,7 @@ import {
} from '../../common/common';
import Icon from 'react-native-vector-icons/Feather';
import {getElevation} from '../../utils/utils';
+import {useAppContext} from '../../provider/useAppContext';
export const Dialog = ({
title,
@@ -25,7 +26,7 @@ export const Dialog = ({
close = () => {},
positivePress = () => {},
}) => {
- const [colors, setColors] = useState(COLOR_SCHEME);
+ const {colors} = useAppContext();
return (
<Modal
diff --git a/apps/mobile/src/components/EditorMenu/index.js b/apps/mobile/src/components/EditorMenu/index.js
index 16ee579a2..21dbfa6e4 100644
--- a/apps/mobile/src/components/EditorMenu/index.js
+++ b/apps/mobile/src/components/EditorMenu/index.js
@@ -35,28 +35,18 @@ import AsyncStorage from '@react-native-community/async-storage';
import {useForceUpdate} from '../../views/ListsEditor';
import {AnimatedSafeAreaView} from '../../views/Home';
import {TextInput} from 'react-native-gesture-handler';
+import {useAppContext} from '../../provider/useAppContext';
let tagsInputRef;
export const EditorMenu = ({close = () => {}, hide, update = () => {}}) => {
- const [colors, setColors] = useState(COLOR_SCHEME);
+ const {colors} = useAppContext();
const forceUpdate = useForceUpdate();
const [tags, setTags] = useState([]);
const [selectedColor, setSelectedColor] = useState([]);
let tagToAdd = null;
let backPressCount = 0;
- useEffect(() => {
- onThemeUpdate(() => {
- forceUpdate();
- });
- return () => {
- clearThemeUpdateListener(() => {
- forceUpdate();
- });
- };
- }, []);
-
return (
<AnimatedSafeAreaView
transition={['backgroundColor', 'opacity']}
diff --git a/apps/mobile/src/components/ListItem/index.js b/apps/mobile/src/components/ListItem/index.js
index 83d773974..dde1fef20 100644
--- a/apps/mobile/src/components/ListItem/index.js
+++ b/apps/mobile/src/components/ListItem/index.js
@@ -13,10 +13,11 @@ import {
import Icon from 'react-native-vector-icons/Ionicons';
import {getElevation} from '../../utils/utils';
import {FlatList} from 'react-native-gesture-handler';
+import {useAppContext} from '../../provider/useAppContext';
const w = Dimensions.get('window').width;
const h = Dimensions.get('window').height;
export const ListItem = props => {
- const [colors, setColors] = useState(COLOR_SCHEME);
+ const {colors} = useAppContext();
return (
<View
diff --git a/apps/mobile/src/components/Menu/index.js b/apps/mobile/src/components/Menu/index.js
index 362c56265..4cbd7f3a8 100644
--- a/apps/mobile/src/components/Menu/index.js
+++ b/apps/mobile/src/components/Menu/index.js
@@ -33,21 +33,10 @@ import {getElevation, w, h, Toast} from '../../utils/utils';
import AsyncStorage from '@react-native-community/async-storage';
import {useForceUpdate} from '../../views/ListsEditor';
import {AnimatedSafeAreaView} from '../../views/Home';
+import {useAppContext} from '../../provider/useAppContext';
export const Menu = ({close = () => {}, hide, update = () => {}}) => {
- const [colors, setColors] = useState(COLOR_SCHEME);
- const forceUpdate = useForceUpdate();
-
- useEffect(() => {
- onThemeUpdate(() => {
- forceUpdate();
- });
- return () => {
- clearThemeUpdateListener(() => {
- forceUpdate();
- });
- };
- }, []);
+ const {colors, changeColorScheme} = useAppContext();
return (
<AnimatedSafeAreaView
@@ -113,13 +102,14 @@ export const Menu = ({close = () => {}, hide, update = () => {}}) => {
'theme',
JSON.stringify(COLOR_SCHEME_DARK),
);
- setColorScheme(COLOR_SCHEME_DARK);
+ changeColorScheme(COLOR_SCHEME_DARK);
} else {
AsyncStorage.setItem(
'theme',
JSON.stringify(COLOR_SCHEME_LIGHT),
);
- setColorScheme(COLOR_SCHEME_LIGHT);
+
+ changeColorScheme(COLOR_SCHEME_LIGHT);
}
},
switch: true,
diff --git a/apps/mobile/src/components/NoteItem/index.js b/apps/mobile/src/components/NoteItem/index.js
index 063baed06..77401b483 100644
--- a/apps/mobile/src/components/NoteItem/index.js
+++ b/apps/mobile/src/components/NoteItem/index.js
@@ -11,11 +11,12 @@ import {Dialog} from '../Dialog';
import {VaultDialog} from '../VaultDialog';
import {db} from '../../../App';
import {DDS} from '../../../App';
+import {useAppContext} from '../../provider/useAppContext';
const w = Dimensions.get('window').width;
const h = Dimensions.get('window').height;
const NoteItem = props => {
- const [colors, setColors] = useState(COLOR_SCHEME);
+ const {colors} = useAppContext();
const [visible, setVisible] = useState(false);
const [vaultDialog, setVaultDialog] = useState(false);
const item = props.item;
diff --git a/apps/mobile/src/components/NotebookItem/index.js b/apps/mobile/src/components/NotebookItem/index.js
index d72257859..4bb6ee5b1 100644
--- a/apps/mobile/src/components/NotebookItem/index.js
+++ b/apps/mobile/src/components/NotebookItem/index.js
@@ -16,6 +16,7 @@ import {w, ToastEvent} from '../../utils/utils';
import {db} from '../../../App';
import {Dialog} from '../Dialog';
import {AddTopicDialog} from '../AddTopicDialog';
+import {useAppContext} from '../../provider/useAppContext';
export const NotebookItem = ({
item,
index,
@@ -28,7 +29,7 @@ export const NotebookItem = ({
numColumns,
refresh = () => {},
}) => {
- const [colors, setColors] = useState(COLOR_SCHEME);
+ const {colors} = useAppContext();
const [isVisible, setVisible] = useState(false);
const [addTopic, setAddTopic] = useState(false);
let setMenuRef = {};
diff --git a/apps/mobile/src/components/NotesList/index.js b/apps/mobile/src/components/NotesList/index.js
index 43bb29f2b..c2dba91c7 100644
--- a/apps/mobile/src/components/NotesList/index.js
+++ b/apps/mobile/src/components/NotesList/index.js
@@ -1,11 +1,19 @@
import React, {useState} from 'react';
-import {View, Text, FlatList, Platform, TouchableOpacity} from 'react-native';
+import {
+ View,
+ Text,
+ FlatList,
+ Platform,
+ TouchableOpacity,
+ SectionList,
+} from 'react-native';
import Icon from 'react-native-vector-icons/Feather';
import {COLOR_SCHEME, SIZE, WEIGHT, ph} from '../../common/common';
import * as Animatable from 'react-native-animatable';
import NoteItem from '../NoteItem';
import {DDS} from '../../../App';
import {w, h} from '../../utils/utils';
+import {useAppContext} from '../../provider/useAppContext';
export const NotesList = ({
keyword = null,
notes,
@@ -13,7 +21,7 @@ export const NotesList = ({
onScroll,
isSearch = false,
}) => {
- const [colors, setColors] = useState(COLOR_SCHEME);
+ const {colors} = useAppContext();
const [numColumns, setNumColumns] = useState(1);
return (
<FlatList
@@ -43,59 +51,92 @@ export const NotesList = ({
ListHeaderComponent={
<View
style={{
- marginTop: margin + 20,
- flexDirection: 'row',
- justifyContent: 'space-between',
- width:
- numColumns === 2
- ? DDS.isTab
- ? w * 0.7 * 0.95
- : w * 0.95
- : w * 0.95,
- alignSelf: 'center',
- marginLeft:
- numColumns === 2 ? (DDS.isTab ? w * 0.7 * 0.025 : 0) : 0,
- paddingHorizontal: ph + 5,
+ marginTop: margin,
+ }}></View>
+ }
+ numColumns={numColumns}
+ key={numColumns}
+ columnWrapperStyle={
+ numColumns === 1
+ ? null
+ : {
+ width:
+ notes.length === 1
+ ? DDS.isTab
+ ? '95%'
+ : '90%'
+ : DDS.isTab
+ ? '45%'
+ : '42.5%',
+ }
+ }
+ contentContainerStyle={{
+ width:
+ numColumns === 2
+ ? DDS.isTab
+ ? '100%'
+ : null
+ : DDS.isTab
+ ? '95%'
+ : '90%',
+ alignItems: numColumns === 2 ? 'flex-start' : null,
+ alignSelf: 'center',
+ }}
+ ListFooterComponent={
+ <View
+ style={{
+ height: 150,
+ alignItems: 'center',
+ justifyContent: 'center',
}}>
- <View>
- {isSearch ? (
- <Text
- transition="marginTop"
- delay={200}
- duration={200}
- style={{
- fontSize: SIZE.lg,
- marginTop: margin,
- fontFamily: WEIGHT.medium,
- color: colors.pri,
- paddingHorizontal: DDS.isTab ? '2.5%' : '5%',
- maxWidth: '100%',
- }}>
- Search Results for{' '}
- <Text
- style={{
- color: colors.accent,
- }}>
- {keyword}
- </Text>
- </Text>
- ) : (
- undefined
- )}
- </View>
+ <Text
+ style={{
+ color: colors.navbg,
+ fontSize: SIZE.sm,
+ fontFamily: WEIGHT.regular,
+ }}>
+ - End -
+ </Text>
+ </View>
+ }
+ renderItem={({item, index}) => (
+ <NoteItem item={item} numColumns={numColumns} index={index} />
+ )}
+ />
+ );
+};
- <TouchableOpacity
- onPress={() => {
- setNumColumns(numColumns === 1 ? 2 : 1);
- }}
+/*
+ <FlatList
+ data={notes}
+ keyExtractor={(item, index) => item.dateCreated.toString()}
+ ListFooterComponent={
+ <View
+ style={{
+ height: 150,
+ alignItems: 'center',
+ justifyContent: 'center',
+ }}>
+ <Text
style={{
- justifyContent: 'center',
- alignItems: 'center',
+ color: colors.navbg,
+ fontSize: SIZE.sm,
+ fontFamily: WEIGHT.regular,
}}>
- <Icon name="list" size={SIZE.xl} color={colors.icon} />
- </TouchableOpacity>
+ - End -
+ </Text>
</View>
}
+ onScroll={event => {
+ y = event.nativeEvent.contentOffset.y;
+ onScroll(y);
+ }}
+ ListHeaderComponent={
+ <View
+ style={{
+ marginTop: margin,
+ }}></View>
+ }
numColumns={numColumns}
key={numColumns}
columnWrapperStyle={
@@ -144,6 +185,4 @@ export const NotesList = ({
renderItem={({item, index}) => (
<NoteItem item={item} numColumns={numColumns} index={index} />
)}
- />
- );
-};
+ /> */
diff --git a/apps/mobile/src/components/SearchInput/index.js b/apps/mobile/src/components/SearchInput/index.js
index 9777b3611..a1ebfaaa7 100644
--- a/apps/mobile/src/components/SearchInput/index.js
+++ b/apps/mobile/src/components/SearchInput/index.js
@@ -14,8 +14,9 @@ import Icon from 'react-native-vector-icons/Ionicons';
import {getElevation} from '../../utils/utils';
import * as Animatable from 'react-native-animatable';
import {DDS} from '../../../App';
+import {useAppContext} from '../../provider/useAppContext';
export const Search = props => {
- const [colors, setColors] = useState(COLOR_SCHEME);
+ const {colors} = useAppContext();
const [focus, setFocus] = useState(false);
const inputRef = createRef();
@@ -49,7 +50,7 @@ export const Search = props => {
paddingVertical: props.hide
? 0
: Platform.OS == 'ios'
- ? pv - 3
+ ? pv - 1
: pv - 8,
marginBottom: props.hide ? 0 : 10,
borderColor: focus ? colors.accent : colors.nav,
@@ -61,7 +62,7 @@ export const Search = props => {
fontFamily: WEIGHT.regular,
color: colors.pri,
maxWidth: '90%',
- paddingVertical: 10,
+
width: '90%',
fontSize: SIZE.md,
}}
diff --git a/apps/mobile/src/components/Toast/index.js b/apps/mobile/src/components/Toast/index.js
index cee8c9ec5..f6ca90438 100644
--- a/apps/mobile/src/components/Toast/index.js
+++ b/apps/mobile/src/components/Toast/index.js
@@ -11,12 +11,13 @@ 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, w} from '../../utils/utils';
+import {useAppContext} from '../../provider/useAppContext';
const AnimatedTouchableOpacity = Animatable.createAnimatableComponent(
TouchableOpacity,
);
export const Toast = () => {
- const [colors, setColors] = useState(COLOR_SCHEME);
+ const {colors} = useAppContext();
const [toast, setToast] = useState(false);
const [message, setMessage] = useState([]);
const [data, setData] = useState([]);
diff --git a/apps/mobile/src/components/VaultDialog/index.js b/apps/mobile/src/components/VaultDialog/index.js
index 7d1854b6e..4769879e7 100644
--- a/apps/mobile/src/components/VaultDialog/index.js
+++ b/apps/mobile/src/components/VaultDialog/index.js
@@ -1,37 +1,16 @@
-import React, {useEffect, useState, createRef} from 'react';
-import {
- ScrollView,
- View,
- Text,
- TouchableOpacity,
- Dimensions,
- Image,
- SafeAreaView,
- Platform,
- Modal,
-} from 'react-native';
-import NavigationService from '../../services/NavigationService';
-import {
- COLOR_SCHEME,
- SIZE,
- br,
- ph,
- pv,
- opacity,
- FONT,
- WEIGHT,
-} from '../../common/common';
+import React, {useState} from 'react';
+import {View, Text, TouchableOpacity, Modal} from 'react-native';
+import {SIZE, ph, pv, opacity, WEIGHT} from '../../common/common';
import Icon from 'react-native-vector-icons/Feather';
-
-import {getElevation, h, w, timeSince, ToastEvent} from '../../utils/utils';
import {FlatList, TextInput} from 'react-native-gesture-handler';
import {useForceUpdate} from '../../views/ListsEditor';
import {db} from '../../../App';
+import {useAppContext} from '../../provider/useAppContext';
let refs = [];
export const VaultDialog = ({visible, close}) => {
- const [colors, setColors] = useState(COLOR_SCHEME);
+ const {colors} = useAppContext();
const forceUpdate = useForceUpdate();
const [hidden, setHidden] = useState(false);
return (
diff --git a/apps/mobile/src/components/header/index.js b/apps/mobile/src/components/header/index.js
index 7ae4d59ae..4beb345a1 100644
--- a/apps/mobile/src/components/header/index.js
+++ b/apps/mobile/src/components/header/index.js
@@ -6,15 +6,16 @@ import {h, SideMenuEvent} from '../../utils/utils';
import * as Animatable from 'react-native-animatable';
import NavigationService from '../../services/NavigationService';
import {DDS} from '../../../App';
+import {useAppContext} from '../../provider/useAppContext';
export const Header = ({
heading,
- colors,
canGoBack = true,
hide,
showSearch,
menu,
sendHeight = e => {},
}) => {
+ const {colors} = useAppContext();
const [isOpen, setOpen] = useState(DDS.isTab ? true : false);
return (
diff --git a/apps/mobile/src/provider/index.js b/apps/mobile/src/provider/index.js
index 8e187fd0a..2dc7668b2 100644
--- a/apps/mobile/src/provider/index.js
+++ b/apps/mobile/src/provider/index.js
@@ -1,12 +1,34 @@
import React, {createContext} from 'react';
import {useImmer} from 'use-immer';
-
-const AppContext = createContext();
+import {COLOR_SCHEME} from '../common/common';
+const ACCENT = {
+ color: '#0560FF',
+};
const defaultState = {
userLoggedIn: false,
+ colors: {
+ night: false,
+ bg: 'white',
+ fg: ACCENT.color,
+ navbg: '#f6fbfc',
+ nav: '#f0f0f0',
+ pri: 'black',
+ sec: 'white',
+ accent: ACCENT.color,
+ normal: 'black',
+ icon: 'gray',
+ errorBg: '#FFD2D2',
+ errorText: '#D8000C',
+ successBg: '#DFF2BF',
+ successText: '#4F8A10',
+ warningBg: '#FEEFB3',
+ warningText: '#9F6000',
+ },
};
+const AppContext = createContext([defaultState, function() {}]);
+
const AppProvider = ({children}) => {
const [state, dispatch] = useImmer({...defaultState});
diff --git a/apps/mobile/src/provider/useAppContext.js b/apps/mobile/src/provider/useAppContext.js
index 5c7c1f325..efbd55878 100644
--- a/apps/mobile/src/provider/useAppContext.js
+++ b/apps/mobile/src/provider/useAppContext.js
@@ -1,5 +1,12 @@
import {useContext} from 'react';
import {AppContext} from '.';
+import {StatusBar} from 'react-native';
+import {
+ COLOR_SCHEME,
+ setColorScheme,
+ getColorScheme,
+ ACCENT,
+} from '../common/common';
const useAppContext = () => {
const [state, dispatch] = useContext(AppContext);
@@ -8,15 +15,32 @@ const useAppContext = () => {
throw new Error('Must have dispatch defined');
}
- function logInUser(isLoggedIn) {
+ async function updateAppTheme(colors = state.colors) {
+ let newColors = await getColorScheme(colors);
dispatch(draft => {
- draft.userLoggedIn = true;
+ draft.colors = {...newColors};
});
}
+ function changeColorScheme(colors = COLOR_SCHEME, accent = ACCENT.color) {
+ let newColors = setColorScheme(colors, accent);
+ StatusBar.setBarStyle(newColors.night ? 'light-content' : 'dark-content');
+
+ dispatch(draft => {
+ draft.colors = {...newColors};
+ });
+ }
+
+ function changeAccentColor(accentColor) {
+ ACCENT.color = accentColor;
+ changeColorScheme();
+ }
+
return {
...state,
- logInUser,
+ updateAppTheme,
+ changeColorScheme,
+ changeAccentColor,
};
};
diff --git a/apps/mobile/src/views/Editor/index.js b/apps/mobile/src/views/Editor/index.js
index a8a949a7e..3e210b35e 100755
--- a/apps/mobile/src/views/Editor/index.js
+++ b/apps/mobile/src/views/Editor/index.js
@@ -56,7 +56,7 @@ const AnimatedTextInput = Animatable.createAnimatableComponent(TextInput);
const Editor = ({navigation}) => {
// STATE
- const [colors, setColors] = useState(COLOR_SCHEME);
+ const {colors} = useAppContext();
const [dialog, setDialog] = useState(false);
const [resize, setResize] = useState(false);
const [isOpen, setOpen] = useState(false);
@@ -123,11 +123,6 @@ const Editor = ({navigation}) => {
if (content && content.delta) {
post(JSON.stringify(content.delta));
}
-
- EditorWebView.requestFocus();
- setTimeout(() => {
- post(null);
- }, 500);
};
const onTitleTextChange = value => {
title = value;
diff --git a/apps/mobile/src/views/Favorites/index.js b/apps/mobile/src/views/Favorites/index.js
index 344e02b92..ff5d24293 100644
--- a/apps/mobile/src/views/Favorites/index.js
+++ b/apps/mobile/src/views/Favorites/index.js
@@ -28,24 +28,14 @@ import {ListItem} from '../../components/ListItem';
import {Header} from '../../components/header';
import {useForceUpdate} from '../ListsEditor';
import {AnimatedSafeAreaView} from '../Home';
+import {useAppContext} from '../../provider/useAppContext';
const w = Dimensions.get('window').width;
const h = Dimensions.get('window').height;
export const Favorites = ({navigation}) => {
- const [colors, setColors] = useState(COLOR_SCHEME);
- const forceUpdate = useForceUpdate();
+ const {colors} = useAppContext();
- useEffect(() => {
- onThemeUpdate(() => {
- forceUpdate();
- });
- return () => {
- clearThemeUpdateListener(() => {
- forceUpdate();
- });
- };
- }, []);
return (
<AnimatedSafeAreaView
transition="backgroundColor"
diff --git a/apps/mobile/src/views/Folders/index.js b/apps/mobile/src/views/Folders/index.js
index 72f19bb59..d96df918c 100644
--- a/apps/mobile/src/views/Folders/index.js
+++ b/apps/mobile/src/views/Folders/index.js
@@ -38,15 +38,17 @@ import {Header} from '../../components/header';
import {AnimatedSafeAreaView} from '../Home';
import * as Animatable from 'react-native-animatable';
import {NavigationEvents} from 'react-navigation';
+import {useAppContext} from '../../provider/useAppContext';
export const Folders = ({navigation}) => {
- const [colors, setColors] = useState(COLOR_SCHEME);
+ const {colors} = useAppContext();
+
const [addNotebook, setAddNotebook] = useState(false);
const [notebooks, setNotebooks] = useState([]);
const [hideHeader, setHideHeader] = useState(false);
const [buttonHide, setButtonHide] = useState(false);
const [margin, setMargin] = useState(190);
const [numColumns, setNumColumns] = useState(1);
- const forceUpdate = useForceUpdate();
+
const params = navigation.state.params;
let offsetY = 0;
let countUp = 0;
@@ -74,17 +76,6 @@ export const Folders = ({navigation}) => {
console.log(db.getNotebooks());
}, []);
- useEffect(() => {
- onThemeUpdate(() => {
- forceUpdate();
- });
- return () => {
- clearThemeUpdateListener(() => {
- forceUpdate();
- });
- };
- }, []);
-
return (
<AnimatedSafeAreaView
transition="backgroundColor"
diff --git a/apps/mobile/src/views/ForgotPassword/index.js b/apps/mobile/src/views/ForgotPassword/index.js
index 3291f8d79..1b9c94588 100644
--- a/apps/mobile/src/views/ForgotPassword/index.js
+++ b/apps/mobile/src/views/ForgotPassword/index.js
@@ -32,21 +32,11 @@ import {FlatList, TextInput} from 'react-native-gesture-handler';
import {NavigationEvents} from 'react-navigation';
import {Header} from '../../components/header';
import {useForceUpdate} from '../ListsEditor';
+import {useAppContext} from '../../provider/useAppContext';
export const ForgotPassword = ({navigation}) => {
- const [colors, setColors] = useState(COLOR_SCHEME);
- const forceUpdate = useForceUpdate();
+ const {colors} = useAppContext();
- useEffect(() => {
- onThemeUpdate(() => {
- forceUpdate();
- });
- return () => {
- clearThemeUpdateListener(() => {
- forceUpdate();
- });
- };
- }, []);
useEffect(() => {
DeviceEventEmitter.emit('hide');
return () => {
diff --git a/apps/mobile/src/views/Home/index.js b/apps/mobile/src/views/Home/index.js
index 2d56eea87..aaff78fdc 100755
--- a/apps/mobile/src/views/Home/index.js
+++ b/apps/mobile/src/views/Home/index.js
@@ -1,25 +1,13 @@
import React, {useEffect, useState, createRef, useCallback} from 'react';
import {
SafeAreaView,
- Platform,
- DeviceEventEmitter,
TouchableOpacity,
View,
KeyboardAvoidingView,
Text,
Keyboard,
} from 'react-native';
-import {
- COLOR_SCHEME,
- opacity,
- pv,
- br,
- SIZE,
- WEIGHT,
- onThemeUpdate,
- clearThemeUpdateListener,
-} from '../../common/common';
-import {styles} from './styles';
+import {COLOR_SCHEME, opacity, pv, br, SIZE, WEIGHT} from '../../common/common';
import {Search} from '../../components/SearchInput';
import {w, h} from '../../utils/utils';
import {Header} from '../../components/header';
@@ -30,7 +18,7 @@ import Icon from 'react-native-vector-icons/Feather';
import NavigationService from '../../services/NavigationService';
import {useForceUpdate} from '../ListsEditor';
import * as Animatable from 'react-native-animatable';
-import {useNavigationEvents, useIsFocused} from 'react-navigation-hooks';
+import {useIsFocused} from 'react-navigation-hooks';
import {useAppContext} from '../../provider/useAppContext';
import {DDS} from '../../../App';
export const AnimatedSafeAreaView = Animatable.createAnimatableComponent(
@@ -39,7 +27,8 @@ export const AnimatedSafeAreaView = Animatable.createAnimatableComponent(
export const Home = ({navigation}) => {
// State
- const [colors, setColors] = useState(COLOR_SCHEME);
+ const {colors, updateAppTheme} = useAppContext();
+
const [search, setSearch] = useState(false);
const [text, setText] = useState('');
const [update, setUpdate] = useState(0);
@@ -48,9 +37,7 @@ export const Home = ({navigation}) => {
const [buttonHide, setButtonHide] = useState(false);
const [notes, setNotes] = useState([]);
const [keyword, setKeyword] = useState('');
- const forceUpdate = useForceUpdate();
const isFocused = useIsFocused();
- const {userLoggedIn, logInUser} = useAppContext();
// Variables
let offsetY = 0;
let countUp = 1;
@@ -62,29 +49,14 @@ export const Home = ({navigation}) => {
let allNotes = [];
// Effects
-
useEffect(() => {
- console.log('deviceType', DDS.isTab);
- console.log(userLoggedIn);
- }, [userLoggedIn]);
+ updateAppTheme(colors);
+ }, []);
useEffect(() => {
- logInUser(true);
-
if (!isFocused) return;
fetchNotes();
}, [isFocused]);
- useEffect(() => {
- onThemeUpdate(() => {
- forceUpdate();
- });
- return () => {
- clearThemeUpdateListener(() => {
- forceUpdate();
- });
- };
- }, []);
-
const fetchNotes = () => {
allNotes = db.getNotes();
setNotes(allNotes);
diff --git a/apps/mobile/src/views/Lists/index.js b/apps/mobile/src/views/Lists/index.js
index f3be8b65f..05b970ab9 100644
--- a/apps/mobile/src/views/Lists/index.js
+++ b/apps/mobile/src/views/Lists/index.js
@@ -23,12 +23,13 @@ import {
import Icon from 'react-native-vector-icons/Ionicons';
import {Reminder} from '../../components/Reminder';
import {ListItem} from '../../components/ListItem';
+import {useAppContext} from '../../provider/useAppContext';
const w = Dimensions.get('window').width;
const h = Dimensions.get('window').height;
export const Lists = ({navigation}) => {
- const [colors, setColors] = useState(COLOR_SCHEME);
+ const {colors} = useAppContext();
return (
<SafeAreaView>
diff --git a/apps/mobile/src/views/Login/index.js b/apps/mobile/src/views/Login/index.js
index 209213eb7..93226d6b3 100644
--- a/apps/mobile/src/views/Login/index.js
+++ b/apps/mobile/src/views/Login/index.js
@@ -32,20 +32,9 @@ import {NavigationEvents} from 'react-navigation';
import {Header} from '../../components/header';
import {useForceUpdate} from '../ListsEditor';
import {DDS} from '../../../App';
+import {useAppContext} from '../../provider/useAppContext';
export const Login = ({navigation}) => {
- const [colors, setColors] = useState(COLOR_SCHEME);
- const forceUpdate = useForceUpdate();
-
- useEffect(() => {
- onThemeUpdate(() => {
- forceUpdate();
- });
- return () => {
- clearThemeUpdateListener(() => {
- forceUpdate();
- });
- };
- }, []);
+ const {colors} = useAppContext();
useEffect(() => {
DeviceEventEmitter.emit('hide');
return () => {
diff --git a/apps/mobile/src/views/Notebook/index.js b/apps/mobile/src/views/Notebook/index.js
index 43393fd11..8eb184850 100644
--- a/apps/mobile/src/views/Notebook/index.js
+++ b/apps/mobile/src/views/Notebook/index.js
@@ -37,6 +37,7 @@ import {AnimatedSafeAreaView} from '../Home';
import * as Animatable from 'react-native-animatable';
import {NavigationEvents} from 'react-navigation';
import {DDS} from '../../../App';
+import {useAppContext} from '../../provider/useAppContext';
const w = Dimensions.get('window').width;
const h = Dimensions.get('window').height;
const AnimatedTouchableOpacity = Animatable.createAnimatableComponent(
@@ -44,7 +45,7 @@ const AnimatedTouchableOpacity = Animatable.createAnimatableComponent(
);
export const Notebook = ({navigation}) => {
// State
- const [colors, setColors] = useState(COLOR_SCHEME);
+ const {colors} = useAppContext();
const params = navigation.state.params;
const [hideHeader, setHideHeader] = useState(false);
const [margin, setMargin] = useState(190);
@@ -61,16 +62,6 @@ export const Notebook = ({navigation}) => {
let marginSet = false;
// Effects
- useEffect(() => {
- onThemeUpdate(() => {
- forceUpdate();
- });
- return () => {
- clearThemeUpdateListener(() => {
- forceUpdate();
- });
- };
- }, []);
// Functions
const setMarginTop = () => {
diff --git a/apps/mobile/src/views/Notes/index.js b/apps/mobile/src/views/Notes/index.js
index e7f56c954..540c70489 100644
--- a/apps/mobile/src/views/Notes/index.js
+++ b/apps/mobile/src/views/Notes/index.js
@@ -33,11 +33,12 @@ import {NotesList} from '../../components/NotesList';
import {AnimatedSafeAreaView} from '../Home';
import {db} from '../../../App';
import * as Animatable from 'react-native-animatable';
+import {useAppContext} from '../../provider/useAppContext';
const w = Dimensions.get('window').width;
const h = Dimensions.get('window').height;
export const Notes = ({navigation}) => {
- const [colors, setColors] = useState(COLOR_SCHEME);
+ const {colors} = useAppContext();
const [hideHeader, setHideHeader] = useState(false);
const [margin, setMargin] = useState(200);
const [buttonHide, setButtonHide] = useState(false);
diff --git a/apps/mobile/src/views/Settings/index.js b/apps/mobile/src/views/Settings/index.js
index b0365fd20..e4319b6d2 100644
--- a/apps/mobile/src/views/Settings/index.js
+++ b/apps/mobile/src/views/Settings/index.js
@@ -34,24 +34,13 @@ import {FlatList} from 'react-native-gesture-handler';
import AsyncStorage from '@react-native-community/async-storage';
import {useForceUpdate} from '../ListsEditor';
import {AnimatedSafeAreaView} from '../Home';
+import {useAppContext} from '../../provider/useAppContext';
const w = Dimensions.get('window').width;
const h = Dimensions.get('window').height;
export const Settings = ({navigation}) => {
- const [colors, setColors] = useState(COLOR_SCHEME);
- const forceUpdate = useForceUpdate();
-
- useEffect(() => {
- onThemeUpdate(() => {
- forceUpdate();
- });
- return () => {
- clearThemeUpdateListener(() => {
- forceUpdate();
- });
- };
- }, []);
+ const {colors} = useAppContext();
return (
<AnimatedSafeAreaView
transition="backgroundColor"
diff --git a/apps/mobile/src/views/Signup/index.js b/apps/mobile/src/views/Signup/index.js
index 648c6155f..78f9593f4 100644
--- a/apps/mobile/src/views/Signup/index.js
+++ b/apps/mobile/src/views/Signup/index.js
@@ -32,20 +32,9 @@ import {NavigationEvents} from 'react-navigation';
import {Header} from '../../components/header';
import {useForceUpdate} from '../ListsEditor';
import {DDS} from '../../../App';
+import {useAppContext} from '../../provider/useAppContext';
export const Signup = ({navigation}) => {
- const [colors, setColors] = useState(COLOR_SCHEME);
- const forceUpdate = useForceUpdate();
-
- useEffect(() => {
- onThemeUpdate(() => {
- forceUpdate();
- });
- return () => {
- clearThemeUpdateListener(() => {
- forceUpdate();
- });
- };
- }, []);
+ const {colors} = useAppContext();
useEffect(() => {
DeviceEventEmitter.emit('hide');
return () => {
diff --git a/apps/mobile/src/views/Tags/index.js b/apps/mobile/src/views/Tags/index.js
index fa4d9ed3b..da3a5f24c 100644
--- a/apps/mobile/src/views/Tags/index.js
+++ b/apps/mobile/src/views/Tags/index.js
@@ -29,24 +29,13 @@ import {ListItem} from '../../components/ListItem';
import {Header} from '../../components/header';
import NoteItem from '../../components/NoteItem';
import {useForceUpdate} from '../ListsEditor';
+import {useAppContext} from '../../provider/useAppContext';
const w = Dimensions.get('window').width;
const h = Dimensions.get('window').height;
export const Tags = ({navigation}) => {
- const [colors, setColors] = useState(COLOR_SCHEME);
- const forceUpdate = useForceUpdate();
-
- useEffect(() => {
- onThemeUpdate(() => {
- forceUpdate();
- });
- return () => {
- clearThemeUpdateListener(() => {
- forceUpdate();
- });
- };
- }, []);
+ const {colors} = useAppContext();
return (
<SafeAreaView
style={{
diff --git a/apps/mobile/src/views/Trash/index.js b/apps/mobile/src/views/Trash/index.js
index 2c2679cea..d85456a88 100644
--- a/apps/mobile/src/views/Trash/index.js
+++ b/apps/mobile/src/views/Trash/index.js
@@ -29,24 +29,13 @@ import {ListItem} from '../../components/ListItem';
import {Header} from '../../components/header';
import NoteItem from '../../components/NoteItem';
import {useForceUpdate} from '../ListsEditor';
+import {useAppContext} from '../../provider/useAppContext';
const w = Dimensions.get('window').width;
const h = Dimensions.get('window').height;
export const Trash = ({navigation}) => {
- const [colors, setColors] = useState(COLOR_SCHEME);
- const forceUpdate = useForceUpdate();
-
- useEffect(() => {
- onThemeUpdate(() => {
- forceUpdate();
- });
- return () => {
- clearThemeUpdateListener(() => {
- forceUpdate();
- });
- };
- }, []);
+ const {colors} = useAppContext();
return (
<SafeAreaView
style={{