All Projects → vinc3m1 → litho-kotlin

vinc3m1 / litho-kotlin

Licence: Apache-2.0 License
Kotlin DSL for Litho ComponentLayout Builders.

Programming Languages

kotlin
9241 projects

Projects that are alternatives of or similar to litho-kotlin

litho-lint-rules
Lint rules for Litho by Facebook http://fblitho.com/
Stars: ✭ 14 (-63.16%)
Mutual labels:  litho
make-react-native-package
CLI tool for bootstrapping react-native packages with Kotlin & Swift & Typescript
Stars: ✭ 36 (-5.26%)
Mutual labels:  litho
litho-kotlin
A simple project showing how to set up an Android project to work with Kotlin and Facebook's Litho.
Stars: ✭ 37 (-2.63%)
Mutual labels:  litho

Litho Kotlin

Kotlin DSL for Litho Component.Builders.

Usage

Import

  1. Copy Litho.kt into your project under com/makeramen/litho.
  2. 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)
  3. 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)
        }
      }
    }
  }
}
Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].