1818
1919package com.example.compose.snippets.predictiveback
2020
21+ import android.annotation.SuppressLint
2122import android.os.Bundle
2223import android.util.Log
2324import android.view.MotionEvent.EDGE_LEFT
2425import android.view.MotionEvent.EDGE_RIGHT
2526import androidx.activity.ComponentActivity
2627import androidx.activity.compose.setContent
27- import androidx.compose.animation.core.animateDpAsState
2828import androidx.compose.animation.core.animateFloatAsState
2929import androidx.compose.runtime.Composable
3030import androidx.compose.runtime.getValue
@@ -74,6 +74,7 @@ class MainActivity : ComponentActivity() {
7474 }
7575}
7676
77+ @SuppressLint(" ConfigurationScreenWidthHeight" )
7778@Composable
7879fun ScreenB (
7980 backEventState : NavigationEventState <NavigationEventInfo >,
@@ -99,16 +100,16 @@ fun ScreenB(
99100 label = " ScaleAnimation"
100101 )
101102
102- val maxShift = (LocalConfiguration .current.screenWidthDp / 20f ) - 8
103+ val configuration = LocalConfiguration .current
104+ val maxShift = remember(configuration) {
105+ (configuration.screenWidthDp / 20f ) - 8
106+ }
103107
104- val animatedOffsetX by animateDpAsState(
105- targetValue = when (swipeEdge) {
106- EDGE_LEFT -> (backProgress * maxShift).dp
107- EDGE_RIGHT -> (- backProgress * maxShift).dp
108- else -> 0 .dp
109- },
110- label = " OffsetXAnimation"
111- )
108+ val offsetX = when (swipeEdge) {
109+ EDGE_LEFT -> (backProgress * maxShift).dp
110+ EDGE_RIGHT -> (- backProgress * maxShift).dp
111+ else -> 0 .dp
112+ }
112113
113114 NavigationBackHandler (
114115 state = backEventState,
0 commit comments