@@ -26,48 +26,51 @@ public class MultiBackStackView : MvxFragment<MultiBackStackViewModel>
2626{
2727private NavigationBarView _navigationView ;
2828private bool _navigatedToTab2 ;
29-
29+
3030public override View OnCreateView ( LayoutInflater inflater , ViewGroup container , Bundle savedInstanceState )
3131{
32- base . OnCreateView ( inflater , container , savedInstanceState ) ;
32+ base . OnCreateView ( inflater , container , savedInstanceState ) ;
33+
34+ var view = this . BindingInflate ( Resource . Layout . MultiBackStackView , container , false ) ;
3335
34- var view = this . BindingInflate ( Resource . Layout . MultiBackStackView , container , false ) ;
35-
36- _navigationView = view . FindViewById < NavigationBarView > ( Resource . Id . navigationview ) ;
37- _navigationView . ItemSelected += NavigationViewOnItemSelected ;
36+ _navigationView = view . FindViewById < NavigationBarView > ( Resource . Id . navigationview ) ;
37+ _navigationView . ItemSelected += NavigationViewOnItemSelected ;
3838
39- return view ;
39+ return view ;
4040}
4141
4242public override void OnDestroy ( )
4343{
44- base . OnDestroy ( ) ;
45-
46- if ( _navigationView != null )
47- {
48- _navigationView . ItemSelected -= NavigationViewOnItemSelected ;
49- }
44+ base . OnDestroy ( ) ;
45+
46+ if ( _navigationView != null )
47+ {
48+ _navigationView . ItemSelected -= NavigationViewOnItemSelected ;
49+ }
5050}
5151
52- private void NavigationViewOnItemSelected ( object sender , NavigationBarView . ItemSelectedEventArgs ev )
53- {
54- switch ( ev . Item . ItemId )
55- {
56- case Resource . Id . tab1 :
57- ChildFragmentManager . SaveBackStack ( typeof ( MultiBackStackTab2View ) . FragmentJavaName ( ) ) ;
58- ChildFragmentManager . RestoreBackStack ( typeof ( MultiBackStackTab1View ) . FragmentJavaName ( ) ) ;
59- break ;
60- case Resource . Id . tab2 :
61- ChildFragmentManager . SaveBackStack ( typeof ( MultiBackStackTab1View ) . FragmentJavaName ( ) ) ;
62- if ( ! _navigatedToTab2 ) {
63- _navigatedToTab2 = true ;
64- Mvx . IoCProvider . Resolve < IMvxNavigationService > ( ) . Navigate ( typeof ( MultiBackStackTab2ViewModel ) ) ;
65- } else {
66- ChildFragmentManager . RestoreBackStack ( typeof ( MultiBackStackTab2View ) . FragmentJavaName ( ) ) ;
67- }
68- break ;
69- }
70- }
52+ private void NavigationViewOnItemSelected ( object sender , NavigationBarView . ItemSelectedEventArgs ev )
53+ {
54+ switch ( ev . Item . ItemId )
55+ {
56+ case Resource . Id . tab1 :
57+ ChildFragmentManager . SaveBackStack ( typeof ( MultiBackStackTab2View ) . FragmentJavaName ( ) ) ;
58+ ChildFragmentManager . RestoreBackStack ( typeof ( MultiBackStackTab1View ) . FragmentJavaName ( ) ) ;
59+ break ;
60+ case Resource . Id . tab2 :
61+ ChildFragmentManager . SaveBackStack ( typeof ( MultiBackStackTab1View ) . FragmentJavaName ( ) ) ;
62+ if ( ! _navigatedToTab2 )
63+ {
64+ _navigatedToTab2 = true ;
65+ Mvx . IoCProvider . Resolve < IMvxNavigationService > ( ) . Navigate ( typeof ( MultiBackStackTab2ViewModel ) ) ;
66+ }
67+ else
68+ {
69+ ChildFragmentManager . RestoreBackStack ( typeof ( MultiBackStackTab2View ) . FragmentJavaName ( ) ) ;
70+ }
71+ break ;
72+ }
73+ }
7174}
7275
7376[ MvxFragmentPresentation ( typeof ( RootViewModel ) , Resource . Id . content_frame , true ,
@@ -78,11 +81,11 @@ public class MultiBackStackTab1View : MvxFragment<MultiBackStackTab1ViewModel>
7881{
7982public override View OnCreateView ( LayoutInflater inflater , ViewGroup container , Bundle savedInstanceState )
8083{
81- base . OnCreateView ( inflater , container , savedInstanceState ) ;
84+ base . OnCreateView ( inflater , container , savedInstanceState ) ;
8285
83- var view = this . BindingInflate ( Resource . Layout . MultiBackStackTab1View , container , false ) ;
86+ var view = this . BindingInflate ( Resource . Layout . MultiBackStackTab1View , container , false ) ;
8487
85- return view ;
88+ return view ;
8689}
8790
8891}
@@ -95,44 +98,44 @@ public class MultiBackStackTab2View : MvxFragment<MultiBackStackTab2ViewModel>
9598{
9699public override View OnCreateView ( LayoutInflater inflater , ViewGroup container , Bundle savedInstanceState )
97100{
98- base . OnCreateView ( inflater , container , savedInstanceState ) ;
101+ base . OnCreateView ( inflater , container , savedInstanceState ) ;
99102
100- var view = this . BindingInflate ( Resource . Layout . MultiBackStackTab2View , container , false ) ;
103+ var view = this . BindingInflate ( Resource . Layout . MultiBackStackTab2View , container , false ) ;
101104
102- return view ;
105+ return view ;
103106}
104107}
105108
106109public class MultiBackStackInnerView : MvxFragment < MultiBackStackInnerViewModel > , IMvxOverridePresentationAttribute
107110{
108111public override View OnCreateView ( LayoutInflater inflater , ViewGroup container , Bundle savedInstanceState )
109112{
110- base . OnCreateView ( inflater , container , savedInstanceState ) ;
113+ base . OnCreateView ( inflater , container , savedInstanceState ) ;
111114
112- var view = this . BindingInflate ( Resource . Layout . MultiBackStackInnerView , container , false ) ;
115+ var view = this . BindingInflate ( Resource . Layout . MultiBackStackInnerView , container , false ) ;
113116
114- var f = ParentFragmentManager . PrimaryNavigationFragment ;
115- return view ;
117+ var f = ParentFragmentManager . PrimaryNavigationFragment ;
118+ return view ;
116119}
117120
118121public MvxBasePresentationAttribute PresentationAttribute ( MvxViewModelRequest request )
119122{
120- if ( request is MvxViewModelInstanceRequest { ViewModelInstance : MultiBackStackInnerViewModel viewModel , ViewModelType : { } viewModelType } )
121- {
122- return new MvxFragmentPresentationAttribute ( )
123- {
124- ViewModelType = typeof ( MultiBackStackInnerViewModel ) ,
125- ActivityHostViewModelType = typeof ( RootViewModel ) ,
126- FragmentHostViewType = typeof ( MultiBackStackView ) ,
127- FragmentContentId = Resource . Id . content_frame ,
128- AddToBackStack = true ,
129- AllowReordering = true ,
130- Tag = viewModelType . Name + viewModel . Depth // unique tag so the restoration restores all of them
131- } ;
132- }
133- else
134- {
135- return null ;
136- }
123+ if ( request is MvxViewModelInstanceRequest { ViewModelInstance : MultiBackStackInnerViewModel viewModel , ViewModelType : { } viewModelType } )
124+ {
125+ return new MvxFragmentPresentationAttribute ( )
126+ {
127+ ViewModelType = typeof ( MultiBackStackInnerViewModel ) ,
128+ ActivityHostViewModelType = typeof ( RootViewModel ) ,
129+ FragmentHostViewType = typeof ( MultiBackStackView ) ,
130+ FragmentContentId = Resource . Id . content_frame ,
131+ AddToBackStack = true ,
132+ AllowReordering = true ,
133+ Tag = viewModelType . Name + viewModel . Depth // unique tag so the restoration restores all of them
134+ } ;
135+ }
136+ else
137+ {
138+ return null ;
139+ }
137140}
138- }
141+ }