Post

Replies

Boosts

Views

Activity

Reply to SwiftUI Timer not working inside Menu bar extra
Using a dedicated obervable object with a timer being initialized there will perfectly work while the open menu is blocking the runloop from SwiftUI. public final class MyObject: ObservableObject { @Published var showItem: Bool = false var cancellable = Set<AnyCancellable>() init() { Timer.publish(every: 5, on: .main, in: .common) .autoconnect() .sink(receiveValue: { [weak self] value in print(value) self?.showItem = true }) .store(in: &cancellable) } } And within the MenuBarExtra content closure, you can use something like: if myObject.showItem{ Button("Item 2") { } }
Topic: UI Frameworks SubTopic: SwiftUI Tags:
Oct ’23
Reply to Animation does not work with List, while works with ScrollView + ForEach
Some issue here. I have a MVP that outlines to issue easily: import SwiftUI struct ContentView: View { var body: some View { List { Element() Element() Element() } } } struct Element: View { @State var isOn: Bool = false var body: some View { VStack { HStack { Text("Hello, World!") Button("Toggle") { isOn.toggle() } } if isOn { Text("It's on!") .transition(.opacity) } } .animation(.default, value: isOn) } } #Preview { ContentView() .frame(width: 400) } When using LazyVStack instead of List, the animation works flawlessly.
Topic: UI Frameworks SubTopic: SwiftUI Tags:
5d