damus

nostr ios client
git clone git://jb55.com/damus
Log | Files | Refs | README | LICENSE

commit 878b1caa952621265007c6551f3397843d76e7a0
parent 1fcbba5041553a388ca9f1cc89599b7a043101dd
Author: Daniel D’Aquino <daniel@daquino.me>
Date:   Fri, 17 Nov 2023 19:58:19 +0000

Fix onboarding post view not being dismissed

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 <daniel@daquino.me>
Reviewed-by: William Casarin <jb55@jb55.com>
Signed-off-by: William Casarin <jb55@jb55.com>

Diffstat:
Mdamus/Views/Onboarding/OnboardingSuggestionsView.swift | 8+++++++-
Mdamus/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 @@ -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 @@ -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