@@ -1876,6 +1876,7 @@ function animateGesture(
1876
1876
// keyframe. Otherwise it applies to every keyframe.
1877
1877
moveOldFrameIntoViewport ( keyframes [ 0 ] ) ;
1878
1878
}
1879
+ // TODO: Reverse the reverse if the original direction is reverse.
1879
1880
const reverse = rangeStart > rangeEnd ;
1880
1881
targetElement . animate ( keyframes , {
1881
1882
pseudoElement : pseudoElement ,
@@ -1886,7 +1887,7 @@ function animateGesture(
1886
1887
// from scroll bouncing.
1887
1888
easing : 'linear' ,
1888
1889
// We fill in both direction for overscroll.
1889
- fill : 'both' ,
1890
+ fill : 'both' , // TODO: Should we preserve the fill instead?
1890
1891
// We play all gestures in reverse, except if we're in reverse direction
1891
1892
// in which case we need to play it in reverse of the reverse.
1892
1893
direction : reverse ? 'normal' : 'reverse' ,
@@ -1931,18 +1932,32 @@ export function startGestureTransition(
1931
1932
// up if they exist later.
1932
1933
const foundGroups : Set < string > = new Set();
1933
1934
const foundNews: Set< string > = new Set();
1935
+ // Collect the longest duration of any view-transition animation including delay.
1936
+ let longestDuration = 0;
1934
1937
for (let i = 0; i < animations . length ; i ++ ) {
1938
+ const effect : KeyframeEffect = ( animations [ i ] . effect : any ) ;
1935
1939
// $FlowFixMe
1936
- const pseudoElement : ?string = animations [ i ] . effect . pseudoElement ;
1940
+ const pseudoElement : ?string = effect . pseudoElement ;
1937
1941
if ( pseudoElement == null ) {
1938
- } else if ( pseudoElement . startsWith ( '::view-transition-group' ) ) {
1939
- foundGroups . add ( pseudoElement . slice ( 23 ) ) ;
1940
- } else if ( pseudoElement . startsWith ( '::view-transition-new' ) ) {
1941
- // TODO: This is not really a sufficient detection because if the new
1942
- // pseudo element might exist but have animations disabled on it.
1943
- foundNews . add ( pseudoElement . slice ( 21 ) ) ;
1942
+ } else if ( pseudoElement . startsWith ( '::view-transition' ) ) {
1943
+ const timing = effect . getTiming ( ) ;
1944
+ const duration =
1945
+ typeof timing . duration === 'number' ? timing . duration : 0 ;
1946
+ const durationWithDelay = timing . delay + duration ;
1947
+ if ( durationWithDelay > longestDuration ) {
1948
+ longestDuration = durationWithDelay ;
1949
+ }
1950
+ if ( pseudoElement . startsWith ( '::view-transition-group' ) ) {
1951
+ foundGroups . add ( pseudoElement . slice ( 23 ) ) ;
1952
+ } else if ( pseudoElement . startsWith ( '::view-transition-new' ) ) {
1953
+ // TODO: This is not really a sufficient detection because if the new
1954
+ // pseudo element might exist but have animations disabled on it.
1955
+ foundNews . add ( pseudoElement . slice ( 21 ) ) ;
1956
+ }
1944
1957
}
1945
1958
}
1959
+ const durationToRangeMultipler =
1960
+ ( rangeEnd - rangeStart ) / longestDuration ;
1946
1961
for ( let i = 0 ; i < animations . length ; i ++ ) {
1947
1962
const anim = animations [ i ] ;
1948
1963
if ( anim . playState !== 'running' ) {
@@ -1982,14 +1997,24 @@ export function startGestureTransition(
1982
1997
}
1983
1998
// TODO: If this has only an old state and no new state,
1984
1999
}
2000
+ // Adjust the range based on how long the animation would've ran as time based.
2001
+ // Since we're running animations in reverse from how they normally would run,
2002
+ // therefore the timing is from the rangeEnd to the start.
2003
+ const timing = effect . getTiming ( ) ;
2004
+ const duration =
2005
+ typeof timing . duration === 'number' ? timing . duration : 0 ;
2006
+ const adjustedRangeStart =
2007
+ rangeEnd - ( duration + timing . delay ) * durationToRangeMultipler ;
2008
+ const adjustedRangeEnd =
2009
+ rangeEnd - timing . delay * durationToRangeMultipler ;
1985
2010
animateGesture (
1986
2011
effect . getKeyframes ( ) ,
1987
2012
// $FlowFixMe: Always documentElement atm.
1988
2013
effect . target ,
1989
2014
pseudoElement ,
1990
2015
timeline ,
1991
- rangeStart ,
1992
- rangeEnd ,
2016
+ adjustedRangeStart ,
2017
+ adjustedRangeEnd ,
1993
2018
isGeneratedGroupAnim ,
1994
2019
isExitGroupAnim ,
1995
2020
) ;
0 commit comments