From af7ebe158715fc2ff28602a80c66ab94700ab438 Mon Sep 17 00:00:00 2001 From: Arturs Krumins Date: Mon, 30 Sep 2024 22:45:39 +0300 Subject: [PATCH] ios: user picker sheet concurent animation (#4955) * ios: user picker sheet concurent animation * bind showSettings; cleanup --- .../Shared/Views/ChatList/ChatListView.swift | 84 +++++++++++-------- .../Shared/Views/ChatList/UserPicker.swift | 2 +- 2 files changed, 51 insertions(+), 35 deletions(-) diff --git a/apps/ios/Shared/Views/ChatList/ChatListView.swift b/apps/ios/Shared/Views/ChatList/ChatListView.swift index 7d6142bcef..856199a405 100644 --- a/apps/ios/Shared/Views/ChatList/ChatListView.swift +++ b/apps/ios/Shared/Views/ChatList/ChatListView.swift @@ -20,6 +20,54 @@ enum UserPickerSheet: Identifiable { var id: Self { self } } +struct UserPickerSheetView: View { + let sheet: UserPickerSheet + @EnvironmentObject var chatModel: ChatModel + @Binding var showSettings: Bool + @State private var loaded = false + + var body: some View { + Group { + if loaded, let currentUser = chatModel.currentUser { + switch sheet { + case .address: + NavigationView { + UserAddressView(shareViaProfile: currentUser.addressShared) + .navigationTitle("SimpleX address") + .navigationBarTitleDisplayMode(.large) + .modifier(ThemedBackground(grouped: true)) + } + case .chatProfiles: + NavigationView { + UserProfilesView() + } + case .currentProfile: + NavigationView { + UserProfile() + .navigationTitle("Your current profile") + .modifier(ThemedBackground(grouped: true)) + } + case .chatPreferences: + NavigationView { + PreferencesView(profile: currentUser.profile, preferences: currentUser.fullPreferences, currentPreferences: currentUser.fullPreferences) + .navigationTitle("Your preferences") + .navigationBarTitleDisplayMode(.large) + .modifier(ThemedBackground(grouped: true)) + } + case .useFromDesktop: + ConnectDesktopView(viaSettings: false) + case .settings: + SettingsView(showSettings: $showSettings) + .navigationBarTitleDisplayMode(.large) + } + } + } + .task { + withAnimation(.easeOut(duration: 0.1)) { loaded = true } + } + } +} + struct ChatListView: View { @EnvironmentObject var chatModel: ChatModel @EnvironmentObject var theme: AppTheme @@ -63,40 +111,8 @@ struct ChatListView: View { UserPicker(userPickerShown: $userPickerShown, activeSheet: $activeUserPickerSheet) } ) - .sheet(item: $activeUserPickerSheet) { sheet in - if let currentUser = chatModel.currentUser { - switch sheet { - case .address: - NavigationView { - UserAddressView(shareViaProfile: currentUser.addressShared) - .navigationTitle("SimpleX address") - .navigationBarTitleDisplayMode(.large) - .modifier(ThemedBackground(grouped: true)) - } - case .chatProfiles: - NavigationView { - UserProfilesView() - } - case .currentProfile: - NavigationView { - UserProfile() - .navigationTitle("Your current profile") - .modifier(ThemedBackground(grouped: true)) - } - case .chatPreferences: - NavigationView { - PreferencesView(profile: currentUser.profile, preferences: currentUser.fullPreferences, currentPreferences: currentUser.fullPreferences) - .navigationTitle("Your preferences") - .navigationBarTitleDisplayMode(.large) - .modifier(ThemedBackground(grouped: true)) - } - case .useFromDesktop: - ConnectDesktopView(viaSettings: false) - case .settings: - SettingsView(showSettings: $showSettings) - .navigationBarTitleDisplayMode(.large) - } - } + .sheet(item: $activeUserPickerSheet) { + UserPickerSheetView(sheet: $0, showSettings: $showSettings) } .onChange(of: activeUserPickerSheet) { if $0 != nil { diff --git a/apps/ios/Shared/Views/ChatList/UserPicker.swift b/apps/ios/Shared/Views/ChatList/UserPicker.swift index 223d782f36..b7818bfac4 100644 --- a/apps/ios/Shared/Views/ChatList/UserPicker.swift +++ b/apps/ios/Shared/Views/ChatList/UserPicker.swift @@ -229,7 +229,7 @@ struct ListRow: ViewModifier { startLocation = gesture.location(in: nil) task = Task { do { - try await Task.sleep(nanoseconds: 100_000000) + try await Task.sleep(nanoseconds: 200_000000) await MainActor.run { representer?.touchDown = true } } catch { } }