Skip to content

[Android] fix TapGestureRecognizer.Tapped called multiple times on Android#23183

Closed
mohsenbgi wants to merge 2 commits intodotnet:mainfrom
mohsenbgi:main
Closed

[Android] fix TapGestureRecognizer.Tapped called multiple times on Android#23183
mohsenbgi wants to merge 2 commits intodotnet:mainfrom
mohsenbgi:main

Conversation

@mohsenbgi
Copy link
Copy Markdown
Contributor

@mohsenbgi mohsenbgi commented Jun 21, 2024

Fixes: #23177

Description of Change

On an Android device, when a new GestureRecognizer is added to a view, the previous GestureRecognizers' Tapped event is raised multiple times by a single tap. I added a method named ClearPlatformViewEventHandlers to remove OnPlatformViewTouched from the Touch event when the GestureCollectionChanged method is called.

Added method:

void ClearPlatformViewEventHandlers()
{
	if (View == null)
		return;

	var platformView = Control;

	if (platformView == null)
		return;

	if (View.GestureRecognizers.Any(gestureRecognizer => gestureRecognizer is not PointerGestureRecognizer))
	{
		platformView.Touch -= OnPlatformViewTouched;
	}
}

Called in GestureCollectionChanged method:

void GestureCollectionChanged(object? sender, NotifyCollectionChangedEventArgs e)
{
	ClearPlatformViewEventHandlers();
	UpdateDragAndDrop();
	UpdatePointer();
	SetupGestures();

	if (_tapAndPanAndSwipeDetector.IsValueCreated)
		_tapAndPanAndSwipeDetector.Value.UpdateLongPressSettings();

	View?.AddOrRemoveControlsAccessibilityDelegate();
}

@mohsenbgi mohsenbgi requested a review from a team as a code owner June 21, 2024 15:47
@dotnet-policy-service dotnet-policy-service bot added the community ✨ Community Contribution label Jun 21, 2024
@mohsenbgi
Copy link
Copy Markdown
Contributor Author

mohsenbgi commented Jun 21, 2024 via email

@mohsenbgi mohsenbgi changed the title [Android] fix TapGestureRecognizer.Tapped fired multiple times on Android [Android] fix TapGestureRecognizer.Tapped called multiple times on Android Jun 25, 2024
@Redth
Copy link
Copy Markdown
Member

Redth commented Jun 25, 2024

/azp run

@azure-pipelines
Copy link
Copy Markdown

Azure Pipelines successfully started running 3 pipeline(s).

@azure-pipelines
Copy link
Copy Markdown

Commenter does not have sufficient privileges for PR 23183 in repo dotnet/maui

@Redth Redth closed this Jun 29, 2024
@Redth
Copy link
Copy Markdown
Member

Redth commented Jun 29, 2024

This was fixed in #23242

@github-actions github-actions bot locked and limited conversation to collaborators Jul 30, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

area-gestures Gesture types community ✨ Community Contribution

Projects

None yet

Development

Successfully merging this pull request may close these issues.

TapGestureRecognizer.Tapped fired multiple times on Android when GestureRecognizers were changed after rendering.

3 participants