SplitView icon indicating copy to clipboard operation
SplitView copied to clipboard

Map view jumps to old fraction when scrolled

Open stevengharris opened this issue 1 year ago • 5 comments

I'm evaluating this library and I found a problem when trying to put a Map (SwiftUI) into the Top view on a VSplit. I've reproduced it by adding a Map to the Demo sample simpleAdjustable Code below. Once I move the map (or zoom) the Split is resized back to an original position instead of retaining where the User left it. Is there a known workaround to resolve this? Video below.

case .simpleAdjustable:
                Split(
                    primary: {
                        Map(coordinateRegion: $region, annotationItems: annotations) {
                            MapPin(coordinate: $0.coordinate)
                        }
                    },
                    secondary: { Color.red }
                )
                .styling(color: .yellow)
                .layout(demo.holders[0].layout)
                .hide(demo.holders[0].hide)

https://github.com/user-attachments/assets/d35b85fd-f8d9-442b-b2ec-c22bd211a7ce

Other supporting code:

@State var region: MKCoordinateRegion = MKCoordinateRegion(center: CLLocationCoordinate2D(latitude: 37.09, longitude: -95.71), latitudinalMeters: Measurement(value: 15, unit: UnitLength.miles).converted(to: .meters).value, longitudinalMeters: Measurement(value: 15, unit: UnitLength.miles).converted(to: .meters).value)
let annotations: [City] = [ ]
struct City: Identifiable {
    let id = UUID()
    let name: String
    let coordinate: CLLocationCoordinate2D
}

Originally posted by @kylepinionseb in https://github.com/stevengharris/SplitView/discussions/43

stevengharris avatar Dec 16 '24 22:12 stevengharris

It turns out that a fix I made to allow the Split view to respond to changes in the split fraction caused this. I was a little worried at the time that there might be side-effects, but I could not find any. I believe you can fix the issue by removing or commenting out the following ~line 102 in Split.swift:

.onChange(of: fraction.value) { new in constrainedFraction = new }

I will have to follow-up with a fix that works in that case without screwing up yours. Unless you're also trying to set the fraction as discussed in https://github.com/stevengharris/SplitView/issues/29, it should not impact you to remove this. Thanks.

stevengharris avatar Dec 16 '24 22:12 stevengharris

Yes, disabling that line for me works. Thanks for the quick tip! I was experimenting with fraction, and it doesn't seem to cause a problem using that for an initial setting, and then the User can adjust and all seems well.

kylepinionseb avatar Dec 17 '24 16:12 kylepinionseb

Not to hop on an old thread but I am seeing the same issue when using .searchable in one of the split sides. Whatever change is triggered by the searchbar changing visibility seems to reset the SplitView.

shainmack avatar Sep 27 '25 04:09 shainmack

Not to hop on an old thread but I am seeing the same issue when using .searchable in one of the split sides. Whatever change is triggered by the searchbar changing visibility seems to reset the SplitView.

Update: I switched to using a Split() instead of an HSplit and it entirely fixed the issue!

shainmack avatar Sep 27 '25 04:09 shainmack

Thanks very much for posting your findings.

stevengharris avatar Sep 27 '25 18:09 stevengharris