Exemplo n.º 1
0
        private void OnPagesChanged(object sender, NotifyCollectionChangedEventArgs e)
        {
            switch (e.Action)
            {
            case NotifyCollectionChangedAction.Add:

                int index = e.NewStartingIndex;
                for (int i = 0; i < e.NewItems.Count; i++)
                {
                    var page = e.NewItems[i] as Page;
                    Widget.AddPage(index, page);
                    _pages.Add(new PageContainer(page, i));
                    index++;
                }

                var newPages = new List <object>();
                foreach (var pc in _pages)
                {
                    newPages.Add(pc.Page);
                }

                e.Apply(Page.Children, newPages);

                break;

            case NotifyCollectionChangedAction.Remove:

                for (int i = 0; i < e.OldItems.Count; i++)
                {
                    var page = e.OldItems[i];
                    Widget.RemovePage(page);
                    var pageContainer = _pages.FirstOrDefault(p => p.Page == page);
                    _pages.Remove(pageContainer);
                }

                var oldPages = new List <object>();
                foreach (var pc in _pages)
                {
                    oldPages.Add(pc.Page);
                }

                e.Apply(Page.Children, oldPages);
                UpdateCurrentPage();
                break;

            case NotifyCollectionChangedAction.Reset:
                Widget?.Reset();
                UpdateSource();
                break;
            }
        }
Exemplo n.º 2
0
        void OnPagesChanged(object sender, NotifyCollectionChangedEventArgs e)
        {
            e.Apply(Element.Children, Control.Items);

            // Potential performance issue, UpdateLayout () is called for every page change
            Control.UpdateLayout();
        }
Exemplo n.º 3
0
        void OnPagesChanged(object sender, NotifyCollectionChangedEventArgs e)
        {
            e.Apply(Element.Children, Control.Items);
            switch (e.Action)
            {
            case NotifyCollectionChangedAction.Add:
            case NotifyCollectionChangedAction.Remove:
            case NotifyCollectionChangedAction.Replace:
                if (e.NewItems != null)
                {
                    for (int i = 0; i < e.NewItems.Count; i++)
                    {
                        ((Page)e.NewItems[i]).PropertyChanged += OnChildPagePropertyChanged;
                    }
                }
                if (e.OldItems != null)
                {
                    for (int i = 0; i < e.OldItems.Count; i++)
                    {
                        ((Page)e.OldItems[i]).PropertyChanged -= OnChildPagePropertyChanged;
                    }
                }
                break;

            case NotifyCollectionChangedAction.Reset:
                foreach (var page in Element.Children)
                {
                    page.PropertyChanged += OnChildPagePropertyChanged;
                }
                break;
            }

            Control.UpdateLayout();
            EnsureBarColors(e.Action);
        }
Exemplo n.º 4
0
 void OnItemsSourceCollectionChanged(object sender, NotifyCollectionChangedEventArgs e)
 {
     e.Apply(
         insert: (item, _, __) => CreatePin(item),
         removeAt: (item, _) => RemovePin(item),
         reset: () => _pins.Clear());
 }
Exemplo n.º 5
0
        void OnChildrenCollectionChanged(object sender, NotifyCollectionChangedEventArgs e)
        {
            e.Apply((o, i, c) => SetupPage((Page)o), (o, i) => TeardownPage((Page)o), Reset);

            FormsViewPager pager = _viewPager;
            TabLayout      tabs  = _tabLayout;

            ((FormsFragmentPagerAdapter <Page>)pager.Adapter).CountOverride = Element.Children.Count;

            pager.Adapter.NotifyDataSetChanged();

            if (Element.Children.Count == 0)
            {
                tabs.RemoveAllTabs();
                tabs.SetupWithViewPager(null);
            }
            else
            {
                tabs.SetupWithViewPager(pager);
                UpdateTabIcons();
                tabs.SetOnTabSelectedListener(this);
            }

            UpdateIgnoreContainerAreas();
        }
Exemplo n.º 6
0
        void OnPagesChanged(object sender, NotifyCollectionChangedEventArgs e)
        {
            e.Apply((o, i, c) => SetupPage((Page)o, i), (o, i) => TeardownPage((Page)o), Reset);

            SetControllers();

            UpdateChildrenOrderIndex();

            SetSelectedTabViewItem();
        }
