示例#1
0
        async Task PushModalInternal(Page modal, bool animated)
        {
            TaskCompletionSource <bool> tcs = null;

            if (CurrentModalNavigationTask != null && !CurrentModalNavigationTask.IsCompleted)
            {
                var previousTask = CurrentModalNavigationTask;
                tcs = new TaskCompletionSource <bool>();
                CurrentModalNavigationTask = tcs.Task;
                await previousTask;
            }

            var      after  = _naviframe.NavigationStack.LastOrDefault();
            NaviItem pushed = null;

            if (animated || after == null)
            {
                pushed = _naviframe.Push(Platform.GetOrCreateRenderer(modal).NativeView, modal.Title);
            }
            else
            {
                pushed = _naviframe.InsertAfter(after, Platform.GetOrCreateRenderer(modal).NativeView, modal.Title);
            }
            pushed.TitleBarVisible = false;

            bool shouldWait = animated && after != null;

            await WaitForCompletion(shouldWait, tcs);
        }
示例#2
0
        EToolbarItem AddToolbarItem(Page newItem, int index)
        {
            EToolbarItem toolbarItem;

            // TODO: investigate if we can use the other image source types: stream, font, uri

            var iconSource = newItem.IconImageSource as FileImageSource;
            var icon       = iconSource.IsNullOrEmpty() ? null : ResourcePath.GetPath(iconSource);

            if (index == 0)
            {
                toolbarItem = _toolbar.Prepend(newItem.Title, icon);
            }
            else
            {
                toolbarItem = _toolbar.InsertAfter(_toolbarItemList[index - 1], newItem.Title, icon);
            }
            _toolbarItemList.Insert(index, toolbarItem);
            _itemToItemPage.Add(toolbarItem, newItem);

            ApplyBarItemColors(toolbarItem, BarItemColorType.Background, Element.BarBackgroundColor.ToNative());
            ApplyBarItemColors(toolbarItem, BarItemColorType.Text, Element.BarTextColor.ToNative());
            ApplyBarItemColors(toolbarItem, BarItemColorType.SelectedTab, Element.SelectedTabColor.ToNative());
            ApplyBarItemColors(toolbarItem, BarItemColorType.UnselectedTab, Element.UnselectedTabColor.ToNative());

            var childContent = Platform.GetOrCreateRenderer(newItem).NativeView;

            _innerBox.PackEnd(childContent);

            newItem.PropertyChanged += OnPageTitleChanged;

            return(toolbarItem);
        }
示例#3
0
        protected override EvasObject OnGetContent(Cell cell, string part)
        {
            if (part == SwitchPart)
            {
                var toggle = new Switch()
                {
                    BindingContext = cell,
                    Parent         = cell.Parent
                };
                toggle.SetBinding(Switch.IsToggledProperty, new Binding(SwitchCell.OnProperty.PropertyName));
                toggle.SetBinding(Switch.OnColorProperty, new Binding(SwitchCell.OnColorProperty.PropertyName));
                var nativeView = Platform.GetOrCreateRenderer(toggle).NativeView;

                if (Device.Idiom == TargetIdiom.Watch)
                {
                    nativeView.MinimumWidth += 8;
                }

                //It is a temporary way to prevent that the check of the Cell gets focus until the UX about views in the Cell for TV is defined.
                if (Device.Idiom == TargetIdiom.TV)
                {
                    ((Check)nativeView).AllowFocus(false);
                }
                else
                {
                    nativeView.PropagateEvents = false;
                }
                return(nativeView);
            }
            return(null);
        }
