Open jessiezh0320 opened 4 years ago
Hey @jessiezh0320 thanks for the report! I can't seem to detect which platform you are talking about. Is this iOS, Android, UWP? As far as I can recall none of these have a "click" sound, so I'm curious to find out what this is about. Thanks!
Hi @jfversluis this concerns Android platform. Here is a sample project with old Xamarin.Forms Version 3.4.0.1008975 where we can hear the click default sound https://github.com/leocdi/ButtonSoundFeedback.git
I have just tried this project on a recent device (Galaxy S10) and I don't hear a clicking sound out of the box. However, I can enable the sound by going into the settings of the phone and enabling it under touch interactions (might be named differently in other Android versions).
When I then upgrade to 4.5 stable, even with the OS setting on, the touch feedback is no longer there. I think this is something that is dropped with the Material design, but I can't find any source to back that up.
@jfversluis Yes, this problem does exist on the Android platform. I hope you can help solve this problem.Thanks.
I was going through the ButtonRenderer on Android for a different reason, but found this: https://github.com/xamarin/Xamarin.Forms/blob/master/Xamarin.Forms.Platform.Android/FastRenderers/ButtonRenderer.cs#L310
~That might be some hint as to why it is not working. Now to find out why that was added..~ Looks like it has been in there from the start.
@jessiezh0320 could you do me a favor and try to enable the legacy renderers (see the doc) and see if that brings back the sound?
@jfversluis Just tested, Enabling legacy renderer Brind Back the sound.
OK so, what I found is that on a VisualElement level the SoundEffectsEnabled
is set to false here: https://github.com/xamarin/Xamarin.Forms/blob/master/Xamarin.Forms.Platform.Android/VisualElementRenderer.cs#L238
On a Button, but only for the fast renderer, this is repeated here: https://github.com/xamarin/Xamarin.Forms/blob/master/Xamarin.Forms.Platform.Android/FastRenderers/ButtonRenderer.cs#L312
However! For the Button
the sound is indeed disabled, but for other controls the sound is still enabled nonetheless. Interestingly enough, as seen above, for the legacy renderers the sound can be heard as well.
The main question is: why are we setting the SoundEffectsEnabled
to false. Or at least trying to. The way this works on Android is that the user can set the feedback sounds on/off on OS level. If they're off, they will never hear any of it. If they enabled them, you as the developer can override it for an element by setting the SoundEffectsEnabled
to false.
I would say; let's just remove the hard setting SoundEffectsEnabled
to false and introduce a PlatformSpecific to set it on any VisualElement
. Users can then decide for themselves.
Totally agree with @jfversluis here. The click sound is so important as user feedback sometimes that it should be free to the developer when to enable or disable it.
Comparing a native and xamarin.forms app the first thing i always notice is that there is no click sound feedback on a button.
If the user does not want any click sounds, he can just disable it in the system.
I worked around it using this renderer
public class ButtonFeedbackRenderer : ButtonRenderer { public ButtonFeedbackRenderer(Context context) : base(context) { }
protected override void OnElementChanged(ElementChangedEventArgs<Button> e)
{
base.OnElementChanged(e);
Control.SoundEffectsEnabled = true;
}
}
Description
The default click sound on button press is lost after updating xamarin forms nuget to the newer version(e.g. 4.3.0.908675).
But in older version, the default click sound on button press still exists.(e.g.Xamarin forms nuget 3.6.0.293080)
Steps to Reproduce
Create a new xamari forms demo and add a button in xaml;
<Button Text="test" VerticalOptions="Center" HorizontalOptions="Center" Clicked="Button_Clicked"/>
Then add event
Click
for the Button;private void Button_Clicked(object sender, EventArgs e) { }
Put on headphone and run the app , click the button, and pay attention to the sound when clicking the Button.
Expected Behavior
The default click sound on button press is not lost after updating xamarin forms nuget.
remains the same as the old version
Actual Behavior
The default click sound on button press is lost after updating xamarin forms nuget.
Basic Information