@@ -31,6 +31,7 @@ import androidx.coordinatorlayout.widget.CoordinatorLayout
31
31
import androidx.core.view.ViewCompat
32
32
import androidx.core.view.ViewGroupCompat
33
33
import androidx.core.view.WindowInsetsCompat
34
+ import androidx.core.view.animation.PathInterpolatorCompat
34
35
import androidx.core.view.updateLayoutParams
35
36
import androidx.core.view.updatePadding
36
37
import androidx.core.widget.NestedScrollView
@@ -39,8 +40,6 @@ import androidx.fragment.app.viewModels
39
40
import androidx.navigation.findNavController
40
41
import androidx.navigation.fragment.findNavController
41
42
import androidx.navigation.fragment.navArgs
42
- import androidx.transition.ChangeTransform
43
- import androidx.transition.TransitionManager
44
43
import com.example.android.motion.R
45
44
import com.google.android.material.appbar.CollapsingToolbarLayout
46
45
import com.google.android.material.transition.MaterialContainerTransform
@@ -49,14 +48,14 @@ class CheeseArticleFragment : Fragment() {
49
48
50
49
companion object {
51
50
const val TRANSITION_NAME_BACKGROUND = " background"
51
+
52
+ private val GestureInterpolator = PathInterpolatorCompat .create(0f , 0f , 0f , 1f )
52
53
}
53
54
54
55
private val args: CheeseArticleFragmentArgs by navArgs()
55
56
56
57
private val viewModel: CheeseArticleViewModel by viewModels()
57
58
58
- private val cancelTransition = ChangeTransform ()
59
-
60
59
override fun onCreate (savedInstanceState : Bundle ? ) {
61
60
super .onCreate(savedInstanceState)
62
61
@@ -131,11 +130,13 @@ class CheeseArticleFragment : Fragment() {
131
130
}
132
131
133
132
override fun handleOnBackProgressed (backEvent : BackEventCompat ) {
134
- val progress = backEvent.progress
133
+ val progress = GestureInterpolator .getInterpolation( backEvent.progress)
135
134
if (initialTouchY < 0f ) {
136
135
initialTouchY = backEvent.touchY
137
136
}
138
- val progressY = (backEvent.touchY - initialTouchY) / background.height
137
+ val progressY = GestureInterpolator .getInterpolation(
138
+ (backEvent.touchY - initialTouchY) / background.height
139
+ )
139
140
140
141
// See the motion spec about the calculations below.
141
142
// https://developer.android.com/design/ui/mobile/guides/patterns/predictive-back#motion-specs
@@ -156,10 +157,10 @@ class CheeseArticleFragment : Fragment() {
156
157
}
157
158
158
159
override fun handleOnBackCancelled () {
159
- TransitionManager .beginDelayedTransition(background, cancelTransition)
160
160
initialTouchY = - 1f
161
161
background.run {
162
162
translationX = 0f
163
+ translationY = 0f
163
164
scaleX = 1f
164
165
scaleY = 1f
165
166
}
0 commit comments