Skip to content

Instantly share code, notes, and snippets.

View chiragthummar's full-sized avatar
🎯
Focusing

Chirag Thummar chiragthummar

🎯
Focusing
View GitHub Profile
package be.motti.uzb;
import android.content.Context;
import android.content.Intent;
import android.os.Handler;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.Button;
@chiragthummar
chiragthummar / BouncyClickable.kt
Created June 25, 2023 07:25
Increase user experience with bouncy click on any component of jetpack compose.
@OptIn(ExperimentalFoundationApi::class)
fun Modifier.bounceClickable(
dampingRatio: Float = 0.85f,
enabled: Boolean = true,
onClick: () -> Unit = {},
onDoubleClick: (() -> Unit)? = null,
onLongClick: (() -> Unit)? = null,
shape: Shape = RectangleShape,
useHapticFeedback: Boolean = true,
) = composed {
fun Modifier.shimmerEffect(): Modifier = composed {
var size by remember {
mutableStateOf(IntSize.Zero)
}
val transition = rememberInfiniteTransition()
val startOffsetX by transition.animateFloat(
initialValue = -2 * size.width.toFloat(),
targetValue = 2 * size.width.toFloat(),
animationSpec = infiniteRepeatable(
animation = tween(2000)
@Composable
fun ButtonStateExample() {
val interactionSource = remember { MutableInteractionSource() }
val isButtonPressed by interactionSource.collectIsPressedAsState()
val isButtonDragged by interactionSource.collectIsDraggedAsState()
val isButtonHovered by interactionSource.collectIsHoveredAsState()
val isButtonFocused by interactionSource.collectIsFocusedAsState()
LaunchedEffect(key1 = isButtonDragged) {
@chiragthummar
chiragthummar / StackOverFlow1.kt
Last active July 25, 2023 11:37
StackOverFlow1
package com.example.jetpackcomposeplayground
import androidx.compose.foundation.Image
import androidx.compose.foundation.background
import androidx.compose.foundation.layout.Arrangement
import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.Row
import androidx.compose.foundation.layout.fillMaxWidth
import androidx.compose.foundation.layout.height
import androidx.compose.foundation.layout.padding
@chiragthummar
chiragthummar / TextField.kt
Created August 14, 2023 16:36
TextField Styling Text Without Cyclic Recomposition
import androidx.compose.material.TextField
import androidx.compose.runtime.Composable
import androidx.compose.runtime.mutableStateOf
import androidx.compose.runtime.remember
import androidx.compose.ui.text.SpanStyle
import androidx.compose.ui.text.buildAnnotatedString
import androidx.compose.ui.text.font.FontWeight
import androidx.compose.ui.text.input.OffsetMapping
import androidx.compose.ui.text.input.TextFieldValue
import androidx.compose.ui.text.input.TransformedText
@Composable
fun NestedNavigationExample() {
val navController = rememberNavController()
NavHost(
navController = navController,
startDestination = Screens.Home.route
) {
navigation(
startDestination = Screens.Home.Login.route,
sealed class Screens(val route : String) {
object Dashboard : Screens("dashboard")
object Home : Screens("home"){
object Login : Screens("login")
object Register : Screens("register")
}
}
dependencies {
val nav_version = "2.7.0"
implementation("androidx.navigation:navigation-compose:$nav_version")
}
@OptIn(ExperimentalMaterial3Api::class)
@Composable
fun DashboardScreen(navigateTo: (route: String) -> Unit) {
Scaffold(topBar = {
TopAppBar(
title = { Text(text = "Dashboard") },
colors = TopAppBarDefaults.topAppBarColors(containerColor = MaterialTheme.colorScheme.primary)
)
}) {
Box(