示例#4
0
        protected override EvasObject OnGetContent(Cell cell, string part)
        {
            if (part == MainContentPart)
            {
                var viewCell = (ViewCell)cell;

                var listView = viewCell?.RealParent as ListView;

                // It is a condition for reusable the cell
                if (listView != null &&
                    listView.HasUnevenRows == false &&
                    !(listView.ItemTemplate is DataTemplateSelector) && !GetCurrentItem().IsGroupItem)
                {
                    return(CreateReusableContent(viewCell));
                }

                Platform.GetRenderer(viewCell.View)?.Dispose();
                var    renderer = Platform.GetOrCreateRenderer(viewCell.View);
                double height   = viewCell.RenderHeight;
                height = height > 0 ? height : FindCellContentHeight(viewCell);

                renderer.NativeView.MinimumHeight = Forms.ConvertToScaledPixel(height);
                (renderer as LayoutRenderer)?.RegisterOnLayoutUpdated();

                UpdatePropagateEvent(viewCell.View);

                return(renderer.NativeView);
            }
            return(null);
        }
        EToolbarItem AddToolbarItem(Page newItem, int index)
        {
            EToolbarItem toolbarItem;

            if (index == 0)
            {
                toolbarItem = _toolbar.Prepend(newItem.Title, string.IsNullOrEmpty(newItem.Icon) ? null : ResourcePath.GetPath(newItem.Icon));
            }
            else
            {
                toolbarItem = _toolbar.InsertAfter(_toolbarItemList[index - 1], newItem.Title, string.IsNullOrEmpty(newItem.Icon) ? null : ResourcePath.GetPath(newItem.Icon));
            }
            _toolbarItemList.Insert(index, toolbarItem);
            _itemToItemPage.Add(toolbarItem, newItem);

            if (Element.BarBackgroundColor != Color.Default)
            {
                toolbarItem.SetPartColor("bg", _toolbar.BackgroundColor);
            }

            var childContent = Platform.GetOrCreateRenderer(newItem).NativeView;

            _innerBox.PackEnd(childContent);

            newItem.PropertyChanged += OnPageTitleChanged;

            return(toolbarItem);
        }
示例#6
0
        void UpdateOverlayContent()
        {
            var renderer = Platform.GetOrCreateRenderer(Specific.GetOverlayContent(_application));

            (renderer as LayoutRenderer)?.RegisterOnLayoutUpdated();
            Forms.BaseLayout.SetPartContent("elm.swallow.overlay", renderer?.NativeView);
        }
示例#7
0
        Native.Page CreateShellContent(ShellContent content)
        {
            Page xpage = ((IShellContentController)content).GetOrCreateContent();

            Native.Page page = Platform.GetOrCreateRenderer(xpage).NativeView as Native.Page;
            page.BackgroundColor = (xpage.BackgroundColor != Color.Default ? xpage.BackgroundColor.ToNative() : EColor.White);
            return(page);
        }
        protected override EvasObject OnGetContent(Cell cell, string part)
        {
            if (part == MainContentPart)
            {
                var entryCell   = cell as EntryCell;
                int pixelHeight = Forms.ConvertToScaledPixel(entryCell.RenderHeight);
                pixelHeight = pixelHeight > 0 ? pixelHeight : Forms.ConvertToPixel(s_defaultHeight);

                var label = new Label()
                {
                    HorizontalOptions     = LayoutOptions.Start,
                    VerticalOptions       = LayoutOptions.Center,
                    VerticalTextAlignment = TextAlignment.Center,
                    FontSize = -1
                };
                label.SetBinding(Label.TextProperty, new Binding(EntryCell.LabelProperty.PropertyName));
                label.SetBinding(Label.TextColorProperty, new Binding(EntryCell.LabelColorProperty.PropertyName, converter: new DefaultColorConverter()));

                var entry = new Entry()
                {
                    HorizontalOptions = LayoutOptions.FillAndExpand,
                    VerticalOptions   = LayoutOptions.Center,
                    FontSize          = -1,
                };
                entry.SetBinding(Entry.TextProperty, new Binding(EntryCell.TextProperty.PropertyName, BindingMode.TwoWay));
                entry.SetBinding(Entry.PlaceholderProperty, new Binding(EntryCell.PlaceholderProperty.PropertyName));
                entry.SetBinding(InputView.KeyboardProperty, new Binding(EntryCell.KeyboardProperty.PropertyName));
                entry.SetBinding(Entry.HorizontalTextAlignmentProperty, new Binding(EntryCell.HorizontalTextAlignmentProperty.PropertyName));

                var layout = new StackLayout()
                {
                    Orientation = StackOrientation.Horizontal,
                    Children    =
                    {
                        label,
                        entry
                    }
                };
                layout.Parent               = cell;
                layout.BindingContext       = entryCell;
                layout.MinimumHeightRequest = Forms.ConvertToScaledDP(pixelHeight);

                var renderer = Platform.GetOrCreateRenderer(layout);
                (renderer as LayoutRenderer)?.RegisterOnLayoutUpdated();

                var nativeView = renderer.NativeView;
                nativeView.PropagateEvents  = false;
                nativeView.MinimumHeight    = pixelHeight;
                _cacheCandidate[nativeView] = layout;
                nativeView.Deleted         += (sender, e) =>
                {
                    _cacheCandidate.Remove(sender as EvasObject);
                };

                return(nativeView);
            }
            return(null);
        }
 EvasObject GetOrCreatePage(Page page)
 {
     Native.Page native = Platform.GetOrCreateRenderer(page).NativeView as Native.Page;
     _pageToNative[page]    = native;
     _nativeToPage[native]  = page;
     native.BackgroundColor = (page.BackgroundColor != Xamarin.Forms.Color.Default ? page.BackgroundColor.ToNative() : ElmSharp.Color.White);
     PackEnd(native);
     return(native);
 }
