dotnet / maui

.NET MAUI is the .NET Multi-platform App UI, a framework for building native device applications spanning mobile, tablet, and desktop.
https://dot.net/maui
MIT License
22.16k stars 1.74k forks source link

Inconsistent HapticFeedback on iOS #25284

Open AncientLust opened 1 week ago

AncientLust commented 1 week ago

Description

The issue is with HapticFeedback.Default.Perform. On iOS it works or not depending on what code follows this line. Sometimes with some chance. For example:

  1. In this case haptic feedback works in 90% of the cases when button is pressed:
[RelayCommand]
private void Play()
{
    HapticFeedback.Default.Perform(HapticFeedbackType.Click);
    _currentState.Play();
}
  1. In this case haptic feedback works in 100% of the cases when button is pressed:
[RelayCommand]
private void Play()
{
    HapticFeedback.Default.Perform(HapticFeedbackType.Click);
    // _currentState.Play();
}

The situation getting worse when you try to use haptic feedback in a more complex situation, like this:

private async Task HandleIncorrectAnswer()
{
    await Task.Delay(100);
    HapticFeedback.Default.Perform(HapticFeedbackType.Click);
    await Task.Delay(100);
    HapticFeedback.Default.Perform(HapticFeedbackType.Click);
}

In this case it just can have zero vibrations, vibrate only once or vibrate twice as you expect.

Let us keep this bug report for a while just to see if people have the same issues with haptic feedback. Because googling of "MAUI inconsistent haptic feedback" returns nothing.

What I tried:

  1. Run HapticFeedback.Default.Perform from main thread via MainThread.BeginInvokeOnMainThread / InvokeOnMainThreadAsync.
  2. Run HapticFeedback.Default.Perform via "run and forget" using Task.Run().

Don't see this issue on Android. On iOS both Click and LongPress have this problematic behavior.

Steps to Reproduce

Wasn't able to reproduce in the clean MAUI project, since behaviour depends on the code which follows haptic feedback usage. Without it it works fine. I will update the bug report if I will find a way to reproduce it.

Link to public reproduction project repository

No response

Version with bug

8.0.40 SR5

Is this a regression from previous behavior?

Not sure, did not test other versions

Last version that worked well

Unknown/Other

Affected platforms

iOS

Affected platform versions

iOS 17.6.1

Did you find any workaround?

So far the only workaround I found is to place await Task.Delay() afterwards with at least 100 ms to make the vibration stable.

Relevant log output

No response

dotnet-policy-service[bot] commented 4 days ago

Hi @AncientLust. We have added the "s/needs-repro" label to this issue, which indicates that we require steps and sample code to reproduce the issue before we can take further action. Please try to create a minimal sample project/solution or code samples which reproduce the issue, ideally as a GitHub repo that we can clone. See more details about creating repros here: https://github.com/dotnet/maui/blob/main/.github/repro.md

This issue will be closed automatically in 7 days if we do not hear back from you by then - please feel free to re-open it if you come back to this issue after that time.