From a9f465e0ee2fcbfc2decbb54640391a547838f3c Mon Sep 17 00:00:00 2001 From: Antonella Sgarlatta Date: Thu, 18 Feb 2021 18:07:46 -0300 Subject: [PATCH] feat: hide protections section if none are available --- package.json | 2 +- src/screens/Settings/Sections/PasscodeSection.tsx | 2 ++ src/screens/Settings/Settings.tsx | 13 ++++++++++--- yarn.lock | 8 ++++---- 4 files changed, 17 insertions(+), 8 deletions(-) diff --git a/package.json b/package.json index f3a1615b..20fb937f 100644 --- a/package.json +++ b/package.json @@ -26,7 +26,7 @@ "@react-navigation/native": "^5.8.10", "@react-navigation/stack": "^5.12.8", "@standardnotes/sncrypto-common": "1.2.9", - "@standardnotes/snjs": "^2.0.55", + "@standardnotes/snjs": "^2.0.57", "js-base64": "^3.5.2", "moment": "^2.29.1", "react": "16.13.1", diff --git a/src/screens/Settings/Sections/PasscodeSection.tsx b/src/screens/Settings/Sections/PasscodeSection.tsx index 062c2f29..7ae6477c 100644 --- a/src/screens/Settings/Sections/PasscodeSection.tsx +++ b/src/screens/Settings/Sections/PasscodeSection.tsx @@ -19,6 +19,7 @@ type Props = { title: string; hasPasscode: boolean; encryptionAvailable: boolean; + updateProtectionsAvailable: Function; }; export const PasscodeSection = (props: Props) => { @@ -156,6 +157,7 @@ export const PasscodeSection = (props: Props) => { await application?.enableBiometrics(); await setBiometricsTiming(UnlockTiming.OnQuit); } + props.updateProtectionsAvailable(); await application?.getAppState().setScreenshotPrivacy(); }; diff --git a/src/screens/Settings/Settings.tsx b/src/screens/Settings/Settings.tsx index 0bad7e3a..40096ac0 100644 --- a/src/screens/Settings/Settings.tsx +++ b/src/screens/Settings/Settings.tsx @@ -22,15 +22,23 @@ export const Settings = (props: Props) => { const [hasPasscode, setHasPasscode] = useState(() => Boolean(application?.hasPasscode()) ); + const [protectionsAvailable, setProtectionsAvailable] = useState( + application?.hasProtectionSources() + ); const [encryptionAvailable, setEncryptionAvailable] = useState(() => application?.isEncryptionAvailable() ); + const updateProtectionsAvailable = () => { + setProtectionsAvailable(application?.hasProtectionSources()); + }; + useEffect(() => { const removeApplicationEventSubscriber = application?.addEventObserver( async event => { if (event === ApplicationEvent.KeyStatusChanged) { setHasPasscode(Boolean(application?.hasPasscode())); + updateProtectionsAvailable(); setEncryptionAvailable(() => application?.isEncryptionAvailable()); } } @@ -60,11 +68,10 @@ export const Settings = (props: Props) => { - + {protectionsAvailable && }