示例#10
0
 void FillContent()
 {
     _scrollCanvas.UnPackAll();
     if (Element.Content != null)
     {
         _scrollCanvas.PackEnd(Platform.GetOrCreateRenderer(Element.Content).NativeView);
         UpdateContentSize();
     }
 }
        protected override void OnElementChanged(ElementChangedEventArgs <NavigationPage> e)
        {
            if (_naviFrame == null)
            {
                _naviFrame = new Naviframe(Forms.NativeParent);
                _naviFrame.PreserveContentOnPop     = true;
                _naviFrame.DefaultBackButtonEnabled = false;
                _naviFrame.AnimationFinished       += OnAnimationFinished;

                SetNativeView(_naviFrame);
                _naviItemMap = new Dictionary <Page, NaviItem>();
            }

            if (_toolbarTracker == null)
            {
                _toolbarTracker = new ToolbarTracker();
                _toolbarTracker.CollectionChanged += OnToolbarCollectionChanged;
            }

            if (e.OldElement != null)
            {
                var navigation = e.OldElement as INavigationPageController;
                navigation.PopRequested              -= OnPopRequested;
                navigation.PopToRootRequested        -= OnPopToRootRequested;
                navigation.PushRequested             -= OnPushRequested;
                navigation.RemovePageRequested       -= OnRemovePageRequested;
                navigation.InsertPageBeforeRequested -= OnInsertPageBeforeRequested;

                var pageController = e.OldElement as IPageController;
                pageController.InternalChildren.CollectionChanged -= OnPageCollectionChanged;
            }

            if (e.NewElement != null)
            {
                var navigation = e.NewElement as INavigationPageController;
                navigation.PopRequested              += OnPopRequested;
                navigation.PopToRootRequested        += OnPopToRootRequested;
                navigation.PushRequested             += OnPushRequested;
                navigation.RemovePageRequested       += OnRemovePageRequested;
                navigation.InsertPageBeforeRequested += OnInsertPageBeforeRequested;

                var pageController = e.NewElement as IPageController;
                pageController.InternalChildren.CollectionChanged += OnPageCollectionChanged;

                foreach (Page page in pageController.InternalChildren)
                {
                    _naviItemMap[page]    = _naviFrame.Push(Platform.GetOrCreateRenderer(page).NativeView, SpanTitle(page.Title));
                    page.PropertyChanged += NavigationBarPropertyChangedHandler;

                    UpdateHasNavigationBar(page);
                }

                _toolbarTracker.Target = e.NewElement;
                _previousPage          = e.NewElement.CurrentPage;
            }
            base.OnElementChanged(e);
        }
