Add loading animation while syncing timeline position

This commit is contained in:
Shadowfacts 2023-01-01 12:25:44 -05:00
parent b81c83a250
commit 4dca231a06
3 changed files with 30 additions and 15 deletions

View File

@ -213,12 +213,10 @@ class TimelineViewController: UIViewController, TimelineLikeCollectionViewContro
clearSelectionOnAppear(animated: animated)
if case .notLoadedInitial = controller.state {
if restoreState() {
Task {
if await restoreState() {
await checkPresent(jumpImmediately: false)
}
} else {
Task {
await controller.loadInitial()
}
}
@ -329,19 +327,17 @@ class TimelineViewController: UIViewController, TimelineLikeCollectionViewContro
return activity
}
func restoreState() -> Bool {
func restoreState() async -> Bool {
guard persistsState,
Preferences.shared.timelineStateRestoration,
let position = mastodonController.persistentContainer.getTimelinePosition(timeline: timeline) else {
return false
}
loadViewIfNeeded()
Task {
await controller.restoreInitial {
await loadStatusesToRestore(position: position)
applyItemsToRestore(position: position)
}
}
return true
}
@ -492,15 +488,29 @@ class TimelineViewController: UIViewController, TimelineLikeCollectionViewContro
return false
}
if !alwaysPrompt {
_ = self.restoreState()
Task {
_ = await restoreState()
}
} else {
var config = ToastConfiguration(title: "Sync Position")
config.edge = .top
config.dismissAutomaticallyAfter = 5
config.systemImageName = "arrow.triangle.2.circlepath"
config.action = { [unowned self] toast in
toast.isUserInteractionEnabled = false
UIView.animateKeyframes(withDuration: 1, delay: 0, options: .repeat) {
UIView.addKeyframe(withRelativeStartTime: 0, relativeDuration: 0.5) {
toast.imageView!.transform = CGAffineTransform(rotationAngle: 0.5 * .pi)
}
UIView.addKeyframe(withRelativeStartTime: 0.5, relativeDuration: 0.5) {
// the translation is because the symbol isn't perfectly centered
toast.imageView!.transform = CGAffineTransform(translationX: -0.5, y: 0).rotated(by: .pi)
}
}
Task {
_ = await self.restoreState()
toast.dismissToast(animated: true)
_ = self.restoreState()
}
}
showToast(configuration: config, animated: true)
UIAccessibility.post(notification: .announcement, argument: "Synced Position Updated")

View File

@ -59,7 +59,9 @@ class TimelinesPageViewController: SegmentedPageViewController<TimelinesPageView
guard let vc = currentViewController as? TimelineViewController else {
return false
}
_ = vc.restoreState()
Task {
_ = await vc.restoreState()
}
return true
}),
]

View File

@ -12,6 +12,8 @@ class ToastView: UIView {
let configuration: ToastConfiguration
private(set) var imageView: UIImageView?
private var panRecognizer: UIPanGestureRecognizer!
private var shrinkAnimator: UIViewPropertyAnimator?
private var recognizedGesture = false
@ -61,6 +63,7 @@ class ToastView: UIView {
imageView.tintColor = .white
imageView.contentMode = .scaleAspectFit
stack.addArrangedSubview(imageView)
self.imageView = imageView
}
let titleLabel = UILabel()