From 9ffaf318eb8599dbae9d3fec021b70b62f089b8a Mon Sep 17 00:00:00 2001 From: Radek Czemerys Date: Thu, 23 Jul 2020 11:20:58 +0200 Subject: [PATCH] feature: hide privacy snapshot when app loses focus --- ios/Podfile.lock | 6 ++++++ package.json | 1 + src/lib/ApplicationState.ts | 3 +++ src/types/react-native-privacy-snapshot/index.d.ts | 5 +++++ yarn.lock | 4 ++++ 5 files changed, 19 insertions(+) create mode 100644 src/types/react-native-privacy-snapshot/index.d.ts diff --git a/ios/Podfile.lock b/ios/Podfile.lock index 6dd57715..d15335aa 100644 --- a/ios/Podfile.lock +++ b/ios/Podfile.lock @@ -323,6 +323,8 @@ PODS: - React - RNKeychain (4.0.5): - React + - RNPrivacySnapshot (1.0.0): + - React - RNReanimated (1.9.0): - React - RNScreens (2.9.0): @@ -389,6 +391,7 @@ DEPENDENCIES: - RNFS (from `../node_modules/react-native-fs`) - RNGestureHandler (from `../node_modules/react-native-gesture-handler`) - RNKeychain (from `../node_modules/react-native-keychain`) + - RNPrivacySnapshot (from `../node_modules/react-native-privacy-snapshot`) - RNReanimated (from `../node_modules/react-native-reanimated`) - RNScreens (from `../node_modules/react-native-screens`) - RNSearchBar (from `../node_modules/react-native-search-bar`) @@ -492,6 +495,8 @@ EXTERNAL SOURCES: :path: "../node_modules/react-native-gesture-handler" RNKeychain: :path: "../node_modules/react-native-keychain" + RNPrivacySnapshot: + :path: "../node_modules/react-native-privacy-snapshot" RNReanimated: :path: "../node_modules/react-native-reanimated" RNScreens: @@ -559,6 +564,7 @@ SPEC CHECKSUMS: RNFS: 2bd9eb49dc82fa9676382f0585b992c424cd59df RNGestureHandler: 8f09cd560f8d533eb36da5a6c5a843af9f056b38 RNKeychain: 840f8e6f13be0576202aefcdffd26a4f54bfe7b5 + RNPrivacySnapshot: 71919dde3c6a29dd332115409c2aec564afee8f4 RNReanimated: b5ccb50650ba06f6e749c7c329a1bc3ae0c88b43 RNScreens: c526239bbe0e957b988dacc8d75ac94ec9cb19da RNSearchBar: 9860431356b7d12a8449d2fddb2b5f3c78d1e99f diff --git a/package.json b/package.json index 6bf1f8d8..7cc69669 100644 --- a/package.json +++ b/package.json @@ -40,6 +40,7 @@ "react-native-gesture-handler": "^1.6.1", "react-native-keychain": "^4.0.5", "react-native-mail": "standardnotes/react-native-mail#9862c76", + "react-native-privacy-snapshot": "rhdeck/react-native-privacy-snapshot#529e462", "react-native-reanimated": "^1.9.0", "react-native-safe-area-context": "^3.1.1", "react-native-screens": "^2.9.0", diff --git a/src/lib/ApplicationState.ts b/src/lib/ApplicationState.ts index dba8379d..d6377046 100644 --- a/src/lib/ApplicationState.ts +++ b/src/lib/ApplicationState.ts @@ -7,6 +7,7 @@ import { NativeModules, Platform, } from 'react-native'; +import { hide, show } from 'react-native-privacy-snapshot'; import { ApplicationEvent, ApplicationService, @@ -473,6 +474,7 @@ export class ApplicationState extends ApplicationService { } if (isResumingFromBackground || isResuming) { + hide(); // hide privacy lock over the app (iOS only) if (isResumingFromBackground) { this.notifyOfStateChange(AppStateType.ResumingFromBackground); } @@ -482,6 +484,7 @@ export class ApplicationState extends ApplicationService { } if (isLosingFocus) { + show(); // show privacy lock over the app (iOS only) this.notifyOfStateChange(AppStateType.LosingFocus); // If a privileges authentication session is in progress, we don't want to lock the application diff --git a/src/types/react-native-privacy-snapshot/index.d.ts b/src/types/react-native-privacy-snapshot/index.d.ts new file mode 100644 index 00000000..872a2eae --- /dev/null +++ b/src/types/react-native-privacy-snapshot/index.d.ts @@ -0,0 +1,5 @@ +declare module 'react-native-privacy-snapshot' { + export function show(): void; + export function hide(): void; + export function enabled(enabledFlag: boolean): void; +} diff --git a/yarn.lock b/yarn.lock index f6413254..0a18f71f 100644 --- a/yarn.lock +++ b/yarn.lock @@ -6205,6 +6205,10 @@ react-native-platform-touchable@^1.1.1: resolved "https://registry.yarnpkg.com/react-native-platform-touchable/-/react-native-platform-touchable-1.1.1.tgz#fde4acc65eea585d28b164d0c3716a42129a68e4" integrity sha1-/eSsxl7qWF0osWTQw3FqQhKaaOQ= +react-native-privacy-snapshot@rhdeck/react-native-privacy-snapshot#529e462: + version "1.0.0" + resolved "https://codeload.github.com/rhdeck/react-native-privacy-snapshot/tar.gz/529e4627d93f67752a27e82a040ff7b64dca0783" + react-native-reanimated@^1.9.0: version "1.9.0" resolved "https://registry.yarnpkg.com/react-native-reanimated/-/react-native-reanimated-1.9.0.tgz#38676c99dd585504fdc7331efb45e5f48ec7339a"