public OptionImageButton(double contentHeight) { _icon = new SvgCachedImage() { Source = ImageSource, VerticalOptions = LayoutOptions.Fill, HorizontalOptions = LayoutOptions.Fill, Aspect = Aspect.AspectFit }; _lbl = new Label() { HorizontalOptions = LayoutOptions.Center, VerticalOptions = LayoutOptions.Start, HorizontalTextAlignment = TextAlignment.Center, VerticalTextAlignment = TextAlignment.Start, Text = Text, TextColor = TextColor, FontSize = Sizes.TextSmall - 1, }; Content = new Grid() { HorizontalOptions = LayoutOptions.Center, VerticalOptions = LayoutOptions.Center, RowSpacing = 4, HeightRequest = contentHeight, RowDefinitions = new RowDefinitionCollection() { new RowDefinition() { Height = GridLength.Star }, new RowDefinition() { Height = GridLength.Auto }, }, Children = { { _icon, 0, 0 }, { _lbl, 0, 1 }, } }; this.AddTouch(async(sender, args) => { Command?.Execute(this); await _icon.ScaleTo(0.85, 100u, Easing.SpringOut); await _icon.ScaleTo(1, 150u, Easing.SpringOut); Tapped?.Invoke(this, null); }); }
public HeartIconView() { // add larger touch-area Margin = new Thickness(-10); Padding = new Thickness(10); _icon = new SvgCachedImage() { HeightRequest = 25, WidthRequest = 25, Aspect = Aspect.AspectFit, Source = IsActive ? Images.FavoriteFill : Images.Favorite, FadeAnimationEnabled = true, FadeAnimationForCachedImages = true, FadeAnimationDuration = 150, }; Content = new Grid() { Children = { _icon, } }; this.AddTouch(async(sender, args) => { if (_isAnimating) { return; } _isAnimating = true; if (!IsActive) { IsActive = true; await _icon.ScaleTo(.7f, 100u, Easing.SinInOut); await _icon.ScaleTo(1f, 150u, Easing.SpringOut); } else { IsActive = false; await _icon.ScaleTo(.7f, 100u, Easing.SinOut); await _icon.ScaleTo(1f, 150u, Easing.SpringOut); _isAnimating = false; } ClickedCommand?.Execute(null); }); }