Migrating Layout Spec
Overview
This guide provides detailed instructions for migrating from the Litho LayoutSpec API to the KComponent API. The transition is crucial as the Litho Spec API is now in maintenance mode, with limited support and no new features being added. Migrating to the KComponent API offers performance improvements, enhanced stability, and compile-time reliability checks.
Benefits of Migration
- Stability: Converts many runtime crashes into compile-time errors.
- Performance: Improves build time as there is no generated code required.
- Support: The Spec API will only receive bug fixes, with all new APIs and improvements available exclusively in the Kotlin API.
Migration Process
- Preparation:
- Ensure you have screenshot tests and/or end-to-end tests in place to verify functionality post-migration.
- Consider breaking down large or complex specs into smaller components.
- Conversion: convert your Java layout spec to Kotlin using the j2k tool, then migrate it to the Kotlin API.
- Testing:
- Build the migrated module to ensure it compiles.
- Run screenshot or end-to-end tests to ensure they still pass.
Current Limitations
- There is no codemod available for MountSpec and Sections as the small number of usages. Refer to the Migrating MountSpecs to PrimitiveComponents and Migrating Sections to LazyCollections for detailed steps.