Skip to content

Adding this package disables default navigation behavior on Android.Β #61

@DRFR33MAN24

Description

@DRFR33MAN24

HI, I started using this package in my project because I couldn't find anyway to list game-pads apart from writing a custom native logic and relying on platform channels, my app runs on TVs and make use of dpad to handle navigation, I followed the documentation and provided overrides as follows:

    override fun dispatchGenericMotionEvent(motionEvent: MotionEvent): Boolean {
        return motionListener?.invoke(motionEvent) ?: false
    }
    
    override fun dispatchKeyEvent(keyEvent: KeyEvent): Boolean {
        return keyListener?.invoke(keyEvent) ?: false
    }

    override fun registerInputDeviceListener(
      listener: InputManager.InputDeviceListener, handler: Handler?) {
        val inputManager = getSystemService(INPUT_SERVICE) as InputManager
        inputManager.registerInputDeviceListener(listener, null)
    }

    override fun registerKeyEventHandler(handler: (KeyEvent) -> Boolean) {
        keyListener = handler
    }

    override fun registerMotionEventHandler(handler: (MotionEvent) -> Boolean) {
        motionListener = handler
    }  

however it seems that keyListener?.invoke(keyEvent) always returns true, which means the event is consumed AFIK.

this disables navigating the app screens with gamepad, dpad, and keyboard, I tried to call the parent event listener first and also force the methods to return false always, but that missed with gamepads logic.

currently I'm only relying on gamepads package in one page only where I'm listening to keys and changing gamepads mappings, the mapping is saved and then sent to the backend.

How to use gamepads package without affecting default android way of handling input from keyboards, dpad , gamepads, or how to handle consuming events manually?

Another problem I'm running into is "How to get a unique ID per gamepad, currently when calling Gamepads.list() the only non changing quality is 'name' but multiple gamepads might have the same name already, how to expose vendor id?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions