private void StaticPresentToolbar(ToolbarItemBase toolbar, Action<IToolbar> afterToolbarUpdateAction) { _currentPrimaryViews.Clear(); _currentSecondaryViews.Clear(); foreach (UIView view in Subviews) view.RemoveFromSuperview(); CreatePrimaryViews(toolbar); CreateSecondaryViews(toolbar); if (afterToolbarUpdateAction != null) { afterToolbarUpdateAction(this); } }
private void RecursivelyFindIds(ToolbarItemBase node) { if (!String.IsNullOrWhiteSpace(node.Id)) { _idsToItems.Add(node.Id, node); } foreach (ToolbarItem childNode in node.PrimaryItems) { RecursivelyFindIds(childNode); } foreach (ToolbarItem childNode in node.SecondaryItems) { RecursivelyFindIds(childNode); } }
private void CreateSecondaryViews(ToolbarItemBase toolbar) { float offset = (IsHorizontal ? Bounds.Size.Width : Bounds.Size.Height) - _definition.ItemSpacing; foreach (ToolbarItem item in toolbar.SecondaryItems.Reverse()) { UIView toolbarView = CreateToolbarView(item); offset -= IsHorizontal ? toolbarView.Frame.Width : toolbarView.Frame.Height; toolbarView.Frame = ToolbarItemRectangle(offset, toolbarView); toolbarView.AutoresizingMask = IsHorizontal ? UIViewAutoresizing.FlexibleLeftMargin : UIViewAutoresizing.FlexibleTopMargin; AddSubview(toolbarView); _currentSecondaryViews.Add(toolbarView); offset -= _definition.ItemSpacing; } }
private void CreatePrimaryViews(ToolbarItemBase toolbar) { float offset = _definition.ItemSpacing; float width = 0; foreach (ToolbarItem item in toolbar.PrimaryItems) { UIView toolbarUiView = CreateToolbarView(item); toolbarUiView.Frame = ToolbarItemRectangle(offset, toolbarUiView); if (IsHorizontal) { UIViewAutoresizing resizeMask = UIViewAutoresizing.FlexibleRightMargin; switch (_definition.PrimaryItemAlignment) { case Definition.ToolbarAlignmentEnum.Middle: resizeMask = UIViewAutoresizing.FlexibleLeftMargin | UIViewAutoresizing.FlexibleRightMargin; break; case Definition.ToolbarAlignmentEnum.Right: resizeMask = UIViewAutoresizing.FlexibleLeftMargin; break; } toolbarUiView.AutoresizingMask = resizeMask; } AddSubview(toolbarUiView); _currentPrimaryViews.Add(toolbarUiView); offset += (IsHorizontal ? toolbarUiView.Frame.Width : toolbarUiView.Frame.Height) + _definition.ItemSpacing; width += toolbarUiView.Frame.Width + _definition.ItemSpacing; } width -= _definition.ItemSpacing; if (IsHorizontal && _definition.PrimaryItemAlignment == Definition.ToolbarAlignmentEnum.Middle) { offset = Bounds.Size.Width/2 - width/2; foreach (UIView view in _currentPrimaryViews) { RectangleF frame = view.Frame; frame.X = offset; view.Frame = frame; offset += frame.Width + _definition.ItemSpacing; } } }
private void AnimatePresentToolbar(ToolbarItemBase to, ToolbarItemBase from, Action<IToolbar> afterToolbarUpdateAction) { if (ToolbarWillAnimate != null) { ToolbarWillAnimate(new ToolbarAnimateEventArgs { From = from, To = to }); } List<UIView> oldLeftViews = new List<UIView>(_currentPrimaryViews); List<UIView> oldRightViews = new List<UIView>(_currentSecondaryViews); List<RectangleF> leftFrames = new List<RectangleF>(); List<RectangleF> rightFrames = new List<RectangleF>(); _currentPrimaryViews.Clear(); _currentSecondaryViews.Clear(); CreatePrimaryViews(to); CreateSecondaryViews(to); foreach (UIView view in _currentPrimaryViews) { RectangleF frame = view.Frame; leftFrames.Add(frame); if (IsHorizontal) { frame.X = -frame.Width; } else { frame.Y = -frame.Height; } view.Frame = frame; } foreach (UIView view in _currentSecondaryViews) { RectangleF frame = view.Frame; rightFrames.Add(frame); if (IsHorizontal) { frame.X = Bounds.Width; } else { frame.Y = Bounds.Height; } view.Frame = frame; } FluentAnimate.EaseIn(_definition.AnimationDuration, () => { foreach (UIView view in oldLeftViews) { RectangleF frame = view.Frame; if (IsHorizontal) { frame.X = -frame.Width; } else { frame.Y = -frame.Height; } view.Frame = frame; } foreach (UIView view in oldRightViews) { RectangleF frame = view.Frame; if (IsHorizontal) { frame.X = Bounds.Width; } else { frame.Y = Bounds.Height; } view.Frame = frame; } }).Then.Do( () => { if (ToolbarDidRemoveOldToolbar != null) { ToolbarDidRemoveOldToolbar(new ToolbarAnimateEventArgs { From = from, To = to }); } }).Then.EaseIn( () => { int index = 0; foreach (UIView view in _currentPrimaryViews) { view.Frame = leftFrames[index]; index++; } index = 0; foreach (UIView view in _currentSecondaryViews) { view.Frame = rightFrames[index]; index++; } }).WhenComplete( () => { foreach (UIView view in oldLeftViews) { view.RemoveFromSuperview(); } foreach (UIView view in oldRightViews) { view.RemoveFromSuperview(); } if (ToolbarDidAnimate != null) { ToolbarDidAnimate(new ToolbarAnimateEventArgs { From = from, To = to }); } if (afterToolbarUpdateAction != null) { afterToolbarUpdateAction(this); } }).Start(); }
internal void PushToolbar(ToolbarItemBase toolbar, bool animate, Action<IToolbar> afterToolbarUpdateAction) { if (!animate) { StaticPresentToolbar(toolbar, afterToolbarUpdateAction); } else { AnimatePresentToolbar(toolbar, _currentToolbar.Peek(), afterToolbarUpdateAction); } _currentToolbar.Push(toolbar); }