Giter VIP home page Giter VIP logo

Comments (7)

indragiek avatar indragiek commented on July 16, 2024

I'd like to help with this. Can't be sure when I'll get to it, but if someone else has time before I do they can feel free to steal it.

from reactiveanimation.

indragiek avatar indragiek commented on July 16, 2024

Should this use the same RAN struct, or should it be separated into something like RANView and RANConstraint? The former would be get a little icky implementation-wise, but the latter feels like you're repeating something that can be inferred anyways.

from reactiveanimation.

jspahrsummers avatar jspahrsummers commented on July 16, 2024

@indragiek It should definitely use a different type but! we can cheat and change RAN into a free function that selects the right type. :trollface:

from reactiveanimation.

indragiek avatar indragiek commented on July 16, 2024

@jspahrsummers Nice 👍

from reactiveanimation.

indragiek avatar indragiek commented on July 16, 2024

@jspahrsummers If I make RAN a free function to have it choose the correct type, how will accessing the properties work? RANView has alpha, bounds, etc. and RANConstraint would only have constant. Making both conform to a common protocol doesn't seem feasible.

from reactiveanimation.

indragiek avatar indragiek commented on July 16, 2024

@jspahrsummers Never mind, that was dumb. Forgot about function overloading.

from reactiveanimation.

thebarndog avatar thebarndog commented on July 16, 2024

I was making my own local copy to use in one of my projects and there's a problem with the current PR & animating constraints, mainly because those animations require that the constraint value be set outside of animateWithDuration. Furthermore you have to call view.layoutIfNeeded() in the animation block. That means the current implementation for constraints in the PR and branch doesn't animate.

The way I was thinking about doing is was:

  1. Add a view property to the constraints struct
  2. call constraint.view?.layoutIfNeeded() in the binding
public struct ReactiveConstraint {
    private weak var constraint: NSLayoutConstraint?
    private weak var view: UIView?
    private let willDealloc: SignalProducer<(), NoError>

    public init(_ constraint: NSLayoutConstraint, view: UIView?) {
        self.constraint = constraint
        self.view = view
        self.willDealloc = constraint.rac_willDeallocSignal()
            .toSignalProducer()
            .map { _ in () }
            .flatMapError {
                fatalError("rac_willDeallocSignal failed with error: \($0)")
                ()
        }
    }
}

public func <~ (constraint: ReactiveConstraint, signal: Signal<CGFloat, NoError>) -> Disposable {
    let disposable = CompositeDisposable()
    let constraintDisposable = constraint.willDealloc.startWithCompleted {
        disposable.dispose()
    }
    disposable.addDisposable(constraintDisposable)

    let signalDisposable = signal.observe(Observer(
        next: {
            constraint.constraint?.constant = $0
            constraint.view?.layoutIfNeeded()
        },
        completed: {
            disposable.dispose()
        }
    ))

    disposable.addDisposable(signalDisposable)
    return disposable
}

Now my constraint animations work without having to change the animateEach method.

from reactiveanimation.

Related Issues (7)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.