示例#12
0
        void PushRequest(object sender, Internals.NavigationRequestedEventArgs request)
        {
            var renderer = Platform.GetOrCreateRenderer(request.Page);

            _viewStack.Push(renderer.NativeView);
            request.Task = Task.FromResult(true);
            Device.BeginInvokeOnMainThread(() =>
            {
                (renderer.NativeView as Widget)?.SetFocus(true);
            });
        }
示例#13
0
 /// <summary>
 /// Updates the content of the carousel.
 /// </summary>
 void UpdateCarouselContent()
 {
     _innerContainer.UnPackAll();
     foreach (var page in Element.Children)
     {
         EvasObject nativeView = Platform.GetOrCreateRenderer(page).NativeView;
         _innerContainer.PackEnd(nativeView);
     }
     _pageIndex = Element.Children.IndexOf(Element.CurrentPage);
     _scroller.ScrollTo(_pageIndex, 0, false);
     Element.UpdateFocusTreePolicy();
 }
示例#14
0
        void UpdateTitleView(View titleView)
        {
            _nativeTitleView?.Unrealize();
            _nativeTitleView = null;

            if (titleView != null)
            {
                var renderer = Platform.GetOrCreateRenderer(titleView);
                (renderer as LayoutRenderer)?.RegisterOnLayoutUpdated();
                _nativeTitleView = renderer.NativeView;
                PackEnd(_nativeTitleView);
            }
        }
示例#15
0
        void UpdateOverlayContent()
        {
            EvasObject nativeView = null;
            var        content    = Specific.GetOverlayContent(_application);

            if (content != null)
            {
                var renderer = Platform.GetOrCreateRenderer(content);
                (renderer as LayoutRenderer)?.RegisterOnLayoutUpdated();
                nativeView = renderer?.NativeView;
            }
            Forms.BaseLayout.SetPartContent("elm.swallow.overlay", nativeView);
        }
 /// <summary>
 /// Updates the content of the carousel.
 /// </summary>
 void UpdateCarouselContent()
 {
     _innerContainer.UnPackAll();
     foreach (var page in Element.Children)
     {
         EvasObject nativeView = Platform.GetOrCreateRenderer(page).NativeView;
         _innerContainer.PackEnd(nativeView);
         // if possible, make the subpage focusable, this ensures that there is something
         // to focus on all pages and prevents the scroller from auto-scrolling to focused widget
         (nativeView as ElmSharp.Widget)?.AllowFocus(true);
     }
     _pageIndex = Element.Children.IndexOf(Element.CurrentPage);
     _scroller.ScrollTo(_pageIndex, 0, false);
 }
示例#17
0
        void InsertRequest(object sender, Internals.NavigationRequestedEventArgs request)
        {
            var before = Platform.GetRenderer(request.BeforePage)?.NativeView ?? null;

            if (before == null)
            {
                request.Task = Task.FromException <bool>(new ArgumentException("Can't found page on stack", nameof(request.BeforePage)));
                return;
            }
            var renderer = Platform.GetOrCreateRenderer(request.Page);

            _viewStack.Insert(before, renderer.NativeView);
            request.Task = Task.FromResult(true);
        }
        /// <summary>
        /// Adds a new child if it's derived from the VisualElement class. Otherwise this method does nothing.
        /// </summary>
        /// <param name="child">Child to be added.</param>
        void AddChild(Element child)
        {
            VisualElement vElement = child as VisualElement;

            if (vElement != null)
            {
                var childRenderer = Platform.GetOrCreateRenderer(vElement);

                // if the native view can have children, attach the new child
                if (NativeView is Native.IContainable <EvasObject> )
                {
                    (NativeView as Native.IContainable <EvasObject>).Children.Add(childRenderer.NativeView);
                }
            }
        }
        void OnInsertPageBeforeRequested(object sender, NavigationRequestedEventArgs nre)
        {
            if (nre.BeforePage == null)
            {
                throw new ArgumentNullException("before");
            }
            if (nre.Page == null)
            {
                throw new ArgumentNullException("page");
            }

            EvasObject page = Platform.GetOrCreateRenderer(nre.Page).NativeView;

            _naviItemMap[nre.Page] = _naviFrame.InsertBefore(GetNaviItemForPage(nre.BeforePage), page, SpanTitle(nre.Page.Title));
            UpdateHasNavigationBar(nre.Page);
        }
