Skip to content
This repository has been archived by the owner on May 1, 2024. It is now read-only.

[Bug] TranslateTo not working repeatedly #13346

Open
eli191 opened this issue Jan 8, 2021 · 3 comments
Open

[Bug] TranslateTo not working repeatedly #13346

eli191 opened this issue Jan 8, 2021 · 3 comments
Labels
a/animation 🎬 Animation stuff e/5 🕔 5 i/high Completely doesn't work, crashes, or is unusably slow, has no obvious workaround; occurs less often p/Android p/iOS 🍎 t/bug 🐛
Milestone

Comments

@eli191
Copy link

eli191 commented Jan 8, 2021

Description

Move a view on user touch

Steps to Reproduce

  1. Create a new Xamarin.Forms app with version 5.0.0.1874
  2. Add Skiasharp.Views.Forms.2.80.2 package
  3. Replace MainPage.xaml with below code
<?xml version="1.0" encoding="utf-8" ?>
<ContentPage
    xmlns="http://xamarin.com/schemas/2014/forms"
    xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
    xmlns:forms="clr-namespace:SkiaSharp.Views.Forms;assembly=SkiaSharp.Views.Forms"
    x:Class="TranslateTo.MainPage">

    <Grid
        x:Name="container"
        HorizontalOptions="FillAndExpand"
        VerticalOptions="FillAndExpand">
        <Frame
            x:Name="movingView"
            BackgroundColor="Blue"
            WidthRequest="50"
            HeightRequest="50"
            VerticalOptions="Start"
            HorizontalOptions="Start">
        </Frame>
        <forms:SKCanvasView
            HorizontalOptions="FillAndExpand"
            VerticalOptions="FillAndExpand"
            PaintSurface="OnPaintSurface"
            EnableTouchEvents="True"
            Touch="OnTouchAction" />
    </Grid>

</ContentPage>
  1. Replace MainPage.xaml.cs with below code
public partial class MainPage : ContentPage
    {
        private void OnPaintSurface(object sender, SKPaintSurfaceEventArgs e)
        {
            SKImageInfo info = e.Info;
            viewportHeight = info.Height;
            viewportWidth = info.Width;
        }

        public async void OnTouchAction(object sender, SKTouchEventArgs e)
        {
            e.Handled = true;
            switch (e.ActionType)
            {
                case SKTouchAction.Pressed:
                    await movingView.ScaleTo(0.5, 0);
                    break;
                case SKTouchAction.Moved:
                    var location = e.Location;
                    var x = location.X * container.Width / viewportWidth;
                    var y = location.Y * container.Height / viewportHeight;
                    Console.WriteLine($"X={x}/{container.Width} Y={x}/{container.Height}");
                    await movingView.TranslateTo(x, y, 0);
                    break;
                case SKTouchAction.Released:
                    await movingView.TranslateTo(0, 0, 0);
                    await movingView.ScaleTo(1, 0);
                    break;
            }
        }

        private int viewportHeight;
        private int viewportWidth;

        public MainPage()
        {
            InitializeComponent();
        }
    }

Expected Behavior

View moves

Actual Behavior

View doesn't move (iOS)
App crashes (Android)

Basic Information

  • Version with issue:
  • Last known good version: ?
  • Platform Target Frameworks:
    • iOS:
    • Android:
    • UWP:
  • Android Support Library / AndroidX Version:
  • NuGet Packages:
  • Affected Devices:

Environment

Show/Hide Visual Studio info

Build Logs

Screenshots

Reproduction Link

https://github.com/eli191/translateto

Workaround

@eli191 eli191 added s/unverified New report that has yet to be verified t/bug 🐛 labels Jan 8, 2021
@themronion
Copy link

@eli191 I have a feeling there is a division by zero somewhere. Put a breakpoint before this line:

var x = location.X * container.Width / viewportWidth;

and see if viewportWidth is equal to 0

@hartez
Copy link
Contributor

hartez commented Jan 9, 2021

It's not a division by zero in this code, though something like that might be happening in the TranslateTo method in Forms.

@eli191 I tried changing the length parameter of TranslateTo from zero to 1 millisecond and that seems to prevent the crash. So if you need a workaround while we investigate this, you might give that a try.

@hartez hartez added p/Android p/iOS 🍎 a/animation 🎬 Animation stuff e/5 🕔 5 and removed s/unverified New report that has yet to be verified labels Jan 9, 2021
@hartez hartez added the i/high Completely doesn't work, crashes, or is unusably slow, has no obvious workaround; occurs less often label Jan 9, 2021
@hartez hartez added this to the 5.0.1 milestone Jan 9, 2021
@eli191
Copy link
Author

eli191 commented Jan 10, 2021

Hi @hartez

You are a genius! effectively, putting 1 millisecond instead of 0 does the job very well!!
I am very happy with that workaround for now as it was blocking.

Thank you!

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
a/animation 🎬 Animation stuff e/5 🕔 5 i/high Completely doesn't work, crashes, or is unusably slow, has no obvious workaround; occurs less often p/Android p/iOS 🍎 t/bug 🐛
Projects
None yet
Development

No branches or pull requests

3 participants