DEV Community

Nicholas Eddy
Nicholas Eddy

Posted on

1

Powerful, yet simple Carousels in Doodle

You can build almost any experience you can imagine using the new Carousels in Doodle 0.9.3. That's because their API is unrestricted and not opinionated about what a Carousel should look like. There are several built-in examples of various Presenters; but so much more is possible.

Here's how you might show a list of Images using the LinearPresenter, which shows all images in a line with the selected item positioned/sized based on the given constraints.

val carousel = Carousel(
    SimpleListModel(listOf(image1, image2, image3)),
    itemVisualizer { item, previous, _ ->
        when (previous) {
            is DynamicImage -> previous.also { it.update(item) }
            else            -> DynamicImage(item)
        }
    }
).apply {
    wrapAtEnds    = true
    acceptsThemes = false
    behavior      = object: CarouselBehavior<Image> {

      override val presenter = LinearPresenter<Image>(spacing = 10.0) {
          val aspectRatio = it.width.readOnly / it.height.readOnly

          it.width  eq parent.width
          it.center eq parent.center
          it.height eq it.width / aspectRatio
      }

      override val transitioner = dampedTransitioner<Image>(timer, animationScheduler) { _,_,_, update ->
          animate(0f to 1f, using = tweenFloat(easeInOutCubic, duration = 1 * seconds)) {
                update(it)
          }
      }
    }
}
Enter fullscreen mode Exit fullscreen mode

Doodle is a pure Kotlin UI framework for the Web (and Desktop), that lets you create rich applications without relying on Javascript, HTML or CSS. Check out the documentation and tutorials to learn more.

Sentry mobile image

Mobile Vitals: A first step to Faster Apps

Slow startup times, UI hangs, and frozen frames frustrate users—but they’re also fixable. Mobile Vitals help you measure and understand these performance issues so you can optimize your app’s speed and responsiveness. Learn how to use them to reduce friction and improve user experience.

Read the guide →

Top comments (0)

Heroku

Build apps, not infrastructure.

Dealing with servers, hardware, and infrastructure can take up your valuable time. Discover the benefits of Heroku, the PaaS of choice for developers since 2007.

Visit Site

👋 Kindness is contagious

Please leave a ❤️ or a friendly comment on this post if you found it helpful!

Okay