Coder Social home page Coder Social logo

Comments (9)

jspahrsummers avatar jspahrsummers commented on April 29, 2024

The reason you're running into a crash is because setting rcl_frame generates a value on rcl_frameSignal, leading to an infinite loop.

What is that code actually intended to do? It's generally a bad idea to create a feedback signal like this.

from reactivecocoalayout.

zakdances avatar zakdances commented on April 29, 2024

I just want to horizontally center self.playButton and set its y coordinate to 0. (so it's top is aligned to its superview top)

from reactivecocoalayout.

jspahrsummers avatar jspahrsummers commented on April 29, 2024

In that case, I would observe rcl_boundsSignal or rcl_intrinsicContentSizeSignal. You don't actually care about the frame, since the origin is completely discarded, and only the size remains.

from reactivecocoalayout.

zakdances avatar zakdances commented on April 29, 2024

Ok, I think I understand better. Does this also create an infinite loop?

RAC(myButton,rcl_bounds) = [myButton.rcl_boundsSignal 
replaceWidth:myButton.superview.rcl_boundsSignal.width];

If so, what's the best way to set the bounds or frame relative to its current value? That's what I'm trying to do here. Do I need to create a whole new rect signal when use RAC/RCL to set bounds/frame?

from reactivecocoalayout.

jspahrsummers avatar jspahrsummers commented on April 29, 2024

If so, what's the best way to set the bounds or frame relative to its current value? That's what I'm trying to do here.

Since signals operate over time, it doesn't really make sense to do that. What's your end goal?

from reactivecocoalayout.

zakdances avatar zakdances commented on April 29, 2024

I just want to position and size my UIView's. Nothing abnormal. The reason I've used the above code is to avoid doing something more verbose like this everytime:

RAC(myButton,rcl_bounds) = [RACSignal rectsWithX:[RACSignal return:@20] 
Y:myButton.superview.rcl_boundsSignal.y width:[RACSignal return:@40] 
height:myButton.superview.rcl_boundsSignal.height];

Is this the recommended approach?

See how constructing a new rect signal is more verbose than just getting the current bounds rect and adjusting one property (like width using replaceWidth)? I guess my what I've been doing is wrong so I'm gonna go back and look at the demos some more.

I know you're busy so I'm gonna close this (I won't keep responding). Your answers are VERY HELPFUL so thank you. If you get a chance, just let me know if the rectsWithX: approach is a bit more on the right trail. Or point me to the relevant line in one of the demos.

from reactivecocoalayout.

jspahrsummers avatar jspahrsummers commented on April 29, 2024

Constructing a new rect is indeed the recommended way to do it. RCL favors creating layouts from scratch, rather than trying to modify the existing properties of a view, because signal feedback is very tricky to handle correctly.

If you really want to base your layout on the current bounds rectangle, that's possible. You just don't want it to update when it changes in the future. Create a signal from the current value – don't observe the property:

RAC(myButton,rcl_bounds) = [[RACSignal
    return:MEDBox(myButton.bounds)]
    replaceWidth:myButton.superview.rcl_boundsSignal.width];

from reactivecocoalayout.

zakdances avatar zakdances commented on April 29, 2024

Perfect, thank you again.

from reactivecocoalayout.

jspahrsummers avatar jspahrsummers commented on April 29, 2024

No problem!

from reactivecocoalayout.

Related Issues (20)

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.