Skip to content

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

use change state instead of focus and blur

ammarahm-edab836d986a26
diff --git a/apps/mobile/App.js b/apps/mobile/App.js
index c2f620ff0..6a5c9e6d4 100644
--- a/apps/mobile/App.js
+++ b/apps/mobile/App.js
@@ -43,20 +43,22 @@ Sentry.init({
let firstLoad = true;
let note = null;
-const onAppFocused = async () => {
- StatusBar.setBarStyle(COLOR_SCHEME.night ? 'light-content' : 'dark-content');
- if (Platform.OS === 'android') {
- StatusBar.setTranslucent(true);
- StatusBar.setBackgroundColor(COLOR_SCHEME.bg);
- }
- if (SettingsService.get().privacyScreen) {
- enabled(false);
- }
-};
-
-const onAppBlur = async () => {
- if (SettingsService.get().privacyScreen) {
- enabled(true);
+const onAppStateChanged = async (state) => {
+ if (state === 'active') {
+ StatusBar.setBarStyle(
+ COLOR_SCHEME.night ? 'light-content' : 'dark-content',
+ );
+ if (Platform.OS === 'android') {
+ StatusBar.setTranslucent(true);
+ StatusBar.setBackgroundColor(COLOR_SCHEME.bg);
+ }
+ if (SettingsService.get().privacyScreen) {
+ enabled(false);
+ }
+ } else {
+ if (SettingsService.get().privacyScreen) {
+ enabled(true);
+ }
}
};
@@ -138,8 +140,7 @@ const App = () => {
eSubscribeEvent(eDispatchAction, (type) => {
dispatch(type);
});
- AppState.addEventListener('focus', onAppFocused);
- AppState.addEventListener('blur', onAppBlur);
+ AppState.addEventListener('change', onAppStateChanged);
Appearance.addChangeListener(onSystemThemeChanged);
let unsub = NetInfo.addEventListener(onNetworkStateChanged);
return () => {
@@ -150,8 +151,7 @@ const App = () => {
dispatch(type);
});
Orientation.removeOrientationListener(_onOrientationChange);
- AppState.removeEventListener('focus', onAppFocused);
- AppState.removeEventListener('blur', onAppBlur);
+ AppState.removeEventListener('change', onAppStateChanged);
Appearance.removeChangeListener(onSystemThemeChanged);
unsub();
};
diff --git a/apps/mobile/src/services/SettingsService.js b/apps/mobile/src/services/SettingsService.js
index 745d5138d..d97f6b3eb 100644
--- a/apps/mobile/src/services/SettingsService.js
+++ b/apps/mobile/src/services/SettingsService.js
@@ -5,7 +5,8 @@ import {AndroidModule, sortSettings} from '../utils';
import {getColorScheme} from '../utils/ColorUtils';
import {MMKV} from '../utils/mmkv';
import {scale, updateSize} from '../utils/SizeUtils';
-
+import {enabled} from 'react-native-privacy-snapshot';
+import {Platform} from 'react-native';
let settings = defaultState.settings;
async function init() {
@@ -21,9 +22,17 @@ async function init() {
scale.fontScale = settings.fontScale;
}
if (settings.privacyScreen) {
- AndroidModule.setSecureMode(true);
+ if (Platform.OS === 'android') {
+ AndroidModule.setSecureMode(true);
+ } else {
+ enabled(true);
+ }
} else {
- AndroidModule.setSecureMode(false);
+ if (Platform.OS === 'android') {
+ AndroidModule.setSecureMode(false);
+ } else {
+ enabled(false);
+ }
}
sortSettings.sort = settings.sort;
sortSettings.sortOrder = settings.sortOrder;