示例#20
0
        void UpdateCarouselContent()
        {
            _innerContainer.UnPackAll();
            _layoutBound = new ESize(0, 0);
            foreach (var page in Element.Children)
            {
                var nativeView = Platform.GetOrCreateRenderer(page).NativeView;
                _innerContainer.PackEnd(nativeView);
            }
            _pageIndex = Element.Children.IndexOf(Element.CurrentPage);

            _isUpdateCarousel = true;
            _scroller.ScrollTo(_pageIndex, 0, false);
            Element.UpdateFocusTreePolicy();
            _isUpdateCarousel = false;
        }
示例#21
0
        EvasObject CreateNavItem(Page page)
        {
            View       titleView  = NavigationPage.GetTitleView(page);
            EvasObject nativeView = null;

            if (titleView != null)
            {
                titleView.Parent = this.Element;
                nativeView       = new Native.TitleViewPage(Forms.NativeParent, page, titleView);
                nativeView.Show();
            }
            else
            {
                nativeView = Platform.GetOrCreateRenderer(page).NativeView;
            }
            return(nativeView);
        }
示例#22
0
 protected virtual void AddHeadlessChild(VisualElement element, IContainable <EvasObject> parent)
 {
     foreach (var child in element.LogicalChildren)
     {
         if (child is VisualElement visualChild)
         {
             if (CompressedLayout.GetIsHeadless(visualChild))
             {
                 AddHeadlessChild(visualChild, parent);
                 visualChild.IsPlatformEnabled = true;
             }
             else
             {
                 var childRenderer = Platform.GetOrCreateRenderer(visualChild);
                 parent.Children.Add(childRenderer.NativeView);
             }
         }
     }
 }
示例#23
0
 /// <summary>
 /// Adds a new child if it's derived from the VisualElement class. Otherwise this method does nothing.
 /// </summary>
 /// <param name="child">Child to be added.</param>
 protected virtual void AddChild(Element child)
 {
     if (child is VisualElement ve)
     {
         if (CompressedLayout.GetIsHeadless(ve) && NativeView is IContainable <EvasObject> containerNativeView)
         {
             AddHeadlessChild(ve, containerNativeView);
             ve.IsPlatformEnabled = true;
         }
         else
         {
             var childRenderer = Platform.GetOrCreateRenderer(ve);
             // if the native view can have children, attach the new child
             if (NativeView is IContainable <EvasObject> containerView)
             {
                 containerView.Children.Add(childRenderer.NativeView);
             }
         }
     }
 }
示例#24
0
        void InitializeFlyout()
        {
            ((IShellController)Element).StructureChanged += OnShellStructureChanged;

            View flyoutHeader = ((IShellController)Element).FlyoutHeader;

            if (flyoutHeader != null)
            {
                var headerView = Platform.GetOrCreateRenderer(flyoutHeader);
                (headerView as LayoutRenderer)?.RegisterOnLayoutUpdated();

                Size request = flyoutHeader.Measure(Forms.ConvertToScaledDP(_native.NavigationView.MinimumWidth), Forms.ConvertToScaledDP(_native.NavigationView.MinimumHeight)).Request;
                headerView.NativeView.MinimumHeight = Forms.ConvertToScaledPixel(request.Height);

                _native.NavigationView.Header = headerView.NativeView;
            }

            BuildMenu();
            _native.NavigationView.MenuItemSelected += OnItemSelected;
        }
        void OnPushRequested(object sender, NavigationRequestedEventArgs nre)
        {
            if (nre.Animated || _naviFrame.NavigationStack.Count == 0)
            {
                _naviItemMap[nre.Page] = _naviFrame.Push(Platform.GetOrCreateRenderer(nre.Page).NativeView, SpanTitle(nre.Page.Title));
                _currentTaskSource     = new TaskCompletionSource <bool>();
                nre.Task = _currentTaskSource.Task;

                // There is no TransitionFinished (AnimationFinished) event after the first Push
                if (_naviFrame.NavigationStack.Count == 1)
                {
                    CompleteCurrentNavigationTask();
                }
            }
            else
            {
                _naviItemMap[nre.Page] = _naviFrame.InsertAfter(_naviFrame.NavigationStack.Last(), Platform.GetOrCreateRenderer(nre.Page).NativeView, SpanTitle(nre.Page.Title));
            }
            UpdateHasNavigationBar(nre.Page);
        }
