@@ -180,22 +180,19 @@ class CupertinoPageRoute<T> extends PageRoute<T> {
180180 return nextRoute is CupertinoPageRoute && ! nextRoute.fullscreenDialog;
181181 }
182182
183- @override
184- void dispose () {
185- _popGestureInProgress.remove (this );
186- super .dispose ();
187- }
188-
189- /// True if a Cupertino pop gesture is currently underway for [route] .
183+ /// True if an iOS-style back swipe pop gesture is currently underway for [route] .
184+ ///
185+ /// This just check the route's [NavigatorState.userGestureInProgress] .
190186 ///
191187 /// See also:
192188 ///
193189 /// * [popGestureEnabled] , which returns true if a user-triggered pop gesture
194190 /// would be allowed.
195- static bool isPopGestureInProgress (PageRoute <dynamic > route) => _popGestureInProgress.contains (route);
196- static final Set <PageRoute <dynamic >> _popGestureInProgress = < PageRoute <dynamic >> {};
191+ static bool isPopGestureInProgress (PageRoute <dynamic > route) {
192+ return route.navigator.userGestureInProgress;
193+ }
197194
198- /// True if a Cupertino pop gesture is currently underway for this route.
195+ /// True if an iOS-style back swipe pop gesture is currently underway for this route.
199196 ///
200197 /// See also:
201198 ///
@@ -233,10 +230,15 @@ class CupertinoPageRoute<T> extends PageRoute<T> {
233230 if (route.fullscreenDialog)
234231 return false ;
235232 // If we're in an animation already, we cannot be manually swiped.
236- if (route.controller.status != AnimationStatus .completed)
233+ if (route.animation.status != AnimationStatus .completed)
234+ return false ;
235+ // If we're being popped into, we also cannot be swiped until the pop above
236+ // it completes. This translates to our secondary animation being
237+ // dismissed.
238+ if (route.secondaryAnimation.status != AnimationStatus .dismissed)
237239 return false ;
238240 // If we're in a gesture already, we cannot start another.
239- if (_popGestureInProgress. contains (route))
241+ if (isPopGestureInProgress (route))
240242 return false ;
241243
242244 // Looks like a back gesture would be welcome!
@@ -266,9 +268,7 @@ class CupertinoPageRoute<T> extends PageRoute<T> {
266268 // gesture is detected. The returned controller handles all of the subsequent
267269 // drag events.
268270 static _CupertinoBackGestureController <T > _startPopGesture <T >(PageRoute <T > route) {
269- assert (! _popGestureInProgress.contains (route));
270271 assert (_isPopGestureEnabled (route));
271- _popGestureInProgress.add (route);
272272
273273 _CupertinoBackGestureController <T > backController;
274274 backController = _CupertinoBackGestureController <T >(
@@ -277,7 +277,6 @@ class CupertinoPageRoute<T> extends PageRoute<T> {
277277 onEnded: () {
278278 backController? .dispose ();
279279 backController = null ;
280- _popGestureInProgress.remove (route);
281280 },
282281 );
283282 return backController;
@@ -313,9 +312,12 @@ class CupertinoPageRoute<T> extends PageRoute<T> {
313312 return CupertinoPageTransition (
314313 primaryRouteAnimation: animation,
315314 secondaryRouteAnimation: secondaryAnimation,
315+ // Check if the route has an animation that's currently participating
316+ // in a back swipe gesture.
317+ //
316318 // In the middle of a back gesture drag, let the transition be linear to
317319 // match finger motions.
318- linearTransition: _popGestureInProgress. contains (route),
320+ linearTransition: isPopGestureInProgress (route),
319321 child: _CupertinoBackGestureDetector <T >(
320322 enabledCallback: () => _isPopGestureEnabled <T >(route),
321323 onStartPopGesture: () => _startPopGesture <T >(route),
@@ -354,28 +356,38 @@ class CupertinoPageTransition extends StatelessWidget {
354356 @required this .child,
355357 @required bool linearTransition,
356358 }) : assert (linearTransition != null ),
357- _primaryPositionAnimation = (linearTransition ? primaryRouteAnimation :
358- // The curves below have been rigorously derived from plots of native
359- // iOS animation frames. Specifically, a video was taken of a page
360- // transition animation and the distance in each frame that the page
361- // moved was measured. A best fit bezier curve was the fitted to the
362- // point set, which is linearToEaseIn. Conversely, easeInToLinear is the
363- // reflection over the origin of linearToEaseIn.
364- CurvedAnimation (
365- parent: primaryRouteAnimation,
366- curve: Curves .linearToEaseOut,
367- reverseCurve: Curves .easeInToLinear,
368- )
369- ).drive (_kRightMiddleTween),
370- _secondaryPositionAnimation = CurvedAnimation (
371- parent: secondaryRouteAnimation,
372- curve: Curves .linearToEaseOut,
373- reverseCurve: Curves .easeInToLinear,
374- ).drive (_kMiddleLeftTween),
375- _primaryShadowAnimation = CurvedAnimation (
376- parent: primaryRouteAnimation,
377- curve: Curves .linearToEaseOut,
378- ).drive (_kGradientShadowTween),
359+ _primaryPositionAnimation =
360+ (linearTransition
361+ ? primaryRouteAnimation
362+ : CurvedAnimation (
363+ // The curves below have been rigorously derived from plots of native
364+ // iOS animation frames. Specifically, a video was taken of a page
365+ // transition animation and the distance in each frame that the page
366+ // moved was measured. A best fit bezier curve was the fitted to the
367+ // point set, which is linearToEaseIn. Conversely, easeInToLinear is the
368+ // reflection over the origin of linearToEaseIn.
369+ parent: primaryRouteAnimation,
370+ curve: Curves .linearToEaseOut,
371+ reverseCurve: Curves .easeInToLinear,
372+ )
373+ ).drive (_kRightMiddleTween),
374+ _secondaryPositionAnimation =
375+ (linearTransition
376+ ? secondaryRouteAnimation
377+ : CurvedAnimation (
378+ parent: secondaryRouteAnimation,
379+ curve: Curves .linearToEaseOut,
380+ reverseCurve: Curves .easeInToLinear,
381+ )
382+ ).drive (_kMiddleLeftTween),
383+ _primaryShadowAnimation =
384+ (linearTransition
385+ ? primaryRouteAnimation
386+ : CurvedAnimation (
387+ parent: primaryRouteAnimation,
388+ curve: Curves .linearToEaseOut,
389+ )
390+ ).drive (_kGradientShadowTween),
379391 super (key: key);
380392
381393 // When this page is coming in to cover another page.
@@ -618,7 +630,6 @@ class _CupertinoBackGestureController<T> {
618630 animateForward = velocity > 0 ? false : true ;
619631 else
620632 animateForward = controller.value > 0.5 ? true : false ;
621-
622633 if (animateForward) {
623634 // The closer the panel is to dismissing, the shorter the animation is.
624635 // We want to cap the animation time, but we want to use a linear curve
@@ -650,9 +661,9 @@ class _CupertinoBackGestureController<T> {
650661 controller.removeStatusListener (_handleStatusChanged);
651662 }
652663 _animating = false ;
664+ onEnded ();
653665 if (status == AnimationStatus .dismissed)
654- route.navigator.removeRoute (route); // this will cause the route to get disposed, which will dispose us
655- onEnded (); // this will call dispose if popping the route failed to do so
666+ route.navigator.removeRoute (route); // This also disposes the route.
656667 }
657668
658669 void dispose () {
0 commit comments