From dff679d994729306f7fa916d4411dfeca5a6b5bd Mon Sep 17 00:00:00 2001 From: Mauro Romito Date: Fri, 21 Jul 2023 11:01:12 +0200 Subject: [PATCH] avoid problems --- .../Sources/Application/AppSettings.swift | 4 ---- .../View/TimelineTableViewController.swift | 19 +++++++++++-------- .../DeveloperOptionsScreenModels.swift | 2 -- .../DeveloperOptionsScreenViewModel.swift | 5 +---- .../View/DeveloperOptionsScreen.swift | 7 ------- 5 files changed, 12 insertions(+), 25 deletions(-) diff --git a/ElementX/Sources/Application/AppSettings.swift b/ElementX/Sources/Application/AppSettings.swift index 7f53fd5f7..a89b45a5a 100644 --- a/ElementX/Sources/Application/AppSettings.swift +++ b/ElementX/Sources/Application/AppSettings.swift @@ -34,7 +34,6 @@ final class AppSettings { case readReceiptsEnabled case hasShownWelcomeScreen case notificationSettingsEnabled - case timelineDiffableAnimationsEnabled } private static var suiteName: String = InfoPlistReader.main.appGroupIdentifier @@ -218,7 +217,4 @@ final class AppSettings { @UserPreference(key: UserDefaultsKeys.notificationSettingsEnabled, defaultValue: false, storageType: .userDefaults(store)) var notificationSettingsEnabled - - @UserPreference(key: UserDefaultsKeys.timelineDiffableAnimationsEnabled, defaultValue: false, storageType: .userDefaults(store)) - var timelineDiffableAnimationsEnabled } diff --git a/ElementX/Sources/Screens/RoomScreen/View/TimelineTableViewController.swift b/ElementX/Sources/Screens/RoomScreen/View/TimelineTableViewController.swift index 2e9df3c36..f355b8cd9 100644 --- a/ElementX/Sources/Screens/RoomScreen/View/TimelineTableViewController.swift +++ b/ElementX/Sources/Screens/RoomScreen/View/TimelineTableViewController.swift @@ -122,10 +122,6 @@ class TimelineTableViewController: UIViewController { self?.paginateBackwardsIfNeeded() } .store(in: &cancellables) - - ServiceLocator.shared.settings.$timelineDiffableAnimationsEnabled - .weakAssign(to: \.shouldAnimate, on: self) - .store(in: &cancellables) configureDataSource() } @@ -137,12 +133,13 @@ class TimelineTableViewController: UIViewController { super.viewWillAppear(animated) guard !hasAppearedOnce else { return } - scrollToBottom(animated: false) + tableView.contentOffset.y = -1 hasAppearedOnce = true paginateBackwardsPublisher.send() - // We never want the table view to be fully at the bottom to allow the status bar tap to work properly - tableView.contentOffset.y = -1 + DispatchQueue.main.asyncAfter(deadline: .now() + 2) { + self.shouldAnimate = true + } } override func viewWillLayoutSubviews() { @@ -213,18 +210,24 @@ class TimelineTableViewController: UIViewController { // We only animate when new items come at the end of the timeline let animated = shouldAnimate && - hasAppearedOnce && snapshot.itemIdentifiers.first != currentSnapshot.itemIdentifiers.first dataSource.apply(snapshot, animatingDifferences: animated) } /// Scrolls to the bottom of the timeline. private func scrollToBottom(animated: Bool) { + guard !timelineItemsIDs.isEmpty else { + return + } tableView.scrollToRow(at: IndexPath(item: 0, section: 0), at: .top, animated: animated) } /// Scrolls to the top of the timeline. private func scrollToTop(animated: Bool) { + let index = timelineItemsIDs.count - 1 + guard index >= 0 else { + return + } tableView.scrollToRow(at: IndexPath(item: timelineItemsIDs.count - 1, section: 0), at: .bottom, animated: animated) } diff --git a/ElementX/Sources/Screens/Settings/DeveloperOptionsScreen/DeveloperOptionsScreenModels.swift b/ElementX/Sources/Screens/Settings/DeveloperOptionsScreen/DeveloperOptionsScreenModels.swift index 2dfd7daf3..abea557e1 100644 --- a/ElementX/Sources/Screens/Settings/DeveloperOptionsScreen/DeveloperOptionsScreenModels.swift +++ b/ElementX/Sources/Screens/Settings/DeveloperOptionsScreen/DeveloperOptionsScreenModels.swift @@ -30,7 +30,6 @@ struct DeveloperOptionsScreenViewStateBindings { var readReceiptsEnabled: Bool var isEncryptionSyncEnabled: Bool var notificationSettingsEnabled: Bool - var timelineDiffableAnimationsEnabled: Bool } enum DeveloperOptionsScreenViewAction { @@ -39,6 +38,5 @@ enum DeveloperOptionsScreenViewAction { case changedReadReceiptsEnabled case changedIsEncryptionSyncEnabled case changedNotificationSettingsEnabled - case changedTimelineDiffableAnimationsEnabled case clearCache } diff --git a/ElementX/Sources/Screens/Settings/DeveloperOptionsScreen/DeveloperOptionsScreenViewModel.swift b/ElementX/Sources/Screens/Settings/DeveloperOptionsScreen/DeveloperOptionsScreenViewModel.swift index c17c53c81..f07434ea4 100644 --- a/ElementX/Sources/Screens/Settings/DeveloperOptionsScreen/DeveloperOptionsScreenViewModel.swift +++ b/ElementX/Sources/Screens/Settings/DeveloperOptionsScreen/DeveloperOptionsScreenViewModel.swift @@ -30,8 +30,7 @@ class DeveloperOptionsScreenViewModel: DeveloperOptionsScreenViewModelType, Deve userSuggestionsEnabled: appSettings.userSuggestionsEnabled, readReceiptsEnabled: appSettings.readReceiptsEnabled, isEncryptionSyncEnabled: appSettings.isEncryptionSyncEnabled, - notificationSettingsEnabled: appSettings.notificationSettingsEnabled, - timelineDiffableAnimationsEnabled: appSettings.timelineDiffableAnimationsEnabled) + notificationSettingsEnabled: appSettings.notificationSettingsEnabled) let state = DeveloperOptionsScreenViewState(bindings: bindings) super.init(initialViewState: state) @@ -53,8 +52,6 @@ class DeveloperOptionsScreenViewModel: DeveloperOptionsScreenViewModelType, Deve appSettings.isEncryptionSyncEnabled = state.bindings.isEncryptionSyncEnabled case .changedNotificationSettingsEnabled: appSettings.notificationSettingsEnabled = state.bindings.notificationSettingsEnabled - case .changedTimelineDiffableAnimationsEnabled: - appSettings.timelineDiffableAnimationsEnabled = state.bindings.timelineDiffableAnimationsEnabled case .clearCache: callback?(.clearCache) } diff --git a/ElementX/Sources/Screens/Settings/DeveloperOptionsScreen/View/DeveloperOptionsScreen.swift b/ElementX/Sources/Screens/Settings/DeveloperOptionsScreen/View/DeveloperOptionsScreen.swift index 8aa652f7c..b254ece40 100644 --- a/ElementX/Sources/Screens/Settings/DeveloperOptionsScreen/View/DeveloperOptionsScreen.swift +++ b/ElementX/Sources/Screens/Settings/DeveloperOptionsScreen/View/DeveloperOptionsScreen.swift @@ -63,13 +63,6 @@ struct DeveloperOptionsScreen: View { .onChange(of: context.userSuggestionsEnabled) { _ in context.send(viewAction: .changedUserSuggestionsEnabled) } - - Toggle(isOn: $context.timelineDiffableAnimationsEnabled) { - Text("Enable diffable animations in the timeline") - } - .onChange(of: context.timelineDiffableAnimationsEnabled) { _ in - context.send(viewAction: .changedTimelineDiffableAnimationsEnabled) - } } Section {