Litho Kotlin
Kotlin DSL for Litho Component.Builder
s.
Usage
Import
- Copy
Litho.kt
into your project undercom/makeramen/litho
. - Add any definitions for your own custom components, e.g.
@LithoMarker fun myComponent(c: ComponentContext, init: MyComponent.Builder.() -> Unit) = componentBuilder(c, MyComponent::create, init) @LithoMarker fun ChildHolder.myComponent(c: ComponentContext, init: MyComponent.Builder.() -> Unit) = componentBuilder(c, MyComponent::create, init)
- Remove any definitions you don't want to use, like
recyclerCollectionComponent
if you're not using Sections.
I may look into a proper Maven Central release in the future, but it's just one file, and extensibility for custom components is the best part.
Example
@LayoutSpec
object ExampleComponentSpec {
@OnCreateLayout
fun onCreateLayout(c: ComponentContext): Component {
return column(c) { // Init root Components by passing in the context
paddingDip(YogaEdge.ALL, 8f) // Attributes can be defined inline within the lambda
children { // Add children using a children element
text { // ComponentBuilders within a children element don't need a context
text("TWO")
textSizeDip(16f)
}
text {
text("THREE")
textSizeDip(16f)
}
}
}
}
}