← All repositories

reportage

A life-logging app for iPhone

git clone https://code.inqk.net/reportage.git


commit 9775c8ab7a1ff1b91c2216d7a72d7721ef8bb4b4
parent 21f47eca1a71f5797e3fbc0c959c4e86686993da
Author: Michael Camilleri <[email protected]>
Date:   Thu, 22 Oct 2026 00:45:37 +0900

Blur the app behind App Lock instead of showing the lock screen

With App Lock on, every return to the app briefly showed the lock
screen, even within the delay the user had chosen. iOS animates a
returning app from the snapshot taken as it left, and that snapshot was
the lock screen.

This commit covers the app with a heavy blur of itself while it's in
the background, so the app switcher still shows nothing legible but a
return reads as the app coming into focus. The lock screen now appears
only when the app is actually locked. The return is also handled as
soon as the app becomes inactive rather than once it's active: within
the delay the blur comes straight off, and past it the blur becomes the
lock screen, with Face ID asked for once the app is active.

Co-Authored-By: Claude Opus 5.5 <[email protected]>

Diffstat

MNotes/Design.md | 11+++++++----
MReportage/Services/AppLock.swift | 47++++++++++++++++++++++++++++++++++-------------
MReportage/Views/LockView.swift | 43++++++++++++++++++++++++++++---------------
MTests/Unit/AppLockTests.swift | 25+++++++++++++++++++++++++

4 files changed, 94 insertions(+), 32 deletions(-)

diff --git a/Notes/Design.md b/Notes/Design.md

@@ -824,10 +824,13 @@ or 15 minutes in the background. Only a return from the background locks:
 Face ID's own prompt and Control Center make the app inactive without
 leaving it.
 
-While the app is locked, or in the background with the lock on, a window
-above everything else covers it, so the app switcher's snapshot shows
-nothing. A survey opened by tapping a prompt waits beneath it until the app
-is unlocked. Notification actions, Instant Reports and Shortcuts show
+While the app is in the background with the lock on, a window above
+everything else blurs it, so the app switcher's snapshot shows nothing
+legible. iOS animates a returning app from that snapshot, so the blur shows
+briefly on every return; it comes off as soon as the app starts coming back,
+when it's inactive, rather than once it's active. If the app was away long
+enough to lock, the window shows the lock screen instead, and a survey
+opened by tapping a prompt waits beneath it until the app is unlocked. Notification actions, Instant Reports and Shortcuts show
 nothing, so they work while locked. The setting is per device and isn't
 synced or exported.
 

diff --git a/Reportage/Services/AppLock.swift b/Reportage/Services/AppLock.swift

