// Use OnDestroy instead of OnDestroyView because OnDestroyView will be // called before the animation completes. This causes tons of tiny issues. public override void OnDestroy() { base.OnDestroy(); if (_rootView != null) { UnhookEvents(); var adapter = _viewPager.Adapter; _viewPager.Adapter = null; adapter.Dispose(); _toolbarAppearanceTracker.Dispose(); _tabLayoutAppearanceTracker.Dispose(); _viewPager.RemoveOnPageChangeListener(this); _rootView.Dispose(); _toolbarTracker.Dispose(); _tablayout.Dispose(); _toolbar.Dispose(); _viewPager.Dispose(); _rootView.Dispose(); } _toolbarAppearanceTracker = null; _tabLayoutAppearanceTracker = null; _toolbarTracker = null; _toolbar = null; _tablayout = null; _rootView = null; _viewPager = null; }
void Destroy() { if (_rootView != null) { UnhookEvents(); _viewPager.RemoveOnPageChangeListener(this); var adapter = _viewPager.Adapter; _viewPager.Adapter = null; adapter.Dispose(); _tablayout.LayoutChange -= OnTabLayoutChange; _toolbarAppearanceTracker.Dispose(); _tabLayoutAppearanceTracker.Dispose(); _toolbarTracker.Dispose(); _tablayout.Dispose(); _toolbar.Dispose(); _viewPager.Dispose(); _rootView.Dispose(); } _toolbarAppearanceTracker = null; _tabLayoutAppearanceTracker = null; _toolbarTracker = null; _tablayout = null; _toolbar = null; _viewPager = null; _rootView = null; }
void Destroy() { if (_rootView != null) { UnhookEvents(); _shellContext?.Shell?.Toolbar?.Handler?.DisconnectHandler(); //_viewPager.RemoveOnPageChangeListener(this); var adapter = _viewPager.Adapter; _viewPager.Adapter = null; adapter.Dispose(); _tablayout.LayoutChange -= OnTabLayoutChange; _toolbarAppearanceTracker.Dispose(); _tabLayoutAppearanceTracker.Dispose(); _toolbarTracker.Dispose(); _tablayout.Dispose(); _toolbar.Dispose(); _viewPager.Dispose(); _rootView.Dispose(); } _toolbarAppearanceTracker = null; _tabLayoutAppearanceTracker = null; _toolbarTracker = null; _tablayout = null; _toolbar = null; _viewPager = null; _rootView = null; }
public override AView OnCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { var shellSection = ShellSection; if (shellSection == null) { return(null); } var root = inflater.Inflate(Resource.Layout.RootLayout, null).JavaCast <CoordinatorLayout>(); _toolbar = root.FindViewById <Toolbar>(Resource.Id.main_toolbar); var scrollview = root.FindViewById <NestedScrollView>(Resource.Id.main_scrollview); _tablayout = root.FindViewById <TabLayout>(Resource.Id.main_tablayout); _viewPager = new FormsViewPager(Context) { LayoutParameters = new LP(LP.MatchParent, LP.MatchParent), }; _viewPager.AddOnPageChangeListener(this); _viewPager.Id = Platform.GenerateViewId(); _viewPager.Adapter = new ShellFragmentPagerAdapter(shellSection, ChildFragmentManager); _viewPager.OverScrollMode = OverScrollMode.Never; _tablayout.SetupWithViewPager(_viewPager); var currentPage = ((IShellContentController)shellSection.CurrentItem).GetOrCreateContent(); var currentIndex = ShellSection.Items.IndexOf(ShellSection.CurrentItem); _toolbarTracker = _shellContext.CreateTrackerForToolbar(_toolbar); _toolbarTracker.Page = currentPage; _viewPager.CurrentItem = currentIndex; scrollview.AddView(_viewPager); if (shellSection.Items.Count == 1) { _tablayout.Visibility = ViewStates.Gone; } _tabLayoutAppearanceTracker = _shellContext.CreateTabLayoutAppearanceTracker(ShellSection); _toolbarAppearanceTracker = _shellContext.CreateToolbarAppearanceTracker(); HookEvents(); scrollview.Dispose(); return(_rootView = root); }
public override AView OnCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { var shellSection = ShellSection; if (shellSection == null) { return(null); } if (shellSection.CurrentItem == null) { throw new InvalidOperationException($"Content not found for active {shellSection}. Title: {shellSection.Title}. Route: {shellSection.Route}."); } var root = inflater.Inflate(Resource.Layout.RootLayout, null).JavaCast <CoordinatorLayout>(); _toolbar = root.FindViewById <Toolbar>(Resource.Id.main_toolbar); _viewPager = root.FindViewById <FormsViewPager>(Resource.Id.main_viewpager); _tablayout = root.FindViewById <TabLayout>(Resource.Id.main_tablayout); _viewPager.EnableGesture = false; _viewPager.AddOnPageChangeListener(this); _viewPager.Id = Platform.GenerateViewId(); _viewPager.Adapter = new ShellFragmentPagerAdapter(shellSection, ChildFragmentManager); _viewPager.OverScrollMode = OverScrollMode.Never; _tablayout.SetupWithViewPager(_viewPager); var currentPage = ((IShellContentController)shellSection.CurrentItem).GetOrCreateContent(); var currentIndex = SectionController.GetItems().IndexOf(ShellSection.CurrentItem); _toolbarTracker = _shellContext.CreateTrackerForToolbar(_toolbar); _toolbarTracker.Page = currentPage; _viewPager.CurrentItem = currentIndex; if (SectionController.GetItems().Count == 1) { _tablayout.Visibility = ViewStates.Gone; } _tabLayoutAppearanceTracker = _shellContext.CreateTabLayoutAppearanceTracker(ShellSection); _toolbarAppearanceTracker = _shellContext.CreateToolbarAppearanceTracker(); HookEvents(); return(_rootView = root); }
public override AView OnCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { var shellSection = ShellSection; if (shellSection == null) { return(null); } if (shellSection.CurrentItem == null) { throw new InvalidOperationException($"Content not found for active {shellSection}. Title: {shellSection.Title}. Route: {shellSection.Route}."); } var context = Context; var root = PlatformInterop.CreateShellCoordinatorLayout(context); var appbar = PlatformInterop.CreateShellAppBar(context, Resource.Attribute.appBarLayoutStyle, root); int actionBarHeight = context.GetActionBarHeight(); _toolbar = PlatformInterop.CreateShellToolbar(context, appbar, actionBarHeight, Resource.Style.ThemeOverlay_AppCompat_Light); _tablayout = PlatformInterop.CreateShellTabLayout(context, appbar, actionBarHeight); var pagerContext = MauiContext.MakeScoped(layoutInflater: inflater, fragmentManager: ChildFragmentManager); var adapter = new ShellFragmentStateAdapter(shellSection, ChildFragmentManager, pagerContext); var pageChangedCallback = new ViewPagerPageChanged(this); _viewPager = PlatformInterop.CreateShellViewPager(context, root, _tablayout, this, adapter, pageChangedCallback); Page currentPage = null; int currentIndex = -1; var currentItem = shellSection.CurrentItem; var items = SectionController.GetItems(); while (currentIndex < 0 && items.Count > 0 && shellSection.CurrentItem != null) { currentItem = shellSection.CurrentItem; currentPage = ((IShellContentController)shellSection.CurrentItem).GetOrCreateContent(); // current item hasn't changed if (currentItem == shellSection.CurrentItem) { currentIndex = items.IndexOf(currentItem); } } _toolbarTracker = _shellContext.CreateTrackerForToolbar(_toolbar); _toolbarTracker.Page = currentPage; _viewPager.CurrentItem = currentIndex; if (items.Count == 1) { UpdateTablayoutVisibility(); } _tablayout.LayoutChange += OnTabLayoutChange; _tabLayoutAppearanceTracker = _shellContext.CreateTabLayoutAppearanceTracker(ShellSection); _toolbarAppearanceTracker = _shellContext.CreateToolbarAppearanceTracker(); HookEvents(); return(_rootView = root); }
public override AView OnCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { var shellSection = ShellSection; if (shellSection == null) { return(null); } if (shellSection.CurrentItem == null) { throw new InvalidOperationException($"Content not found for active {shellSection}. Title: {shellSection.Title}. Route: {shellSection.Route}."); } var root = inflater.Inflate(Resource.Layout.shellrootlayout, null).JavaCast <CoordinatorLayout>(); _toolbar = root.FindViewById <Toolbar>(Resource.Id.maui_toolbar); if (Context.GetActivity() is AppCompatActivity aca) { aca.SetSupportActionBar(_toolbar); } _viewPager = root.FindViewById <ViewPager2>(Resource.Id.main_viewpager); _tablayout = root.FindViewById <TabLayout>(Resource.Id.main_tablayout); //_viewPager.EnableGesture = false; //_viewPager.AddOnPageChangeListener(this); _viewPager.Id = AView.GenerateViewId(); _viewPager.Adapter = new ShellFragmentStateAdapter(shellSection, ChildFragmentManager, MauiContext); _viewPager.OverScrollMode = OverScrollMode.Never; new TabLayoutMediator(_tablayout, _viewPager, this) .Attach(); //_tablayout.SetupWithViewPager(_viewPager); Page currentPage = null; int currentIndex = -1; var currentItem = ShellSection.CurrentItem; while (currentIndex < 0 && SectionController.GetItems().Count > 0 && ShellSection.CurrentItem != null) { currentItem = ShellSection.CurrentItem; currentPage = ((IShellContentController)shellSection.CurrentItem).GetOrCreateContent(); // current item hasn't changed if (currentItem == shellSection.CurrentItem) { currentIndex = SectionController.GetItems().IndexOf(currentItem); } } _toolbarTracker = _shellContext.CreateTrackerForToolbar(_toolbar); _toolbarTracker.Page = currentPage; _viewPager.CurrentItem = currentIndex; if (SectionController.GetItems().Count == 1) { UpdateTablayoutVisibility(); } _tablayout.LayoutChange += OnTabLayoutChange; _tabLayoutAppearanceTracker = _shellContext.CreateTabLayoutAppearanceTracker(ShellSection); _toolbarAppearanceTracker = _shellContext.CreateToolbarAppearanceTracker(); HookEvents(); return(_rootView = root); }