From 878b1caa952621265007c6551f3397843d76e7a0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20D=E2=80=99Aquino?= Date: Fri, 17 Nov 2023 19:58:19 +0000 Subject: [PATCH] Fix onboarding post view not being dismissed MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This commit fixes the issue where clicking "post" on the onboarding sheet does not dismisses itself under certain device/iOS combos. The root cause is that the behavior of `dismiss` calls under a deeply nested view (i.e. not a direct subview of the sheet) is inconsistent depending on the device or iOS. This fix does two things: 1. It upgrades the usage of `presentationMode` (which is deprecated) to the new `dismiss` API 2. It makes the onboarding sheet view (A direct subview of the sheet) to listen to signals from the post view and use that to also call `dismiss()`, which is explicitly supported by Apple in their docs (https://developer.apple.com/documentation/swiftui/environmentvalues/dismiss) Testing ------- PASS Device: iPhone 13 mini (physical device) iOS: 17.1 Damus: This commit (Local build, no local mods) Setting: "Always show onboarding" is set to ON Coverage: 1. Clicking "post" on onboarding post view publishes the post and dismisses the view. PASS 2. Clicking "cancel" on onboarding post view dismisses the view without publishing. PASS 3. Dragging the onboarding post view down dismisses the view without publishing. PASS 4. Making a normal post (I replied to a thread) still publishes the post and dismisses the normal post view sheet. PASS Testing on other Device/iOS combos --------------------------------- PASS Preconditions: - iPhone 15 Pro (simulator) on iOS 17.0.1 - iPhone SE 3rd gen (simulator) on iOS 16.4 Damus: This commit (Local build, no local mods) Setting: "Always show onboarding" is set to ON Coverage: 1. Clicking "post" on onboarding post view publishes the post and dismisses the view. PASS Closes: https://github.com/damus-io/damus/issues/1726 Changelog-Fixed: Fix onboarding post view not being dismissed under certain conditions Signed-off-by: Daniel D’Aquino Reviewed-by: William Casarin Signed-off-by: William Casarin --- damus/Views/Onboarding/OnboardingSuggestionsView.swift | 8 +++++++- damus/Views/PostView.swift | 6 +----- 2 files changed, 8 insertions(+), 6 deletions(-) diff --git a/damus/Views/Onboarding/OnboardingSuggestionsView.swift b/damus/Views/Onboarding/OnboardingSuggestionsView.swift index 3a4eb307..773e22c1 100644 --- a/damus/Views/Onboarding/OnboardingSuggestionsView.swift +++ b/damus/Views/Onboarding/OnboardingSuggestionsView.swift @@ -19,7 +19,7 @@ struct OnboardingSuggestionsView: View { let first_post_examples: [String] = [first_post_example_1, first_post_example_2, first_post_example_3, first_post_example_4] let initial_text_suffix: String = "\n\n#introductions" - @Environment(\.presentationMode) private var presentationMode + @Environment(\.dismiss) var dismiss func next_page() { withAnimation { @@ -58,6 +58,12 @@ struct OnboardingSuggestionsView: View { placeholder_messages: self.first_post_examples, initial_text_suffix: self.initial_text_suffix ) + .onReceive(handle_notify(.post)) { _ in + // NOTE: Even though PostView already calls `dismiss`, that is not guaranteed to work under deeply nested views. + // Thus, we should also call `dismiss` from here (a direct subview of a sheet), which is explicitly supported by Apple. + // See https://github.com/damus-io/damus/issues/1726 for more context and information + dismiss() + } .tag(1) } .tabViewStyle(.page(indexDisplayMode: .never)) diff --git a/damus/Views/PostView.swift b/damus/Views/PostView.swift index 35573839..5b70c951 100644 --- a/damus/Views/PostView.swift +++ b/damus/Views/PostView.swift @@ -85,16 +85,12 @@ struct PostView: View { self.initial_text_suffix = initial_text_suffix } - @Environment(\.presentationMode) var presentationMode + @Environment(\.dismiss) var dismiss func cancel() { notify(.post(.cancel)) dismiss() } - - func dismiss() { - self.presentationMode.wrappedValue.dismiss() - } func send_post() { let refs = references.filter { ref in