@@ -8,6 +8,8 @@ namespace MADE.App.Views.Navigation
88 using Android . Support . V4 . App ;
99 using Android . Support . V7 . App ;
1010
11+ using MADE . App . Views . Navigation . Pages ;
12+
1113 /// <summary>
1214 /// Defines a frame for navigating and displaying page content.
1315 /// </summary>
@@ -82,25 +84,21 @@ public void GoBack()
8284 return ;
8385 }
8486
85- if ( ! this . CanNavigateAway ( ) )
87+ NavigationEventArgs previousPageEvent = this . GetNavigationEvent ( this . BackStackDepth - 1 ) ;
88+ if ( previousPageEvent == null )
8689 {
90+ // ToDo, if there is no page event, we are at the end of the stack. Should exit app.
8791 return ;
8892 }
8993
90- NavigationEventArgs currentPageEvent = this . GetNavigationEvent ( this . BackStackDepth ) ;
91- if ( currentPageEvent != null )
92- {
93- currentPageEvent . NavigationMode = NavigationMode . Back ;
94- }
94+ previousPageEvent . NavigationMode = NavigationMode . Back ;
9595
96- NavigationEventArgs previousPageEvent = this . GetNavigationEvent ( this . BackStackDepth - 1 ) ;
97- if ( previousPageEvent != null )
96+ if ( ! this . CanNavigateAway ( previousPageEvent ) )
9897 {
99- previousPageEvent . NavigationMode = NavigationMode . Back ;
98+ return ;
10099 }
101100
102101 this . HandleNavigation (
103- currentPageEvent ,
104102 previousPageEvent ,
105103 ( ) =>
106104 {
@@ -137,11 +135,6 @@ public bool Navigate(Type sourcePageType)
137135 /// </returns>
138136 public bool Navigate ( Type sourcePageType , object parameter )
139137 {
140- if ( ! this . CanNavigateAway ( ) )
141- {
142- return false ;
143- }
144-
145138 if ( ! ( Activator . CreateInstance ( sourcePageType ) is Page page ) )
146139 {
147140 return false ;
@@ -154,6 +147,11 @@ public bool Navigate(Type sourcePageType, object parameter)
154147 SourcePageType = sourcePageType
155148 } ;
156149
150+ if ( ! this . CanNavigateAway ( navArgs ) )
151+ {
152+ return false ;
153+ }
154+
157155 this . HandleNavigation (
158156 navArgs ,
159157 ( ) =>
@@ -193,26 +191,18 @@ protected override void OnCreate(Bundle savedInstanceState)
193191 }
194192
195193 private void HandleNavigation ( NavigationEventArgs navArgs , Action navigationAction )
196- {
197- this . HandleNavigation ( navArgs , navArgs , navigationAction ) ;
198- }
199-
200- private void HandleNavigation (
201- NavigationEventArgs previousNavArgs ,
202- NavigationEventArgs newNavArgs ,
203- Action navigationAction )
204194 {
205195 IPage previousPage = this . currentPage ;
206- previousPage ? . OnNavigatedFrom ( previousNavArgs ) ;
196+ previousPage ? . OnNavigatedFrom ( navArgs ) ;
207197
208198 navigationAction ? . Invoke ( ) ;
209199
210200 this . currentPage = this . SupportFragmentManager . GetCurrentFragment ( ) as Page ;
211201 if ( this . currentPage != null )
212202 {
213- this . currentPage . OnNavigatedTo ( newNavArgs ) ;
214- this . CurrentSourcePageParameter = newNavArgs . Parameter ;
215- this . PageNavigated ? . Invoke ( this , newNavArgs ) ;
203+ this . currentPage . OnNavigatedTo ( navArgs ) ;
204+ this . CurrentSourcePageParameter = navArgs . Parameter ;
205+ this . PageNavigated ? . Invoke ( this , navArgs ) ;
216206 }
217207 }
218208
@@ -239,7 +229,7 @@ private void RemoveNavigationEvent(int key)
239229 }
240230 }
241231
242- private bool CanNavigateAway ( )
232+ private bool CanNavigateAway ( NavigationEventArgs args )
243233 {
244234 IPage previousPage = this . currentPage ;
245235
@@ -248,9 +238,10 @@ private bool CanNavigateAway()
248238 NavigatingCancelEventArgs navArgs =
249239 new NavigatingCancelEventArgs ( ( ) => shouldCancel = true )
250240 {
251- SourcePageType = previousPage ? . GetType ( ) ,
252- NavigationMode = NavigationMode . Back
253- } ;
241+ SourcePageType = args . SourcePageType ,
242+ NavigationMode = args . NavigationMode ,
243+ Parameter = args . Parameter
244+ } ;
254245
255246 previousPage ? . OnNavigatingFrom ( navArgs ) ;
256247
0 commit comments