Im my app I have a ScrollView with a LazyVStack inside.
The ForEach inside takes an array of DailyEvents:
struct DailyEvents: Equatable, Identifiable { var id: String { dayString + "\(events.count)" } let day: Date let events: [EventInfo] var isToday: Bool { day.isToday() } var dateString: String { DateFormatter.dayMonthDateFormtter.string(from: day) } var dayString: String { isToday ? "today".localized : DateFormatter.dayDateFormtter.string(from: day) } } So every time I add a new DailyEvents in the array, the LazyVStack updates properly.
But if I add a new EventInfo inside the events property of a DailyEvents already existing. The LazyVstack does not see the update and it does not reload.
If I switch LazyVstack for a VStack, everything works properly.
UI:
@ObservedObject var viewModel: ViewModel var scrollViewProxy = ScrollViewProxyManager() @SwiftUI.State private var isBackToTodayVisible = false private var events: [DailyEvents] { viewModel.dailyEvents.value ?? [] } var eventsList: some View { ZStack(alignment: .bottom) { ScrollView { ScrollViewReader { proxy in LazyVStack(alignment: .center, spacing: 0) { Spacer() .frame(height: 16) ForEach(events, id: \.id) { dailyEvent in makeDailyEvents(dailyEvent) } } .onAppear { scrollViewProxy.setProxy(proxy: proxy) } } } if isBackToTodayVisible { scrollTodayButton .padding(.bottom, 16) } } }
eventsare constant property?