Skip to content

Commit bb5e239

Browse files
authored
Merge pull request #240 from TaskarCenterAtUW/fix-centering-bug
fix userSheet presented issue
2 parents 76fec89 + 264c178 commit bb5e239

File tree

2 files changed

+18
-6
lines changed

2 files changed

+18
-6
lines changed

GoInfoGame/GoInfoGame/UI/Map/CustomMap.swift

Lines changed: 17 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ struct CustomMap: UIViewRepresentable {
2121
@Binding var selectedQuest: DisplayUnit?
2222
@Binding var shouldShowPolyline: Bool
2323
@Binding var isPresented: Bool
24+
@Binding var isUserSettingsPresented: Bool
2425
@StateObject var locationManagerDelegate = LocationManagerDelegate()
2526

2627
@Binding var selectedAnnotations: Set<DisplayUnitAnnotation>
@@ -137,6 +138,8 @@ struct CustomMap: UIViewRepresentable {
137138

138139
let shadowOverlay: ShadowOverlay
139140

141+
var isCenteredOnUser = false
142+
140143
private let maxZoomAltitude: CLLocationDistance = 120
141144
private var zoomReachedLimit: Bool = false
142145

@@ -476,12 +479,21 @@ struct CustomMap: UIViewRepresentable {
476479
// Helper method to manage annotations
477480
private func manageAnnotations(_ mapView: MKMapView, context: Context) {
478481

479-
let existingCoordinates = mapView.annotations.compactMap { ($0 as? DisplayUnitAnnotation)?.coordinate }
482+
let existingCoordinates = mapView.annotations.compactMap {
483+
($0 as? DisplayUnitAnnotation)?.coordinate
484+
}
480485

481-
/// resetting region only when app is launched/re-launched
482-
if existingCoordinates.count == 0 {
483-
mapView.setCenter(userLocation, animated: true)
484-
}
486+
// Check for modals or settings before changing map
487+
if isPresented || isUserSettingsPresented {
488+
return
489+
}
490+
491+
// ✅ Only if no annotations and safe state
492+
if existingCoordinates.isEmpty && !context.coordinator.isCenteredOnUser {
493+
mapView.setCenter(userLocation, animated: true)
494+
context.coordinator.isCenteredOnUser = true
495+
}
496+
485497
context.coordinator.isRegionSet = true
486498

487499

GoInfoGame/GoInfoGame/UI/Map/MapView.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ struct MapView: View {
7373
selectedQuest: $viewModel.selectedQuest,
7474
shouldShowPolyline: $shouldShowPolyline,
7575

76-
isPresented: $isPresented, selectedAnnotations: $viewModel.selectedAnnotaions, isMultiSelectModeEnabled: $viewModel.isMultiSelectModeEnabled, selectedAnnotationType: $viewModel.selectedAnnotationType, showMultiSelectionBottomSheet: $showMultiSelectionBottomSheet,
76+
isPresented: $isPresented, isUserSettingsPresented: $showUserSettingsSheet, selectedAnnotations: $viewModel.selectedAnnotaions, isMultiSelectModeEnabled: $viewModel.isMultiSelectModeEnabled, selectedAnnotationType: $viewModel.selectedAnnotationType, showMultiSelectionBottomSheet: $showMultiSelectionBottomSheet,
7777
onMapViewCreated: { map in
7878
self.mapViewRef = map
7979
},

0 commit comments

Comments
 (0)