Fixed navigationDestination infinite loop
This commit is contained in:
parent
81bdf64b61
commit
544ae05b2a
@ -20,6 +20,7 @@
|
|||||||
7A131FD52D37B76A00DC7755 /* HistoryViewModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7A131FD42D37B76A00DC7755 /* HistoryViewModel.swift */; };
|
7A131FD52D37B76A00DC7755 /* HistoryViewModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7A131FD42D37B76A00DC7755 /* HistoryViewModel.swift */; };
|
||||||
7A1441662C297EDE00E79018 /* NotesScreen.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7A1441652C297EDE00E79018 /* NotesScreen.swift */; };
|
7A1441662C297EDE00E79018 /* NotesScreen.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7A1441652C297EDE00E79018 /* NotesScreen.swift */; };
|
||||||
7A1441682C297EFD00E79018 /* NotesViewModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7A1441672C297EFD00E79018 /* NotesViewModel.swift */; };
|
7A1441682C297EFD00E79018 /* NotesViewModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7A1441672C297EFD00E79018 /* NotesViewModel.swift */; };
|
||||||
|
7A17ADA02DC9F4A5002BA02A /* ScreenInput.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7A17AD9F2DC9F4A5002BA02A /* ScreenInput.swift */; };
|
||||||
7A1CF81629A42117007962DA /* Realm.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7A1CF81529A42117007962DA /* Realm.swift */; };
|
7A1CF81629A42117007962DA /* Realm.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7A1CF81529A42117007962DA /* Realm.swift */; };
|
||||||
7A1E78F62CE900330004B740 /* ReportScreen.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7A1E78F52CE900330004B740 /* ReportScreen.swift */; };
|
7A1E78F62CE900330004B740 /* ReportScreen.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7A1E78F52CE900330004B740 /* ReportScreen.swift */; };
|
||||||
7A1E78F82CE900440004B740 /* ReportViewModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7A1E78F72CE900440004B740 /* ReportViewModel.swift */; };
|
7A1E78F82CE900440004B740 /* ReportViewModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7A1E78F72CE900440004B740 /* ReportViewModel.swift */; };
|
||||||
@ -264,6 +265,7 @@
|
|||||||
7A1441652C297EDE00E79018 /* NotesScreen.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = NotesScreen.swift; sourceTree = "<group>"; };
|
7A1441652C297EDE00E79018 /* NotesScreen.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = NotesScreen.swift; sourceTree = "<group>"; };
|
||||||
7A1441672C297EFD00E79018 /* NotesViewModel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = NotesViewModel.swift; sourceTree = "<group>"; };
|
7A1441672C297EFD00E79018 /* NotesViewModel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = NotesViewModel.swift; sourceTree = "<group>"; };
|
||||||
7A15051124DB3E3000F39631 /* AnyEncodable.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AnyEncodable.swift; sourceTree = "<group>"; };
|
7A15051124DB3E3000F39631 /* AnyEncodable.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AnyEncodable.swift; sourceTree = "<group>"; };
|
||||||
|
7A17AD9F2DC9F4A5002BA02A /* ScreenInput.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ScreenInput.swift; sourceTree = "<group>"; };
|
||||||
7A1CF81529A42117007962DA /* Realm.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Realm.swift; sourceTree = "<group>"; };
|
7A1CF81529A42117007962DA /* Realm.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Realm.swift; sourceTree = "<group>"; };
|
||||||
7A1E78F52CE900330004B740 /* ReportScreen.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ReportScreen.swift; sourceTree = "<group>"; };
|
7A1E78F52CE900330004B740 /* ReportScreen.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ReportScreen.swift; sourceTree = "<group>"; };
|
||||||
7A1E78F72CE900440004B740 /* ReportViewModel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ReportViewModel.swift; sourceTree = "<group>"; };
|
7A1E78F72CE900440004B740 /* ReportViewModel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ReportViewModel.swift; sourceTree = "<group>"; };
|
||||||
@ -573,6 +575,7 @@
|
|||||||
children = (
|
children = (
|
||||||
7AB4E4652D58A16C0006D052 /* GenericError.swift */,
|
7AB4E4652D58A16C0006D052 /* GenericError.swift */,
|
||||||
7AE8CBB42DBA3B55005EF1AB /* Router.swift */,
|
7AE8CBB42DBA3B55005EF1AB /* Router.swift */,
|
||||||
|
7A17AD9F2DC9F4A5002BA02A /* ScreenInput.swift */,
|
||||||
);
|
);
|
||||||
path = Utils;
|
path = Utils;
|
||||||
sourceTree = "<group>";
|
sourceTree = "<group>";
|
||||||
@ -1357,6 +1360,7 @@
|
|||||||
7AE8CBB72DBA3E4E005EF1AB /* MainSplitScreen.swift in Sources */,
|
7AE8CBB72DBA3E4E005EF1AB /* MainSplitScreen.swift in Sources */,
|
||||||
7AFBE8CE2C308B53003C491D /* ACMessageView.swift in Sources */,
|
7AFBE8CE2C308B53003C491D /* ACMessageView.swift in Sources */,
|
||||||
7AAAFADE2C4D23620050410D /* ACImageSliderModel.swift in Sources */,
|
7AAAFADE2C4D23620050410D /* ACImageSliderModel.swift in Sources */,
|
||||||
|
7A17ADA02DC9F4A5002BA02A /* ScreenInput.swift in Sources */,
|
||||||
7A8AB76525A0DB8F00ECF2C1 /* BundleVersion.swift in Sources */,
|
7A8AB76525A0DB8F00ECF2C1 /* BundleVersion.swift in Sources */,
|
||||||
7A9519822D80B6E500E69883 /* RecordsViewModel.swift in Sources */,
|
7A9519822D80B6E500E69883 /* RecordsViewModel.swift in Sources */,
|
||||||
7AAAFADC2C4D1E130050410D /* ACImageSliderView+Modifier.swift in Sources */,
|
7AAAFADC2C4D1E130050410D /* ACImageSliderView+Modifier.swift in Sources */,
|
||||||
|
|||||||
@ -11,9 +11,9 @@ import AutoCatCore
|
|||||||
|
|
||||||
struct LocationEditScreen: View {
|
struct LocationEditScreen: View {
|
||||||
|
|
||||||
enum Screen: String {
|
enum Screen: Hashable {
|
||||||
|
|
||||||
case locationPicker
|
case locationPicker(ScreenInput<VehicleEventDto>)
|
||||||
}
|
}
|
||||||
|
|
||||||
@Environment(\.dismiss) var dismiss
|
@Environment(\.dismiss) var dismiss
|
||||||
@ -32,7 +32,14 @@ struct LocationEditScreen: View {
|
|||||||
List {
|
List {
|
||||||
DatePicker("Date", selection: $viewModel.date)
|
DatePicker("Date", selection: $viewModel.date)
|
||||||
.datePickerStyle(.compact)
|
.datePickerStyle(.compact)
|
||||||
NavigationLink(value: Screen.locationPicker) {
|
NavigationLink(
|
||||||
|
value: Screen.locationPicker(
|
||||||
|
.init(
|
||||||
|
initialValue: viewModel.event,
|
||||||
|
onChange: viewModel.onEventUpdated
|
||||||
|
)
|
||||||
|
)
|
||||||
|
) {
|
||||||
TextRowView(title: "Location", value: viewModel.event.location)
|
TextRowView(title: "Location", value: viewModel.event.location)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -45,8 +52,12 @@ struct LocationEditScreen: View {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
.navigationDestination(for: Screen.self) { _ in
|
.navigationDestination(for: Screen.self) { screen in
|
||||||
LocationPickerScreen(event: viewModel.event, onUpdate: viewModel.onEventUpdated)
|
|
||||||
|
switch screen {
|
||||||
|
case .locationPicker(let input):
|
||||||
|
LocationPickerScreen(event: input.initialValue, onUpdate: input.onChange)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -16,9 +16,9 @@ final class LocationEditViewModel {
|
|||||||
var event: VehicleEventDto
|
var event: VehicleEventDto
|
||||||
var date: Date
|
var date: Date
|
||||||
|
|
||||||
var onUpdate: (VehicleEventDto) -> Void
|
var onUpdate: ((VehicleEventDto) -> Void)?
|
||||||
|
|
||||||
init(event: VehicleEventDto, onUpdate: @escaping (VehicleEventDto) -> Void) {
|
init(event: VehicleEventDto, onUpdate: ((VehicleEventDto) -> Void)? = nil) {
|
||||||
self.event = event
|
self.event = event
|
||||||
self.date = Date(timeIntervalSince1970: event.date)
|
self.date = Date(timeIntervalSince1970: event.date)
|
||||||
self.onUpdate = onUpdate
|
self.onUpdate = onUpdate
|
||||||
@ -26,7 +26,7 @@ final class LocationEditViewModel {
|
|||||||
|
|
||||||
func done() {
|
func done() {
|
||||||
event.date = date.timeIntervalSince1970
|
event.date = date.timeIntervalSince1970
|
||||||
onUpdate(event)
|
onUpdate?(event)
|
||||||
}
|
}
|
||||||
|
|
||||||
func onEventUpdated(_ event: VehicleEventDto) {
|
func onEventUpdated(_ event: VehicleEventDto) {
|
||||||
|
|||||||
@ -16,7 +16,7 @@ struct LocationPickerScreen: View {
|
|||||||
|
|
||||||
@State var viewModel: LocationPickerViewModel
|
@State var viewModel: LocationPickerViewModel
|
||||||
|
|
||||||
init(event: VehicleEventDto, onUpdate: @escaping (VehicleEventDto) -> Void) {
|
init(event: VehicleEventDto, onUpdate: ((VehicleEventDto) -> Void)? = nil) {
|
||||||
|
|
||||||
self.viewModel = LocationPickerViewModel(
|
self.viewModel = LocationPickerViewModel(
|
||||||
locationService: ServiceContainer.shared.resolve(LocationServiceProtocol.self),
|
locationService: ServiceContainer.shared.resolve(LocationServiceProtocol.self),
|
||||||
|
|||||||
@ -50,6 +50,7 @@ struct NumberEditView: View {
|
|||||||
.frame(height: 220)
|
.frame(height: 220)
|
||||||
}
|
}
|
||||||
.padding(16)
|
.padding(16)
|
||||||
|
.gesture(DragGesture(), including: .gesture)
|
||||||
}
|
}
|
||||||
|
|
||||||
func buttonPressed(type: PNButtonType) {
|
func buttonPressed(type: PNButtonType) {
|
||||||
|
|||||||
28
AutoCat/Utils/ScreenInput.swift
Normal file
28
AutoCat/Utils/ScreenInput.swift
Normal file
@ -0,0 +1,28 @@
|
|||||||
|
//
|
||||||
|
// ScreenInput.swift
|
||||||
|
// AutoCat
|
||||||
|
//
|
||||||
|
// Created by Selim Mustafaev on 06.05.2025.
|
||||||
|
// Copyright © 2025 Selim Mustafaev. All rights reserved.
|
||||||
|
//
|
||||||
|
|
||||||
|
import Foundation
|
||||||
|
|
||||||
|
struct ScreenInput<T: Hashable> {
|
||||||
|
|
||||||
|
var initialValue: T
|
||||||
|
var onChange: ((T) -> Void)?
|
||||||
|
}
|
||||||
|
|
||||||
|
extension ScreenInput: Hashable {
|
||||||
|
|
||||||
|
static func == (lhs: ScreenInput<T>, rhs: ScreenInput<T>) -> Bool {
|
||||||
|
|
||||||
|
lhs.initialValue == rhs.initialValue
|
||||||
|
}
|
||||||
|
|
||||||
|
func hash(into hasher: inout Hasher) {
|
||||||
|
|
||||||
|
hasher.combine(initialValue)
|
||||||
|
}
|
||||||
|
}
|
||||||
Loading…
Reference in New Issue
Block a user