If I ON/OFF the darkmode with a button (by a bool value) on my view, my List elements are deleted. Not only do they disappear on the view, the list is actually becomes empty. The list declared in the AlarmModel, maybe thats the problem, I initialize an AlarmModel in the HomeView? How can I solve it?
struct ContentView: View {
@State var isDarkMode = true
var body: some View {
NavigationView {
HomeView(isDarkMode: self.$isDarkMode)
.navigationBarTitle("")
.navigationBarHidden(true)
}.preferredColorScheme(self.isDarkMode ? .dark : .light)
}
struct ContentView_Previews: PreviewProvider {
static var previews: some View {
ContentView()
}
}
struct HomeView : View {
@Binding var isDarkMode: Bool
@State var isEditMode = false
@ObservedObject var alarmModel : AlarmModel = AlarmModel()
@ObservedObject var clockViewModel : ClockViewModel = ClockViewModel()
var body: some View {
GeometryReader { proxy in
VStack(/*spacing: 15*/) {
TopBarView(alarmModel: self.alarmModel, clockViewModel: self.clockViewModel, isDarkMode: self.$isDarkMode, isEditMode: self.$isEditMode)
ClockView(clockViewModel: self.clockViewModel, isEditMode: self.$isEditMode)
AlarmListView(alarmModel: self.alarmModel).opacity(self.isEditMode ? 0 : 1)
}
}
}
}
}