-
Notifications
You must be signed in to change notification settings - Fork 729
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Carousel building with Kotlin DSL - Step 1 (#967)
* apply commit eeff265 * fix wrong merge * Move the builder in sample app waiting for a more robust api * Actually let's do it for the carousel no snap * Use new DSL in sample app * ktlint * ktlint * Simplify, BaseEpoxyController class -> ModelCollector interface * ktlint Co-authored-by: Eli Hart <eli.hart@airbnb.com> Co-authored-by: Emmanuel Boudrant <eboudrant@netflix.com>
- Loading branch information
1 parent
cb9673f
commit 7c4ac9c
Showing
6 changed files
with
71 additions
and
20 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
10 changes: 10 additions & 0 deletions
10
epoxy-adapter/src/main/java/com/airbnb/epoxy/ModelCollector.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
package com.airbnb.epoxy | ||
|
||
/** | ||
* Interface used to collect models. Used by [EpoxyController]. It is also convenient to build DSL | ||
* helpers for carousel: @link https://github.com/airbnb/epoxy/issues/847. | ||
*/ | ||
interface ModelCollector { | ||
|
||
fun add(model: EpoxyModel<*>) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
41 changes: 41 additions & 0 deletions
41
...nsample/src/main/java/com/airbnb/epoxy/kotlinsample/helpers/EpoxyCarouselNoSnapBuilder.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
package com.airbnb.epoxy.kotlinsample.helpers | ||
|
||
import com.airbnb.epoxy.EpoxyModel | ||
import com.airbnb.epoxy.ModelCollector | ||
import com.airbnb.epoxy.kotlinsample.views.CarouselNoSnapModelBuilder | ||
import com.airbnb.epoxy.kotlinsample.views.CarouselNoSnapModel_ | ||
|
||
/** | ||
* Example that illustrate how to add a builder for nested list (ex: carousel) that allow building | ||
* it using DSL : | ||
* | ||
* carouselBuilder { | ||
* id(...) | ||
* for (...) { | ||
* carouselItemCustomView { | ||
* id(...) | ||
* } | ||
* } | ||
* } | ||
* | ||
* @link https://github.com/airbnb/epoxy/issues/847 | ||
*/ | ||
fun ModelCollector.carouselNoSnapBuilder(builder: EpoxyCarouselNoSnapBuilder.() -> Unit): CarouselNoSnapModel_ { | ||
val carouselBuilder = EpoxyCarouselNoSnapBuilder().apply { builder() } | ||
add(carouselBuilder.carouselNoSnapModel) | ||
return carouselBuilder.carouselNoSnapModel | ||
} | ||
|
||
class EpoxyCarouselNoSnapBuilder( | ||
internal val carouselNoSnapModel: CarouselNoSnapModel_ = CarouselNoSnapModel_() | ||
) : ModelCollector, CarouselNoSnapModelBuilder by carouselNoSnapModel { | ||
private val models = mutableListOf<EpoxyModel<*>>() | ||
|
||
override fun add(model: EpoxyModel<*>) { | ||
models.add(model) | ||
|
||
// Set models list every time a model is added so that it can run debug validations to | ||
// ensure it is still valid to mutate the carousel model. | ||
carouselNoSnapModel.models(models) | ||
} | ||
} |