Exemplo n.º 7
0
 private void OnPagesChanged(object sender, NotifyCollectionChangedEventArgs e)
 {
     if (this.Element != null && this.Control != null)
     {
         e.Apply(this.Element.Children, this.Control.Items);
     }
     if (this.Control != null)
     {
         this.Control.UpdateLayout();
     }
 }
 public static void Apply <TFrom>(this NotifyCollectionChangedEventArgs self, IList <TFrom> from, IList <object> to)
 {
     self.Apply((o, i, b) => to.Insert(i, o), (o, i) => to.RemoveAt(i), () =>
     {
         to.Clear();
         for (var i = 0; i < from.Count; i++)
         {
             to.Add(from[i]);
         }
     });
 }
Exemplo n.º 9
0
        void OnChildrenCollectionChanged(object sender, NotifyCollectionChangedEventArgs e)
        {
            e.Apply((o, i, c) => SetupPage((Page)o), (o, i) => TeardownPage((Page)o), Reset);

            ViewPager2 pager   = _viewPager;
            var        adapter = (MultiPageFragmentStateAdapter <Page>)pager.Adapter;

            adapter.CountOverride = Element.Children.Count;
            if (IsBottomTabPlacement)
            {
                BottomNavigationView bottomNavigationView = _bottomNavigationView;

                adapter.NotifyDataSetChanged();

                if (Element.Children.Count == 0)
                {
                    bottomNavigationView.Menu.Clear();
                }
                else
                {
                    SetupBottomNavigationView(e);
                    bottomNavigationView.SetOnItemSelectedListener(_listeners);
                }

                UpdateIgnoreContainerAreas();
            }
            else
            {
                TabLayout tabs = _tabLayout;

                adapter.NotifyDataSetChanged();
                if (Element.Children.Count == 0)
                {
                    tabs.RemoveAllTabs();
                    tabs.SetupWithViewPager(null);
                }
                else
                {
                    new TabLayoutMediator(tabs, _viewPager, _listeners)
                    .Attach();

                    UpdateTabIcons();
#pragma warning disable CS0618 // Type or member is obsolete
                    tabs.AddOnTabSelectedListener(_listeners);
#pragma warning restore CS0618 // Type or member is obsolete
                }

                UpdateIgnoreContainerAreas();
            }
        }
Exemplo n.º 10
0
        void OnChildrenCollectionChanged(object sender, NotifyCollectionChangedEventArgs e)
        {
            e.Apply((o, i, c) => SetupPage((Page)o), (o, i) => TeardownPage((Page)o), Reset);

            if (IsBottomTabPlacement)
            {
                FormsViewPager       pager = _viewPager;
                BottomNavigationView bottomNavigationView = _bottomNavigationView;

                ((FormsFragmentPagerAdapter <Page>)pager.Adapter).CountOverride = Element.Children.Count;

                pager.Adapter.NotifyDataSetChanged();

                if (Element.Children.Count == 0)
                {
                    bottomNavigationView.Menu.Clear();
                }
                else
                {
                    SetupBottomNavigationView(e);
                    bottomNavigationView.SetOnNavigationItemSelectedListener(this);
                }

                UpdateIgnoreContainerAreas();
            }
            else
            {
                FormsViewPager pager = _viewPager;
                TabLayout      tabs  = _tabLayout;

                ((FormsFragmentPagerAdapter <Page>)pager.Adapter).CountOverride = Element.Children.Count;
                pager.Adapter.NotifyDataSetChanged();
                if (Element.Children.Count == 0)
                {
                    tabs.RemoveAllTabs();
                    tabs.SetupWithViewPager(null);
                }
                else
                {
                    tabs.SetupWithViewPager(pager);
                    UpdateTabIcons();
#pragma warning disable CS0618 // Type or member is obsolete
                    tabs.AddOnTabSelectedListener(this);
#pragma warning restore CS0618 // Type or member is obsolete
                }

                UpdateIgnoreContainerAreas();
            }
        }
Exemplo n.º 11
0
		void OnPagesChanged(object sender, NotifyCollectionChangedEventArgs e)
		{
			e.Apply((o, i, c) => SetupPage((Page)o, i), (o, i) => TeardownPage((Page)o, i), Reset);

			SetControllers();

			UIViewController controller = null;
			if (Tabbed.CurrentPage != null)
				controller = GetViewController(Tabbed.CurrentPage);
			if (controller != null && controller != base.SelectedViewController)
				base.SelectedViewController = controller;

			UpdateBarBackgroundColor();
			UpdateBarTextColor();
			UpdateSelectedTabColors();
		}
