2
2
3
3
namespace FluidNav ;
4
4
5
- public abstract class TransitionView : ContentView
5
+ public abstract class TransitionView : ResponsiveView
6
6
{
7
- private BreakPoint _activeBreakpoint = BreakPoint . sm ;
8
7
private Type _activeType = typeof ( object ) ;
9
8
private readonly Dictionary < Type , IEnumerable < Flow > [ ] > _flows = [ ] ;
10
- private static readonly Dictionary < int , int > s_screens = new ( )
11
- {
12
- { ( int ) BreakPoint . sm , 640 } ,
13
- { ( int ) BreakPoint . md , 768 } ,
14
- { ( int ) BreakPoint . lg , 1024 } ,
15
- { ( int ) BreakPoint . xl , 1280 } ,
16
- { ( int ) BreakPoint . xxl , 1536 }
17
- } ;
18
-
19
- public TransitionView ( )
20
- {
21
- SizeChanged += ( s , e ) =>
22
- {
23
- var flow = GetBreakpointFlow ( _activeType , out var breakPoint ) ;
24
- if ( breakPoint == _activeBreakpoint ) return ;
25
-
26
- _activeBreakpoint = breakPoint ;
27
- _ = Complete ( _activeType ) ;
28
- } ;
29
- }
30
9
31
10
public Rect TransitionBounds { get ; set ; }
32
11
@@ -48,13 +27,13 @@ public bool RemoveState<TView>()
48
27
public TransitionView Complete ( Type type , IEnumerable < Flow > ? flow = null )
49
28
{
50
29
_activeType = type ;
51
- return FluidAnimationsExtensions . Complete ( this , flow ?? GetBreakpointFlow ( type , out _activeBreakpoint ) ) ;
30
+ return FluidAnimationsExtensions . Complete ( this , flow ?? GetBreakpointFlow ( type , ActiveBreakpoint ) ) ;
52
31
}
53
32
54
33
public Task < bool > Animate ( Type type , IEnumerable < Flow > ? flow = null )
55
34
{
56
35
_activeType = type ;
57
- return FluidAnimationsExtensions . Animate ( this , flow ?? GetBreakpointFlow ( type , out _activeBreakpoint ) ) ;
36
+ return FluidAnimationsExtensions . Animate ( this , flow ?? GetBreakpointFlow ( type , ActiveBreakpoint ) ) ;
58
37
}
59
38
60
39
/// <summary>
@@ -96,6 +75,13 @@ public static DataTemplate Build<TFromView, TToView, TTransitionView>(
96
75
} ) ;
97
76
}
98
77
78
+ protected override void OnBreakpointChanged ( BreakPoint breakPoint )
79
+ {
80
+ base . OnBreakpointChanged ( breakPoint ) ;
81
+
82
+ _ = Complete ( _activeType ) ;
83
+ }
84
+
99
85
private void SetBreakpointFlow ( Type type , BreakPoint breakpoint , IEnumerable < Flow > flow )
100
86
{
101
87
if ( ! _flows . TryGetValue ( type , out var typeFlows ) )
@@ -107,33 +93,15 @@ private void SetBreakpointFlow(Type type, BreakPoint breakpoint, IEnumerable<Flo
107
93
typeFlows [ ( int ) breakpoint ] = flow ;
108
94
}
109
95
110
- private IEnumerable < Flow > GetBreakpointFlow ( Type type , out BreakPoint breakPoint )
96
+ private IEnumerable < Flow > GetBreakpointFlow ( Type type , BreakPoint breakpoint )
111
97
{
112
- var view = FlowNavigation . Current . View ?? throw new Exception ( "Host view not found" ) ;
113
-
114
- var screenWidth = view . Width ;
115
- var ft = _flows [ type ] ;
116
-
117
- var flows = ft [ ( int ) BreakPoint . sm ] ;
118
- breakPoint = BreakPoint . sm ;
119
-
120
- bool evaluateBreakpoint ( BreakPoint bp )
121
- {
122
- if ( screenWidth >= s_screens [ ( int ) bp ] )
123
- {
124
- var f = ft ! [ ( int ) bp ] ;
125
- flows = f ?? flows ;
126
- return f is not null ;
127
- }
128
-
129
- return false ;
130
- }
98
+ var flowsOnType = _flows [ type ] ;
99
+ var i = ( int ) breakpoint ;
100
+ var flow = flowsOnType [ i ] ;
131
101
132
- if ( evaluateBreakpoint ( BreakPoint . md ) ) breakPoint = BreakPoint . md ;
133
- if ( evaluateBreakpoint ( BreakPoint . lg ) ) breakPoint = BreakPoint . lg ;
134
- if ( evaluateBreakpoint ( BreakPoint . xl ) ) breakPoint = BreakPoint . xl ;
135
- if ( evaluateBreakpoint ( BreakPoint . xxl ) ) breakPoint = BreakPoint . xxl ;
102
+ while ( flow is null && i > 0 )
103
+ flow = flowsOnType [ -- i ] ;
136
104
137
- return flows ;
105
+ return flow ?? throw new Exception ( $ "No flow found for { type . Name } at breakpoint { breakpoint } " ) ;
138
106
}
139
107
}
0 commit comments