Coder Social home page Coder Social logo

flexboxlayout's Introduction

FlexboxLayout

Swift Carthage compatible ![Platform](https://img.shields.io/badge/platform-iOS | macOS -lightgrey.svg?style=flat) Build

Port of Facebook's [css-layout](facebook css layout) to Swift + UIView extension.

GitHub Logo TL;DR This layout and style is expressed in code in the following declarative fashion:

let view =  UIView().define(children: [
      UIView().define { view in
        view.backgroundColor = UIColor.d
        view.layer.cornerRadius = 24.0
        view.useFlexbox = true
        view.layout_width = 48
        view.layout_height = 48
        view.layout_marginAll = 16
        view.layout_alignSelf = .center
        view.layout_justifyContent = .flexStart
      },
      UIView().define(children: [
        UILabel().define { view in
          view.text = "TITLE"
          view.useFlexbox = true
          view.layout_alignSelf = .flexStart
        },
        UILabel().define { view in
          view.text = "SUBTITLE"
          view.useFlexbox = true
          view.layout_alignSelf = .flexStart
        }
      ]) { view in
        view.backgroundColor = UIColor.a
        view.useFlexbox = true
        view.layout_alignSelf = .center
        view.layout_flexGrow = 0.8
        view.layout_paddingAll = 8
      },
      UILabel().define { view in
        view.text = "88:88"
        view.textColor = UIColor.f
        view.textAlignment = .center
        view.font = UIFont.systemFont(ofSize: 12, weight: UIFontWeightLight)
        view.useFlexbox = true
        view.layout_minWidth = 64
        view.layout_alignSelf = .center
        view.layout_flexShrink = 0.2
        view.layout_paddingAll = 8
        view.layout_marginAll = 2

      }
    ]) { view in
      view.backgroundColor = UIColor.white
      view.layer.borderColor = UIColor.b.cgColor
      view.layer.borderWidth = 2.0
      view.useFlexbox = true
      view.layout_justifyContent = .center
      view.layout_alignSelf = .stretch
      view.layout_marginAll = 8
      view.layout_flexDirection = .row
      view.layout_maxWidth = self.view.bounds.width - 40
    }

view.render()

The define function stores the configuration closure for each view and these are recursively re-applied whenever the render function is called on the root view.

flexboxlayout's People

Contributors

alexdrone avatar

Watchers

 avatar  avatar

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.