Exemplo n.º 12
0
        void OnPagesChanged(object sender, NotifyCollectionChangedEventArgs e)
        {
            e.Apply((o, i, c) => SetupPage((Page)o, i), (o, i) => TeardownPage((Page)o, i), Reset);

            SetControllers();

            UIViewController controller = null;

            if (Tabbed.CurrentPage != null)
            {
                controller = GetViewController(Tabbed.CurrentPage);
            }
            if (controller != null && controller != base.SelectedViewController)
            {
                base.SelectedViewController = controller;
            }
        }
            private void Vms_CollectionChanged(object sender, NotifyCollectionChangedEventArgs e)
            {
                var collection = (IList)sender;

                e.Apply(
                    //insert
                    (o, i, b) => {
                    Insert(o, i, b);
                },
                    //remove
                    (o, i) => {
                    Remove(o, i);
                },
                    //reset
                    () => {
                    Reset(collection);
                });
            }
        void OnPagesChanged(object sender, NotifyCollectionChangedEventArgs e)
        {
            e.Apply((o, i, c) => SetupPage((Page)o, i), (o, i) => TeardownPage((Page)o, i), Reset);
            SetControllers();
            UIViewController controller = null;

            if (Tabbed.CurrentPage != null)
            {
                controller = GetViewController(Tabbed.CurrentPage);
            }
            if (controller != null && controller != SelectedViewController)
            {
                SelectedViewController = controller;
                var index = ViewControllers.IndexOf(SelectedViewController);
                MoveToByIndex(index);
                TabBar.SelectedIndex = index;
            }
        }
Exemplo n.º 15
0
        void OnPagesChanged(object sender, NotifyCollectionChangedEventArgs e)
        {
            _ignoreNativeScrolling = true;

            NotifyCollectionChangedAction action = e.Apply((o, i, c) => InsertPage((ContentPage)o, i), (o, i) => RemovePage((ContentPage)o, i), Reset);

            PositionChildren();

            _ignoreNativeScrolling = false;

            if (action == NotifyCollectionChangedAction.Reset)
            {
                int index = Carousel.CurrentPage != null?CarouselPage.GetIndex(Carousel.CurrentPage) : 0;

                if (index < 0)
                {
                    index = 0;
                }

                ScrollToPage(index);
            }
        }
Exemplo n.º 16
0
        void CurrentTabbedPageChildrenChanged(object sender, NotifyCollectionChangedEventArgs e)
        {
            if (CurrentTabbedPage == null)
            {
                return;
            }

            _ignoreAndroidSelection = true;

            e.Apply((o, index, create) => AddTab((Page)o, index), (o, index) => RemoveTab((Page)o, index), Reset);

            if (CurrentTabbedPage.CurrentPage != null)
            {
                Page page  = CurrentTabbedPage.CurrentPage;
                int  index = TabbedPage.GetIndex(page);
                if (index >= 0 && index < CurrentTabbedPage.Children.Count)
                {
                    ActionBar.GetTabAt(index).Select();
                }
            }

            _ignoreAndroidSelection = false;
        }
Exemplo n.º 17
0
        void OnPagesChanged(object sender, NotifyCollectionChangedEventArgs e)
        {
            e.Apply(Element.Children, Control.Items);
            switch (e.Action)
            {
            case NotifyCollectionChangedAction.Add:
            case NotifyCollectionChangedAction.Remove:
            case NotifyCollectionChangedAction.Replace:
                if (e.NewItems != null)
                {
                    for (int i = 0; i < e.NewItems.Count; i++)
                    {
                        (e.NewItems[i] as Page).PropertyChanged += OnChildPagePropertyChanged;
                    }
                }
                if (e.OldItems != null)
                {
                    for (int i = 0; i < e.OldItems.Count; i++)
                    {
                        (e.OldItems[i] as Page).PropertyChanged -= OnChildPagePropertyChanged;
                    }
                }
                break;

            case NotifyCollectionChangedAction.Reset:
                foreach (var p in Element.Children)
                {
                    p.PropertyChanged += OnChildPagePropertyChanged;
                }
                break;

            default:
                break;
            }
            // Potential performance issue, UpdateLayout () is called for every page change
            Control.UpdateLayout();
        }
Exemplo n.º 18
0
 void OnPagesChanged(object sender, NotifyCollectionChangedEventArgs e)
 {
     e.Apply(Page.Children, _tabs.Items);
 }
Exemplo n.º 19
0
 void OnPagesChanged(object sender, NotifyCollectionChangedEventArgs e)
 {
     e.Apply(InsertItem, RemoveItem, Reset);
 }
 void OnPagesChanged(object sender, NotifyCollectionChangedEventArgs e)
 {
     e.Apply(Element.Children, Control.ItemsSource);
 }
Exemplo n.º 21
0
 void OnChildrenChanged(object sender, NotifyCollectionChangedEventArgs e)
 {
     e.Apply(Element.Children, Items);
 }