mirror of
https://github.com/Dimillian/IceCubesApp.git
synced 2025-01-31 10:12:19 +00:00
Better unread counter + animation
This commit is contained in:
parent
5c2148104c
commit
d0c2cd4520
1 changed files with 14 additions and 3 deletions
|
@ -3,6 +3,7 @@ import Foundation
|
||||||
import Models
|
import Models
|
||||||
import Observation
|
import Observation
|
||||||
import SwiftUI
|
import SwiftUI
|
||||||
|
import DesignSystem
|
||||||
|
|
||||||
@MainActor
|
@MainActor
|
||||||
@Observable class PendingStatusesObserver {
|
@Observable class PendingStatusesObserver {
|
||||||
|
@ -13,9 +14,11 @@ import SwiftUI
|
||||||
|
|
||||||
var pendingStatuses: [String] = [] {
|
var pendingStatuses: [String] = [] {
|
||||||
didSet {
|
didSet {
|
||||||
|
withAnimation(.default) {
|
||||||
pendingStatusesCount = pendingStatuses.count
|
pendingStatusesCount = pendingStatuses.count
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
func removeStatus(status: Status) {
|
func removeStatus(status: Status) {
|
||||||
if !disableUpdate, let index = pendingStatuses.firstIndex(of: status.id) {
|
if !disableUpdate, let index = pendingStatuses.firstIndex(of: status.id) {
|
||||||
|
@ -30,14 +33,18 @@ import SwiftUI
|
||||||
struct PendingStatusesObserverView: View {
|
struct PendingStatusesObserverView: View {
|
||||||
@State var observer: PendingStatusesObserver
|
@State var observer: PendingStatusesObserver
|
||||||
@Environment(UserPreferences.self) private var preferences
|
@Environment(UserPreferences.self) private var preferences
|
||||||
|
@Environment(Theme.self) private var theme
|
||||||
|
|
||||||
var body: some View {
|
var body: some View {
|
||||||
if observer.pendingStatusesCount > 0 {
|
if observer.pendingStatusesCount > 0 {
|
||||||
Button {
|
Button {
|
||||||
observer.scrollToIndex?(observer.pendingStatusesCount)
|
observer.scrollToIndex?(observer.pendingStatusesCount)
|
||||||
} label: {
|
} label: {
|
||||||
Text("\(observer.pendingStatusesCount)")
|
Text("\(observer.pendingStatusesCount)")
|
||||||
|
.contentTransition(.numericText(countsDown: true))
|
||||||
// Accessibility: this results in a frame with a size of at least 44x44 at regular font size
|
// Accessibility: this results in a frame with a size of at least 44x44 at regular font size
|
||||||
.frame(minWidth: 30, minHeight: 30)
|
.frame(minWidth: 16, minHeight: 16)
|
||||||
|
.font(.footnote)
|
||||||
}
|
}
|
||||||
.accessibilityLabel("accessibility.tabs.timeline.unread-posts.label-\(observer.pendingStatusesCount)")
|
.accessibilityLabel("accessibility.tabs.timeline.unread-posts.label-\(observer.pendingStatusesCount)")
|
||||||
.accessibilityHint("accessibility.tabs.timeline.unread-posts.hint")
|
.accessibilityHint("accessibility.tabs.timeline.unread-posts.hint")
|
||||||
|
@ -49,7 +56,11 @@ struct PendingStatusesObserverView: View {
|
||||||
.background(.thinMaterial)
|
.background(.thinMaterial)
|
||||||
#endif
|
#endif
|
||||||
.cornerRadius(8)
|
.cornerRadius(8)
|
||||||
.padding(12)
|
.overlay(
|
||||||
|
RoundedRectangle(cornerRadius: 8)
|
||||||
|
.stroke(theme.tintColor, lineWidth: 1)
|
||||||
|
)
|
||||||
|
.padding(8)
|
||||||
.frame(maxWidth: .infinity, maxHeight: .infinity, alignment: preferences.pendingLocation)
|
.frame(maxWidth: .infinity, maxHeight: .infinity, alignment: preferences.pendingLocation)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue