Skip to content

Commit dbd2ced

Browse files
L00rdDDavidLinhares-DVspydon
authored
fix: Fix incorrect handling of unhandled MotionEvent axes on android (#74)
This PR fixes an issue in the Android gamepads plugin where certain MotionEvent axes could be incorrectly reported as handled even when no value change occurred. Context: - I am using a wheel controller on a GCS-type drone controller. - Before this fix, when using axes that were not recognized by the library, the plugin still returned `handled=true`, which made it impossible to choose between using Gamepads or a custom library for the same input. - The current workaround required modifying MainActivity.kt to call both Gamepads and a custom input handler, which caused duplicate events. Changes: - onMotionEvent now returns `false` if no supported axis has been processed. - Ensures unhandled axes can be caught by custom logic, preventing duplicate values when integrating with other input systems. Impact: - Existing joysticks and gamepads continue to work as before. - Provides more accurate and flexible event handling for apps consuming gamepad input. --------- Co-authored-by: David Linhares <[email protected]> Co-authored-by: Lukas Klingsbo <[email protected]>
1 parent f3c0335 commit dbd2ced

File tree

1 file changed

+6
-3
lines changed
  • packages/gamepads_android/android/src/main/kotlin/org/flame_engine/gamepads_android

1 file changed

+6
-3
lines changed

packages/gamepads_android/android/src/main/kotlin/org/flame_engine/gamepads_android/EventListener.kt

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -44,10 +44,13 @@ class EventListener {
4444
}
4545

4646
fun onMotionEvent(motionEvent: MotionEvent, channel: MethodChannel): Boolean {
47-
supportedAxes.forEach {
48-
reportAxis(motionEvent, channel, it)
47+
var handled = false
48+
supportedAxes.forEach { axis ->
49+
val axisHandled = reportAxis(motionEvent, channel, axis)
50+
if (axisHandled) handled = true
4951
}
50-
return true
52+
53+
return handled
5154
}
5255

5356
private fun reportAxis(

0 commit comments

Comments
 (0)