spacenation / swiftui-sliders

:rocket: SwiftUI Sliders with custom styles
MIT License
793 stars 84 forks source link

Adding onEditingChange breaks Swift #21

Closed jimijon closed 3 years ago

jimijon commented 3 years ago

I can't get this to compile: If I take out onEditingChange it will compile.

    RangeSlider(range: $range)
            .rangeSliderStyle(
                HorizontalRangeSliderStyle(
                    track:
                    HorizontalRangeTrack(
                        view: Capsule().foregroundColor(Color("TPOrange"))
                    )
                        .background(Capsule().foregroundColor(Color("TPOrange").opacity(0.30)))
                        .frame(height: 8),
                    lowerThumb: Circle().foregroundColor(Color(UIColor(named: "TPLightGrey")!)),
                    upperThumb: Circle().foregroundColor(Color(UIColor(named: "TPLightGrey")!)),
                    lowerThumbSize: CGSize(width: 32, height: 32),
                    upperThumbSize: CGSize(width: 32, height: 32),
                    options: .forceAdjacentValue,
                    onEditingChanged: {
                       value in
                       if !value {
                           self.queryCallback()
                       }
                   }
                )

        ).padding([.horizontal]).frame(height: 64)
ay42 commented 3 years ago

@jimijon does it compile if you uncomment just this line self.queryCallback() ?

jimijon commented 3 years ago

nope: /Users/James/Development/TrendPlaySwiftUI/TrendPlay2/TrendPlay2/BaseWidgetClasses/TrendSlider.swift:323:17: Expression type 'HorizontalRangeSliderStyle<, , _>' is ambiguous without more context

jimijon commented 3 years ago

This used to work in 0.6. I shipped a product last year.. updating for release this year and now have these two bugs.

jimijon commented 3 years ago

Really would like to get these two problems resolved before the weekend is over if possible as I have an impatient client... I really don't want to migrate backwards. Thanks for the great component otherwise!

ay42 commented 3 years ago

@jimijon you have onEditingChanged in Style initializer. But it should be in the slider init. Try it.

jimijon commented 3 years ago

Error: Extra argument onEditingChanged

var hRangeSlider: some View {

      return RangeSlider(range: $range)
            .rangeSliderStyle(
                HorizontalRangeSliderStyle(
                    track:
                    HorizontalRangeTrack(
                        view: Capsule().foregroundColor(Color("TPOrange"))
                    )
                        .background(Capsule().foregroundColor(Color("TPOrange").opacity(0.30)))
                        .frame(height: 8),
                    lowerThumb: Circle().foregroundColor(Color(UIColor(named: "TPLightGrey")!)),
                    upperThumb: Circle().foregroundColor(Color(UIColor(named: "TPLightGrey")!)),
                    lowerThumbSize: CGSize(width: 32, height: 32),
                    upperThumbSize: CGSize(width: 32, height: 32),
                    options: .forceAdjacentValue
                    ),
                onEditingChanged: {
                    value in
                    if !value {
                        self.queryCallback()
                    }
                }

        ).padding([.horizontal]).frame(height: 64)
    }
jimijon commented 3 years ago

OH THE INITS! I missed those (upgrading threw me off)

This fixes both of my issues:

return RangeSlider(range: $range, in: lBound...uBound, step: 1, onEditingChanged: { value in if !value {self.queryCallback()}}) .rangeSliderStyle( HorizontalRangeSliderStyle(

                track:
                HorizontalRangeTrack(
                    view: Capsule().foregroundColor(Color("TPOrange"))
                )
                    .background(Capsule().foregroundColor(Color("TPOrange").opacity(0.30)))
                    .frame(height: 8),
                lowerThumb: Circle().foregroundColor(Color(UIColor(named: "TPLightGrey")!)),
                upperThumb: Circle().foregroundColor(Color(UIColor(named: "TPLightGrey")!)),
                lowerThumbSize: CGSize(width: 32, height: 32),
                upperThumbSize: CGSize(width: 32, height: 32),
                options: .forceAdjacentValue
                )

    ).padding([.horizontal]).frame(height: 64)