@@ -44,17 +44,19 @@ extension AppLockSettings {
 /// Locks the app behind Face ID, or the device passcode when Face ID fails
 /// or isn't set up.
 ///
-/// While the app is locked, or in the background with the lock on, a window
-/// above everything else covers it, so the app switcher's snapshot shows
-/// nothing and a survey opened from a notification waits beneath until the
-/// app is unlocked. Notification actions and App Intents show nothing, so
+/// While the app is in the background with the lock on, a window above
+/// everything else blurs it, so the app switcher's snapshot shows nothing
+/// legible. While it's locked, the window shows the lock screen instead, and
+/// a survey opened from a notification waits beneath until the app is
+/// unlocked. Notification actions and App Intents show nothing, so
 /// they work while locked.
 @MainActor
 @Observable
 final class AppLock {
     private(set) var settings: AppLockSettings
     private(set) var isLocked: Bool
-    /// Whether the cover is shown: while locked, and in the background.
+    /// Whether the cover is shown: the lock screen while locked, and a blur
+    /// in the background.
     private(set) var isCovered: Bool
 
     /// When the app last went into the background unlocked. Only a return
@@ -65,6 +67,9 @@ final class AppLock {
     /// prompt itself makes the app inactive and active again, which mustn't
     /// ask again if it's cancelled.
     @ObservationIgnored private var promptsOnReturn = true
+    /// Set while the app is in the background, so the return is handled
+    /// once, at whichever of inactive or active comes first.
+    @ObservationIgnored private var isInBackground = false
     @ObservationIgnored private var window: UIWindow?
     @ObservationIgnored private var isAuthenticating = false
     private let defaults: UserDefaults
@@ -109,34 +114,46 @@ final class AppLock {
         guard settings.isEnabled else { return }
         if !isLocked { leftAt = now }
         promptsOnReturn = true
+        isInBackground = true
         isCovered = true
         updateWindow()
     }
 
     /// On launch the scene is inactive before it's active, so the cover is
-    /// up before anything else is seen.
-    func didBecomeInactive() {
+    /// up before anything else is seen. On a return from the background
+    /// it's inactive first too, so the blur comes off as early as it can.
+    func didBecomeInactive(now: Date = Date()) {
+        returnFromBackground(now: now)
         updateWindow()
     }
 
+    /// Face ID can only be asked for once the app is active.
     func didBecomeActive(now: Date = Date()) {
         guard settings.isEnabled else { return }
-        if !isLocked, let leftAt, settings.locks(leftAt: leftAt, now: now) {
-            isLocked = true
-        }
-        leftAt = nil
+        returnFromBackground(now: now)
         if isLocked {
             updateWindow()
             if promptsOnReturn {
                 promptsOnReturn = false
                 Task { await unlock() }
             }
-        } else {
+        } else if isCovered {
             isCovered = false
             updateWindow()
         }
     }
 
+    /// Locks the app if it was away long enough, and otherwise uncovers it.
+    private func returnFromBackground(now: Date) {
+        guard isInBackground else { return }
+        isInBackground = false
+        if !isLocked, let leftAt, settings.locks(leftAt: leftAt, now: now) {
+            isLocked = true
+        }
+        leftAt = nil
+        if !isLocked { isCovered = false }
+    }
+
     // MARK: Unlocking
 
     /// Asks for Face ID, falling back to the passcode, and unlocks if it
@@ -194,7 +211,11 @@ final class AppLock {
             guard window == nil, let scene = Self.windowScene else { return }
             let window = UIWindow(windowScene: scene)
             window.windowLevel = .alert + 1
-            window.rootViewController = UIHostingController(rootView: LockView(lock: self))
+            // Clear, so the blur shows the app beneath it.
+            let controller = UIHostingController(rootView: CoverView(lock: self))
+            controller.view.backgroundColor = .clear
+            window.rootViewController = controller
+            window.backgroundColor = .clear
             window.isHidden = false
             self.window = window
         } else {

diff --git a/Reportage/Views/LockView.swift b/Reportage/Views/LockView.swift

@@ -1,7 +1,22 @@
 import SwiftUI
 
-/// What covers the app while it's locked or in the background: the app's
-/// name and, once it's in front, a button to unlock it.
+/// What covers the app: the lock screen while it's locked, and otherwise a
+/// blur of the app itself, which is what the app switcher shows.
+struct CoverView: View {
+    let lock: AppLock
+
+    var body: some View {
+        if lock.isLocked {
+            LockView(lock: lock)
+        } else {
+            Rectangle()
+                .fill(.ultraThickMaterial)
+                .ignoresSafeArea()
+        }
+    }
+}
+
+/// The lock screen: the app's name and a button to unlock it.
 struct LockView: View {
     let lock: AppLock
 
@@ -12,20 +27,18 @@ struct LockView: View {
                 .screenTitle()
                 .accessibilityLabel(Text("Reportage"))
             Spacer()
-            if lock.isLocked {
-                Button {
-                    Task { await lock.unlock() }
-                } label: {
-                    Text("Unlock with \(Text(lock.methodName))", comment: "Unlocks the app; the method is Face ID, Touch ID or Passcode")
-                        .font(.body.weight(.semibold))
-                        .foregroundStyle(Theme.onAccent)
-                        .frame(maxWidth: .infinity, minHeight: 52)
-                        .background(Theme.accent, in: .capsule)
-                }
-                .buttonStyle(.plain)
-                .padding(.horizontal, Theme.margin)
-                .padding(.vertical, 12)
+            Button {
+                Task { await lock.unlock() }
+            } label: {
+                Text("Unlock with \(Text(lock.methodName))", comment: "Unlocks the app; the method is Face ID, Touch ID or Passcode")
+                    .font(.body.weight(.semibold))
+                    .foregroundStyle(Theme.onAccent)
+                    .frame(maxWidth: .infinity, minHeight: 52)
+                    .background(Theme.accent, in: .capsule)
             }
+            .buttonStyle(.plain)
+            .padding(.horizontal, Theme.margin)
+            .padding(.vertical, 12)
         }
         .frame(maxWidth: .infinity, maxHeight: .infinity)
         .background(Theme.paper)

diff --git a/Tests/Unit/AppLockTests.swift b/Tests/Unit/AppLockTests.swift

@@ -91,6 +91,31 @@ struct AppLockTests {
         #expect(owner.asked == 1)
     }
 
+    @Test("A return within the delay uncovers the app as soon as it's inactive")
+    func uncoversEarly() async {
+        let lock = await unlockedLock(delay: .fiveMinutes)
+        lock.didEnterBackground(now: start)
+        lock.didBecomeInactive(now: start.addingTimeInterval(60))
+        #expect(!lock.isCovered)
+        lock.didBecomeActive(now: start.addingTimeInterval(61))
+        #expect(!lock.isLocked)
+        #expect(!lock.isCovered)
+    }
+
+    @Test("A return after the delay locks as soon as it's inactive, and asks once active")
+    func locksEarly() async {
+        let lock = await unlockedLock()
+        lock.didEnterBackground(now: start)
+        lock.didBecomeInactive(now: start.addingTimeInterval(1))
+        #expect(lock.isLocked)
+        #expect(lock.isCovered)
+        await settle()
+        #expect(owner.asked == 1)
+        lock.didBecomeActive(now: start.addingTimeInterval(2))
+        await settle()
+        #expect(owner.asked == 2)
+    }
+
     @Test("A return after the delay locks and asks once, and unlocking uncovers")
     func afterDelay() async {
         let lock = await unlockedLock(delay: .oneMinute)