Skip to main content

Posts

Showing posts with the label Modifier

Jetpack Compose: Long click listener

Introduction Jetpack Compose is Google's modern toolkit for building native Android UI, allowing developers to write less code and make it more readable and maintainable. One of its standout features is how it simplifies handling gestures like taps, swipes, and long presses. In this article, we’ll explore a practical example of handling long-click actions using Jetpack Compose. We'll break down the code in a programmer-friendly way, so even if you're new to Compose, you'll grasp how to implement interactive UI components with long-press gestures. Our example demonstrates a simple long-click listener that changes the shape of a box when either clicked or long-clicked, using Kotlin and Jetpack Compose. Let’s break down the code and understand how this is achieved in an easy-to-follow manner. Breakdown of the Code : MainActivity Setup The MainActivity class is where our Compose content begins. In the onCreate method, instead of using XML layouts, Jetpack Compose allows u...

Jetpack compose: How to implement double click listener

This code snippet demonstrates how to implement a double click listener in Jetpack Compose. Here's a breakdown of the code: Scaffold : The Scaffold function is the foundation of the user interface in Jetpack Compose. It provides a basic structure for the screen, including an optional top app bar, content area, and bottom navigation bar. TopAppBar : The TopAppBar composes the app bar at the top of the screen. It displays the app title ("Compose - Double click listener" in this case) and can optionally include navigation icons or other elements. MainContent : The MainContent function defines the content of the screen. In this example, it's a clickable box that changes its shape and displays a message based on the user's interaction. Box : The Box function creates a container that can hold other composables. It can be sized and positioned using modifiers. combinedClickable : The combinedClickable modifier allows you to attach both click and doub...