Skip to content

[Alpha] It helps writing the code in Texture with Swift's power. [like SwiftUI]

License

Notifications You must be signed in to change notification settings

chml/TextureSwiftSupport

 
 

Repository files navigation

TextureSwiftSupport

TextureSwiftSupport is a support library for Texture
It helps writing the code in Texture with Swift's power.

Requirements

Swiift 5.1+

LayoutSpecBuilder (Using _functionBuidler)

Swift5.1 has FunctionBuilder(it's not officially)
With this, we can write layout spec with no more commas. (It's like SwiftUI)

SwiftUI-like Method Chain API

Inspiring from SwiftUI.

We can build a node hierarchy with the method chain.

For now, we have only a few methods. (e.g Padding, Overlay, Background)

textNode
  .padding([.vertical], padding: 4)
  .background(backgroundNode)

About Function builders

Function builders is a feature in Swift Language.
For example, SwiftUI uses it.

Implementation example

Plain

override func layoutSpecThatFits(_ constrainedSize: ASSizeRange) -> ASLayoutSpec {
    ASStackLayoutSpec(
        direction: .vertical,
        spacing: 0,
        justifyContent: .start,
        alignItems: .start,
        children: [
            textNode1,
            textNode2,
            textNode3,
        ]
    )
}

With TextureSwiftSupport

override func layoutSpecThatFits(_ constrainedSize: ASSizeRange) -> ASLayoutSpec {
    LayoutSpec {
        VStackLayout {
            textNode1
            textNode2
            textNode3
        }
    }
}

More example

override func layoutSpecThatFits(_ constrainedSize: ASSizeRange) -> ASLayoutSpec {
    LayoutSpec {
        VStackLayout {
            HStackLayout {
                InsetLayout {
                    node1
                }
                InsetLayout {
                    node2
                }
            }
            node3
            HStackLayout {
                node4,
                node5,
                node6,
            }
        }
    }
}

Layout Specs

  • VStackLayout
  • HStackLayout
  • ZStackLayout
  • InsetLayout
  • OverlayLayout
  • BackgroundLayout
  • AspectRatioLayout
  • VSpacerLayout
  • HSpacerLayout

Author

Muukii [email protected]

About

[Alpha] It helps writing the code in Texture with Swift's power. [like SwiftUI]

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages

  • Swift 84.7%
  • Ruby 10.2%
  • Objective-C 5.1%