From d249495c5d8a82b50682a4201b7c48661d850144 Mon Sep 17 00:00:00 2001 From: ammarahm-ed Date: Sat, 26 Jun 2021 10:47:05 +0500 Subject: [PATCH] add proper toggles --- .../toggle-switch-react-native+3.2.0.patch | 21 +++ apps/mobile/src/views/Settings/index.js | 164 +++++++++++------- 2 files changed, 118 insertions(+), 67 deletions(-) create mode 100644 apps/mobile/patches/toggle-switch-react-native+3.2.0.patch diff --git a/apps/mobile/patches/toggle-switch-react-native+3.2.0.patch b/apps/mobile/patches/toggle-switch-react-native+3.2.0.patch new file mode 100644 index 000000000..d0a865fe0 --- /dev/null +++ b/apps/mobile/patches/toggle-switch-react-native+3.2.0.patch @@ -0,0 +1,21 @@ +diff --git a/node_modules/toggle-switch-react-native/ToggleSwitch.js b/node_modules/toggle-switch-react-native/ToggleSwitch.js +index 7ddf25f..04b04e4 100644 +--- a/node_modules/toggle-switch-react-native/ToggleSwitch.js ++++ b/node_modules/toggle-switch-react-native/ToggleSwitch.js +@@ -25,11 +25,11 @@ export default class ToggleSwitch extends React.Component { + switch (size) { + case "small": + return { +- width: 40, +- padding: 10, +- circleWidth: 15, +- circleHeight: 15, +- translateX: 22, ++ width: 30, ++ padding: 8, ++ circleWidth: 11, ++ circleHeight: 11, ++ translateX: 18.5, + }; + case "large": + return { diff --git a/apps/mobile/src/views/Settings/index.js b/apps/mobile/src/views/Settings/index.js index c14c69203..1b99ff514 100644 --- a/apps/mobile/src/views/Settings/index.js +++ b/apps/mobile/src/views/Settings/index.js @@ -86,6 +86,7 @@ import {tabBarRef} from '../../utils/Refs'; import {pv, SIZE} from '../../utils/SizeUtils'; import Storage from '../../utils/storage'; import {sleep, timeConverter} from '../../utils/TimeUtils'; +import ToggleSwitch from 'toggle-switch-react-native'; let menuRef = createRef(); @@ -1191,12 +1192,13 @@ const SettingsAppearanceSection = () => { onPress={switchTheme} maxWidth="90%" customComponent={ - } /> @@ -1216,10 +1218,28 @@ const SettingsAppearanceSection = () => { }} maxWidth="90%" customComponent={ - { + if (!colors.night) { + await MMKV.setStringAsync( + 'theme', + JSON.stringify({night: true}), + ); + changeColorScheme(COLOR_SCHEME_DARK); + } else { + await MMKV.setStringAsync( + 'theme', + JSON.stringify({night: false}), + ); + + changeColorScheme(COLOR_SCHEME_LIGHT); + } + }} /> } /> @@ -1345,6 +1365,21 @@ const SettingsPrivacyAndSecurity = () => { }, ]; + const toggleBiometricUnlocking = () => { + openVault({ + item: {}, + fingerprintAccess: !vaultStatus.biometryEnrolled, + revokeFingerprintAccess: vaultStatus.biometryEnrolled, + novault: true, + title: vaultStatus.biometryEnrolled + ? 'Revoke biometric unlocking' + : 'Enable biometery unlock', + description: vaultStatus.biometryEnrolled + ? 'Disable biometric unlocking for notes in vault' + : 'Disable biometric unlocking for notes in vault', + }); + }; + return ( <> {appLockVisible && ( @@ -1417,10 +1452,15 @@ const SettingsPrivacyAndSecurity = () => { }} maxWidth="90%" customComponent={ - { + SettingsService.set('telemetry', isOn); + }} /> } /> @@ -1438,12 +1478,18 @@ const SettingsPrivacyAndSecurity = () => { }} maxWidth="90%" customComponent={ - { + Platform.OS === 'android' + ? AndroidModule.setSecureMode(isOn) + : enabled(true); + SettingsService.set('privacyScreen', isOn); + }} /> } /> @@ -1467,32 +1513,16 @@ const SettingsPrivacyAndSecurity = () => { key="fingerprintVaultUnlock" title="Vault biometrics unlock" tagline="Access notes in vault using biometrics" - onPress={() => { - openVault({ - item: {}, - fingerprintAccess: !vaultStatus.biometryEnrolled, - revokeFingerprintAccess: vaultStatus.biometryEnrolled, - novault: true, - title: vaultStatus.biometryEnrolled - ? 'Revoke biometric unlocking' - : 'Enable biometery unlock', - description: vaultStatus.biometryEnrolled - ? 'Disable biometric unlocking for notes in vault' - : 'Disable biometric unlocking for notes in vault', - }); - }} + onPress={toggleBiometricUnlocking} maxWidth="90%" customComponent={ - } /> @@ -1585,6 +1615,21 @@ const SettingsBackupAndRestore = () => { }, ]; + const toggleEncryptedBackups = async () => { + if (!user) { + ToastEvent.show({ + heading: 'Login required to enable encryption', + type: 'error', + func: () => { + eSendEvent(eOpenLoginDialog); + }, + actionText: 'Login', + }); + return; + } + await SettingsService.set('encryptedBackup', !settings.encryptedBackup); + }; + return ( <> @@ -1694,30 +1739,15 @@ const SettingsBackupAndRestore = () => { { - if (!user) { - ToastEvent.show({ - heading: 'Login required to enable encryption', - type: 'error', - func: () => { - eSendEvent(eOpenLoginDialog); - }, - actionText: 'Login', - }); - return; - } - await SettingsService.set( - 'encryptedBackup', - !settings.encryptedBackup, - ); - }} + onPress={toggleEncryptedBackups} customComponent={ - } />