@@ -14,6 +14,12 @@ namespace Files.App.Helpers
14
14
{
15
15
internal sealed class NavigationInteractionTracker : IDisposable
16
16
{
17
+ private static IRealTimeLayoutService RealTimeLayoutService => Ioc . Default . GetRequiredService < IRealTimeLayoutService > ( ) ;
18
+
19
+ private static int RePos => RealTimeLayoutService . FlowDirection is FlowDirection . LeftToRight ? 1 : - 1 ;
20
+ private static ( float Min , float Max ) RePosB => RealTimeLayoutService . FlowDirection is FlowDirection . LeftToRight ? ( - 96f , 0f ) : ( 0f , 96f ) ;
21
+ private static ( float Min , float Max ) RePosF => RealTimeLayoutService . FlowDirection is FlowDirection . LeftToRight ? ( 0f , 96f ) : ( - 96f , 0f ) ;
22
+
17
23
public bool CanNavigateForward
18
24
{
19
25
get
@@ -26,7 +32,11 @@ public bool CanNavigateForward
26
32
if ( ! _disposed )
27
33
{
28
34
_props . InsertBoolean ( nameof ( CanNavigateForward ) , value ) ;
29
- _tracker . MaxPosition = new ( value ? 96f : 0f ) ;
35
+ if ( RePos == 1 )
36
+ _tracker . MaxPosition = new ( value ? 96 : 0 ) ;
37
+ else
38
+ _tracker . MinPosition = new ( value ? - 96 : 0 ) ;
39
+
30
40
}
31
41
}
32
42
}
@@ -43,7 +53,10 @@ public bool CanNavigateBackward
43
53
if ( ! _disposed )
44
54
{
45
55
_props . InsertBoolean ( nameof ( CanNavigateBackward ) , value ) ;
46
- _tracker . MinPosition = new ( value ? - 96f : 0f ) ;
56
+ if ( RePos == 1 )
57
+ _tracker . MinPosition = new ( value ? - 96 : 0 ) ;
58
+ else
59
+ _tracker . MaxPosition = new ( value ? 96 : 0 ) ;
47
60
}
48
61
}
49
62
}
@@ -89,6 +102,19 @@ public NavigationInteractionTracker(UIElement rootElement, UIElement backIcon, U
89
102
90
103
_pointerPressedHandler = new ( PointerPressed ) ;
91
104
_rootElement . AddHandler ( UIElement . PointerPressedEvent , _pointerPressedHandler , true ) ;
105
+
106
+ RealTimeLayoutService . FlowDirectionChanged += RealTimeLayoutService_FlowDirectionChanged ;
107
+ }
108
+
109
+ private void RealTimeLayoutService_FlowDirectionChanged ( object ? sender , FlowDirection e )
110
+ {
111
+ var canBack = CanNavigateBackward ;
112
+ var canForward = CanNavigateForward ;
113
+
114
+ CanNavigateBackward = canBack ;
115
+ CanNavigateForward = canForward ;
116
+
117
+ SetupAnimations ( ) ;
92
118
}
93
119
94
120
[ MemberNotNull ( nameof ( _tracker ) , nameof ( _source ) , nameof ( _trackerOwner ) ) ]
@@ -113,17 +139,17 @@ private void SetupAnimations()
113
139
{
114
140
var compositor = _rootVisual . Compositor ;
115
141
116
- var backResistance = CreateResistanceCondition ( - 96f , 0f ) ;
117
- var forwardResistance = CreateResistanceCondition ( 0f , 96f ) ;
142
+ var backResistance = CreateResistanceCondition ( RePosB . Min , RePosB . Max ) ;
143
+ var forwardResistance = CreateResistanceCondition ( RePosF . Min , RePosF . Max ) ;
118
144
List < CompositionConditionalValue > conditionalValues = [ backResistance , forwardResistance ] ;
119
145
_source . ConfigureDeltaPositionXModifiers ( conditionalValues ) ;
120
146
121
- var backAnim = compositor . CreateExpressionAnimation ( "(- clamp(tracker.Position.X, -96, 0 ) * 2) - 48") ;
147
+ var backAnim = compositor . CreateExpressionAnimation ( $ "( clamp(tracker.Position.X, { RePosB . Min } , { RePosB . Max } ) * 2 * ( { - RePos } ) ) - 48") ;
122
148
backAnim . SetReferenceParameter ( "tracker" , _tracker ) ;
123
149
backAnim . SetReferenceParameter ( "props" , _props ) ;
124
150
_backVisual . StartAnimation ( "Translation.X" , backAnim ) ;
125
151
126
- var forwardAnim = compositor . CreateExpressionAnimation ( "(- clamp(tracker.Position.X, 0, 96 ) * 2) + 48") ;
152
+ var forwardAnim = compositor . CreateExpressionAnimation ( $ "( clamp(tracker.Position.X, { RePosF . Min } , { RePosF . Max } ) * 2 * ( { - RePos } ) ) + 48") ;
127
153
forwardAnim . SetReferenceParameter ( "tracker" , _tracker ) ;
128
154
forwardAnim . SetReferenceParameter ( "props" , _props ) ;
129
155
_forwardVisual . StartAnimation ( "Translation.X" , forwardAnim ) ;
@@ -210,11 +236,11 @@ public void IdleStateEntered(InteractionTracker sender, InteractionTrackerIdleSt
210
236
EventHandler < OverscrollNavigationEventArgs > ? navEvent = _parent . NavigationRequested ;
211
237
if ( navEvent is not null )
212
238
{
213
- if ( sender . Position . X > 0 && _parent . CanNavigateForward )
239
+ if ( sender . Position . X * RePos > 0 && _parent . CanNavigateForward )
214
240
{
215
241
navEvent ( _parent , OverscrollNavigationEventArgs . Forward ) ;
216
242
}
217
- else if ( sender . Position . X < 0 && _parent . CanNavigateBackward )
243
+ else if ( sender . Position . X * RePos < 0 && _parent . CanNavigateBackward )
218
244
{
219
245
navEvent ( _parent , OverscrollNavigationEventArgs . Back ) ;
220
246
}
@@ -238,12 +264,12 @@ public void ValuesChanged(InteractionTracker sender, InteractionTrackerValuesCha
238
264
if ( ! _shouldAnimate )
239
265
return ;
240
266
241
- if ( args . Position . X <= - 64 )
267
+ if ( args . Position . X * RePos <= - 64 )
242
268
{
243
269
_parent . _backVisual . StartAnimation ( "Scale" , _scaleAnimation ) ;
244
270
_shouldAnimate = false ;
245
271
}
246
- else if ( args . Position . X >= 64 )
272
+ else if ( args . Position . X * RePos >= 64 )
247
273
{
248
274
_parent . _forwardVisual . StartAnimation ( "Scale" , _scaleAnimation ) ;
249
275
_shouldAnimate = false ;
0 commit comments