Repository: android/compose-samples
File: JetLagged/app/src/main/java/com/example/jetlagged/JetLaggedDrawer.kt (Kotlin)

Code before:
            drawerState = DrawerState.Closed
        }
        suspend fun openDrawer() {
            translationX.animateTo(drawerWidth)
            drawerState = DrawerState.Open
        }
        fun toggleDrawerState() {
            coroutineScope.launch {
                if (drawerState == DrawerState.Open) {
                    closeDrawer()
                } else {
                    openDrawer()
                }
            }
        }
        PredictiveBackHandler(drawerState == DrawerState.Open) { progress ->
            try {
                progress.collect { backEvent ->
                    val targetSize = (drawerWidth - (drawerWidth * backEvent.progress))
                    translationX.snapTo(targetSize)
                }
                closeDrawer()
            } catch (e: CancellationException) {
                openDrawer()
            }
        }

        HomeScreenDrawerContents(
            selectedScreen = screenState,
            onScreenSelected = { screen ->
                screenState = screen
            }
        )

        val draggableState = rememberDraggableState(onDelta = { dragAmount ->
            coroutineScope.launch {
                translationX.snapTo(translationX.value + dragAmount)
            }
        })
        val decay = rememberSplineBasedDecay<Float>()
        ScreenContents(
            windowWidthSizeClass = windowSizeClass.widthSizeClass,
            selectedScreen = screenState,
            onDrawerClicked = ::toggleDrawerState,
            modifier = Modifier
                .graphicsLayer {
                    this.translationX = translationX.value
                    val scale = lerp(1f, 0.8f, translationX.value / drawerWidth)
                    this.scaleX = scale
                    this.scaleY = scale
                    val roundedCorners = lerp(0f, 32.dp.toPx(), translationX.value / drawerWidth)

Review comment (suggestion):
I'm not sure why i didn't merge my PR on this, but i think it'd be nice to do a similar thing to what i was doing before - ie tracking the velocity and finishing the gesture with the velocity.
https://github.com/android/compose-samples/pull/1185 

Something like this is what I had:
```
PredictiveBackHandler(drawerState == DrawerState.Closed) { progress: Flow<BackEventCompat> ->
            // code for gesture back started
            try {
                progress.collect { backEvent ->
                    // code for progress
                    if (drawerState == DrawerState.Closed) {
                        translationX.snapTo(backEvent.progress * drawerWidth)
                        velocityTracker.addPosition(System.currentTimeMillis(), Offset(backEvent.touchX, backEvent.touchY))
                    }
                }
                // code for completion
                val endProgress = if (translationX.value > drawerWidth * 0.2f) {
                    drawerWidth
                } else {
                    0f
                }
                translationX.animateTo(endProgress, initialVelocity = velocityTracker.calculateVelocity().x)

                if (endProgress == 0f){
                    drawerState = DrawerState.Closed
                } else {
                    drawerState = DrawerState.Open
                }
            } catch (e: CancellationException) {
                // code for cancellation
            }
        }
```

Code after:

        suspend fun closeDrawer(velocity: Float = 0f) {
            translationX.animateTo(targetValue = 0f, initialVelocity = velocity)
            drawerState = DrawerState.Closed
        }
        suspend fun openDrawer(velocity: Float = 0f) {
            translationX.animateTo(targetValue = drawerWidth, initialVelocity = velocity)
            drawerState = DrawerState.Open
        }
        fun toggleDrawerState() {
            coroutineScope.launch {
                if (drawerState == DrawerState.Open) {
                    closeDrawer()
                } else {
                    openDrawer()
                }
            }
        }
        val velocityTracker = remember {
            VelocityTracker()
        }
        PredictiveBackHandler(drawerState == DrawerState.Open) { progress ->
            try {
                progress.collect { backEvent ->
                    val targetSize = (drawerWidth - (drawerWidth * backEvent.progress))
                    translationX.snapTo(targetSize)
                    velocityTracker.addPosition(
                        SystemClock.uptimeMillis(),
                        Offset(backEvent.touchX, backEvent.touchY)
                    )
                }
                closeDrawer(velocityTracker.calculateVelocity().x)
            } catch (e: CancellationException) {
                openDrawer(velocityTracker.calculateVelocity().x)
            }
            velocityTracker.resetTracking()
        }

        HomeScreenDrawerContents(
            selectedScreen = screenState,
            onScreenSelected = { screen ->
                screenState = screen
            }
        )

        val draggableState = rememberDraggableState(onDelta = { dragAmount ->
            coroutineScope.launch {
                translationX.snapTo(translationX.value + dragAmount)
            }
        })
        val decay = rememberSplineBasedDecay<Float>()