Code Monkey home page Code Monkey logo

Comments (5)

lucdion avatar lucdion commented on May 10, 2024

Hi @rgdev, items are re-layouted only when their container size change or when an item's flex property is modified. For any other changes, you must call markDirty() to force a re-layout.

See https://github.com/layoutBox/FlexLayout#markdirty for more details.

In your case you need:

   @objc func onButtonPressed(sender: UIButton) {
        mainView.label.text = "goodbye"
        mainView.label.flex.markDirty()
        mainView.setNeedsLayout()
    }

from flexlayout.

rgdev avatar rgdev commented on May 10, 2024

Such a silly mistake, thank you for the swift answer!
Do you think it would be possible to have UILabels to automatically mark themselves as dirty when their text field is updated in a futur version ?

from flexlayout.

lucdion avatar lucdion commented on May 10, 2024

@rgdev you can do that easily by subclassing the UILabel class (ex: Label / FlexLabel) and override the text property setter.

You can also add an UILabel extension and add a property OR a method for setting the text that would call markDirty().
ex:

extension UILabel {
       // Property
       var flexText: String? {
        get {
            return self.text
        }
        set {
            self.text = newValue
            self.flex.markDirty()
        }
    }

    // Method
    func updateText(_ text: String) {
        self.text = text
        flex.markDirty()
    }
}

from flexlayout.

rgdev avatar rgdev commented on May 10, 2024

Thank you @lucdion, I was actually wondering if you think such extension would be worth adding to FlexLayout directly.

from flexlayout.

lucdion avatar lucdion commented on May 10, 2024

I prefer not to add extension to base UIKit classes. There is always the possibility of name clashes with app' extensions.

I could add a subclass of UILabel, but I need to think about that.
Thanks for your input!

from flexlayout.

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.