AutoCat/AutoCat/Screens/LocationPickerScreen/LocationPickerScreen.swift

57 lines
1.5 KiB
Swift

//
// LocationPickerScreen.swift
// AutoCat
//
// Created by Selim Mustafaev on 27.07.2024.
// Copyright © 2024 Selim Mustafaev. All rights reserved.
//
import SwiftUI
import AutoCatCore
import MapKit
struct LocationPickerScreen: View {
@Environment(\.dismiss) var dismiss
@State var viewModel: LocationPickerViewModel
init(event: VehicleEventDto, onUpdate: @escaping (VehicleEventDto) -> Void) {
self.viewModel = LocationPickerViewModel(
locationService: ServiceContainer.shared.resolve(LocationServiceProtocol.self),
event: event,
onUpdate: onUpdate
)
}
var body: some View {
ZStack {
Map(initialPosition: viewModel.position)
.mapControls {
MapUserLocationButton()
}
.onMapCameraChange(frequency: .onEnd) { context in
Task { await viewModel.updateEvent(center: context.region.center) }
}
Image(systemName: "mappin.and.ellipse")
.resizable()
.aspectRatio(contentMode: .fit)
.frame(height: 48)
.offset(.init(width: 0, height: -16))
.foregroundColor(.blue)
}
//.ignoresSafeArea()
.navigationTitle(viewModel.event.location)
.toolbar {
ToolbarItem(placement: .primaryAction) {
Button("Done") {
viewModel.done()
dismiss()
}
}
}
}
}