https://github.com/vinc3m1/litho-kotlin
Kotlin DSL for Litho ComponentLayout Builders.
https://github.com/vinc3m1/litho-kotlin
android android-library kotlin kotlin-dsl kotlin-library litho
Last synced: 10 months ago
JSON representation
Kotlin DSL for Litho ComponentLayout Builders.
- Host: GitHub
- URL: https://github.com/vinc3m1/litho-kotlin
- Owner: vinc3m1
- License: apache-2.0
- Created: 2017-12-24T01:24:43.000Z (over 8 years ago)
- Default Branch: master
- Last Pushed: 2018-07-18T23:48:50.000Z (almost 8 years ago)
- Last Synced: 2025-04-12T18:29:36.910Z (about 1 year ago)
- Topics: android, android-library, kotlin, kotlin-dsl, kotlin-library, litho
- Language: Kotlin
- Size: 27.3 KB
- Stars: 39
- Watchers: 3
- Forks: 2
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# Litho Kotlin
Kotlin DSL for [Litho](https://fblitho.com) `Component.Builder`s.
# Usage
## Import
1. Copy [`Litho.kt`](https://raw.githubusercontent.com/vinc3m1/litho-kotlin/master/src/main/kotlin/com/makeramen/litho/Litho.kt) into your project under `com/makeramen/litho`.
2. Add any definitions for your own custom components, e.g.
```kotlin
@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)
```
3. Remove any definitions you don't want to use, like `recyclerCollectionComponent` if you're not using [Sections](https://fblitho.com/docs/sections-intro).
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
```kotlin
@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)
}
}
}
}
}
```