示例#26
0
 void FillContent()
 {
     if (Forms.UseFastLayout)
     {
         EvasFormsCanvas.UnPackAll();
         if (Element.Content != null)
         {
             EvasFormsCanvas.PackEnd(Platform.GetOrCreateRenderer(Element.Content).NativeView);
             UpdateContentSize();
         }
     }
     else
     {
         Canvas.UnPackAll();
         if (Element.Content != null)
         {
             Canvas.PackEnd(Platform.GetOrCreateRenderer(Element.Content).NativeView);
             UpdateContentSize();
         }
     }
 }
示例#27
0
        void OnInnerLayoutUpdate()
        {
            int  baseX = _innerBox.Geometry.X;
            Rect bound = _scroller.Geometry;
            int  index = 0;

            foreach (var page in Element.Children)
            {
                var nativeView = Platform.GetOrCreateRenderer(page).NativeView;
                bound.X             = baseX + index * bound.Width;
                nativeView.Geometry = bound;
                index++;
            }
            _innerBox.MinimumWidth = Element.Children.Count * bound.Width;
            if (_toolbar.SelectedItem == null)
            {
                return;
            }
            int currentPage = MultiPage <Page> .GetIndex(_itemToItemPage[_toolbar.SelectedItem]);

            _scroller.ScrollTo(currentPage, 0, true);
        }
示例#28
0
        EvasObject CreateReusableContent(ViewCell viewCell)
        {
            var      listView       = viewCell.RealParent as ListView;
            ViewCell duplicatedCell = (ViewCell)listView.ItemTemplate.CreateContent();

            duplicatedCell.BindingContext = viewCell.BindingContext;
            duplicatedCell.Parent         = listView;

            var    renderer = Platform.GetOrCreateRenderer(duplicatedCell.View);
            double height   = duplicatedCell.RenderHeight;

            height = height > 0 ? height : FindCellContentHeight(duplicatedCell);
            renderer.NativeView.MinimumHeight = Forms.ConvertToScaledPixel(height);

            _cacheCandidate[renderer.NativeView] = duplicatedCell;
            renderer.NativeView.Deleted         += (sender, e) =>
            {
                _cacheCandidate.Remove((EvasObject)sender);
            };
            (renderer as LayoutRenderer)?.RegisterOnLayoutUpdated();

            return(renderer.NativeView);
        }
        void FillContent()
        {
            if (_content != null)
            {
                if (_content is Native.Box contentBox)
                {
                    contentBox.LayoutUpdated -= OnContentLayoutUpdated;
                }
                Control.SetContent(null, true);
                _content.Unrealize();
                _content = null;
            }

            if (Element.Content != null)
            {
                _content = Platform.GetOrCreateRenderer(Element.Content).NativeView;
                if (_content is Native.Box contentBox)
                {
                    contentBox.LayoutUpdated += OnContentLayoutUpdated;
                }
                Control.SetContent(_content, true);
                UpdateContentSize();
            }
        }
示例#30
0
        EvasObject CreateShellContent(ShellContent content)
        {
            Page xpage = ((IShellContentController)content).GetOrCreateContent();

            return(Platform.GetOrCreateRenderer(xpage).NativeView);
        }