TBXark / PinterestSegment

A Pinterest-like segment control with masking animation.
http://tbxark.com/2016/12/08/2016-12-08-Swift-Pinterst/
MIT License
686 stars 56 forks source link

How to bind it by RxCocoa #8

Open selfishout opened 6 years ago

selfishout commented 6 years ago

Hi there I want to populate PinterestSegment reactively from network but I don't know how to get that screen shot 2018-07-30 at 2 46 30 pm screen shot 2018-07-30 at 2 46 48 pm

Actually output is a transformation of input to something intelligible for the view and all of those transformation done into ViewModel :

for news which binded to tableView everything works perfectly but when I try binding services (from Service Model) to PinterstSegment , I've got an error which present in above but for the sake of integrity the error is :

Cannot invoke 'drive' with an argument list of type '([String])'

TBXark commented 6 years ago

extension Reactive where Base: PinterestSegment {

    /// Bindable sink for `titles ` property.
    public var titles: Binder<[String]> {
        return Binder(base) { segment, titles in
            segment.titles = titles
        }
    }
}
selfishout commented 6 years ago

Thanks but how could I bind it to PinterestSegment View as I have trying to do like this : output.services.drive(newsSegment.rx.titles) I've got an error : Generic parameter 'Self' could not be inferred

How could I get rid of this annoying error ? Thanks

adrianod1as commented 5 years ago

Actually, it works

Driver.of(["it", "works", "!"])
.drive(segment.rx.titles)
.disposed(by: bag)

I believe the problem is that output.services is not a Driver<[String]> type.

P.S.: And since I'm here, I guess I gonna throw another useful extension for future readers. 😄

extension Reactive where Base: PinterestSegment {

    public var valueChange: Observable<Int> {
        return Observable.create { observable in
            self.base.valueChange = { index in
                observable.onNext(index)
            }
            return Disposables.create()
        }
    }

    public var itemSelected: ControlEvent<Int> {
        return ControlEvent(events: valueChange)
    }
}