private async Task OnTappedTabButton(TabItemPage page) { if (page.Content == null) { page.Clicked?.Execute(null); } else { await ShowPage(page.Index); SelectedPageChanged?.Execute(page); await TabAnimation(page); } }
private async Task TabAnimation(TabItemPage page) { if (HasUnderline) { var prevunderline = this.Children.FirstOrDefault(x => x.AutomationId == "underlineitem"); //Adding underline on item BoxView underline = new BoxView() { AutomationId = "underlineitem", HeightRequest = 1, StyleId = page.Index.ToString(), Color = TitleActiveTextColor, WidthRequest = 70, Opacity = 0, HorizontalOptions = LayoutOptions.Center, VerticalOptions = LayoutOptions.EndAndExpand }; //remove previous underline and animate it async Task <bool> AnimatePrev() { if (prevunderline != null) { int spaces = (int.Parse(underline.StyleId) - int.Parse(prevunderline.StyleId)) * 100; await prevunderline.TranslateTo(spaces, 0, 200, Easing.SinOut); return(this.Children.Remove(prevunderline)); } else { return(await Task.FromResult(true)); } }; //add a new underline and animate it async Task <bool> AnimateAddUnderline() { this.Children.Add(underline, page.Index, 1); return(await underline.FadeTo(100, 1000, Easing.SinIn)); }; //runs the two actions at the same time await Task.WhenAny <bool> ( AnimatePrev(), AnimateAddUnderline() ); } //highligth tab button title var tabs = this.Children.Where(tb => tb.StyleId != null && tb.StyleId.Contains("tabbutton")).ToList(); //foreach (StackLayout tb in tabs) foreach (CustomFrame tb in tabs) { var buttonarea = tb.Content as StackLayout; var title = buttonarea.Children.FirstOrDefault(lbl => lbl is Label) as Label; if (tb.StyleId == $"tabbutton{page.Index}") { title.TextColor = TitleActiveTextColor; if (page.IconActiveName.Contains("svg")) { var icon = buttonarea.Children.FirstOrDefault(ico => ico is SvgCachedImage) as SvgCachedImage; var xfSource = _imageSourceConverter.ConvertFromInvariantString(page.IconActiveName) as ImageSource; icon.Source = new SvgImageSource(xfSource, 0, 0, true); } else { var icon = buttonarea.Children.FirstOrDefault(ico => ico is CachedImage) as CachedImage; icon.Source = ImageSource.FromFile(page.IconActiveName); } tb.StartColor = StartActiveBackgroundColor; tb.EndColor = EndActiveBackgroundColor; } else { title.TextColor = TitleTextColor; var iconnormal = Pages.FirstOrDefault(ico => ico.Index == int.Parse(tb.StyleId.Replace("tabbutton", string.Empty))); if (iconnormal.IconName.Contains("svg")) { var icon = buttonarea.Children.FirstOrDefault(ico => ico is SvgCachedImage) as SvgCachedImage; var xfSource = _imageSourceConverter.ConvertFromInvariantString(iconnormal.IconName) as ImageSource; icon.Source = new SvgImageSource(xfSource, 0, 0, true); } else { var icon = buttonarea.Children.FirstOrDefault(ico => ico is CachedImage) as CachedImage; icon.Source = ImageSource.FromFile(iconnormal.IconName); } tb.StartColor = StartBackgroundColor; tb.EndColor = EndBackgroundColor; } } }