yonat / MultiSlider

UISlider clone with multiple thumbs and values, range highlight, optional snap intervals, optional value labels, either vertical or horizontal.
MIT License
494 stars 113 forks source link

Constraints breaking in SwiftUI Form #38

Closed anmolrajpal closed 4 years ago

anmolrajpal commented 4 years ago

Description of the problem: When implementing MultiSlider in SwiftUI Form, the height constraints break which causes the slider to disappear until I explicitly scroll back and forth to its position.

My Installation Process

File -> Swift Packages -> Add Package Dependency -> [URL: https://github.com/yonat/MultiSlider], [Branch: swiftui]

Code Snippet

    Form {
        Section {
            VStack {
                HStack {
                    Text("Age")
                    Spacer()
                    Text("\(Int(selectedAgeRange[0])) - \(Int(selectedAgeRange[1]))")
                }.font(.title)
                MultiValueSlider(
                    value: $selectedAgeRange,
                    minimumValue: 18,
                    maximumValue: 80,
                    snapStepSize: 1,
                    outerTrackColor: .lightGray,
                    keepsDistanceBetweenThumbs: true
                )
            }
        }
    }

Debug Log

When the slider is not visible


(
"<NSAutoresizingMaskLayoutConstraint:0x283b505a0 h=--& v=--& multi_slider.height == 63   (active, names: multi_slider:0x137f04cb0 )>",
"<NSLayoutConstraint:0x283b5b890 multi_slider.height == 31   (active, names: multi_slider:0x137f04cb0 )>"
)

Will attempt to recover by breaking constraint <NSLayoutConstraint:0x283b5b890 multi_slider.height == 31 (active, names: multi_slider:0x137f04cb0 )>


> When I scroll back & forth to its position & then slider appears

[Warning] Warning once only: Detected a case where constraints ambiguously suggest a height of zero for a table view cell's content view. We're considering the collapse unintentional and using standard height instead. Cell: <SwiftUI.ListCoreCellHost: 0x13c214b00; baseClass = UITableViewCell; frame = (0 199.667; 374 0.666667); clipsToBounds = YES; autoresize = W; layer = <CALayer: 0x2818bd660>>

yonat commented 4 years ago

Trying to reproduce this problem, I'm able to see the warning but not to cause the slider to disappear. Please add code that reproduces the disappearance problem, so I can find how to solve it.

yonat commented 4 years ago

@anmolrajpal Still a problem? To help me help you, please create a minimal reproducible project:

  1. Fork this repo. (See instructions)
  2. Open the project in the Example directory.
  3. Change the code there to make the problem appear.

Then just link to your fork here.