NativeScript / NativeScript/angular

Cannot capture keypressed event in modal on Android

Abierto
#71 0 comentarios 0 reacciones 0 asignados Ver en GitHub

Nadie ha tomado este issue todavía.

Lenguaje dominante
TypeScript
Estrellas
55
Forks
13
Merge medio
16 min
PR fusionados (30 d)
1

Descripción

Environment
Provide version numbers for the following components (information can be retrieved by running tns info in your project folder or by inspecting the package.json of the project):

  • CLI: 8.2.0
  • Cross-platform modules:
  • Android Runtime: 6.3.1
  • iOS Runtime: N/A
  • Plugin(s):
  • NativeScript-Angular: 8.2.1
  • Angular: 8.2.0

Describe the bug
Same as title, I am unable to capture the keydown event in a modal dialog.

The key press is coming from a hardware keyboard, not the onscreen one.

I can accomplish this in any other component using:

application.on('KEYCODE_DPAD_DOWN', (() => {
	console.log('Keyboard Down Arrow Pressed');
}));

And it works fine.

This is after extending activity.android.ts, and adding:

public dispatchKeyEvent(event) {
    let keyCode = event.getKeyCode();

    switch (keyCode) {
        case android.view.KeyEvent.KEYCODE_DPAD_LEFT:
        case android.view.KeyEvent.KEYCODE_DPAD_UP:
            application.notify({
                eventName: 'KEYCODE_DPAD_UP',
            })
            return true;
        case android.view.KeyEvent.KEYCODE_DPAD_RIGHT:
        case android.view.KeyEvent.KEYCODE_DPAD_DOWN:
            application.notify({
                eventName: 'KEYCODE_DPAD_DOWN',
            })
            return true;
        default:
            return super.dispatchKeyEvent(event);
    }
}

I have tried every manner of capturing the keypress in a modal that I could, none work.

To Reproduce
Extend android activity to capture a keypress, try to capture a keypress in a non-fullscreen modal.

Expected behavior
Should be able to capture the keypress and console log it, similar to how it is in a component.

Additional context
In my modal, I have a dropdown. If I open the dropdown and then press the up/down arrow keys, it navigates through the selections, so the buttons work in the modal, I just don't know how to capture and console log them.

Please let me know if additional info is required.

Guía de contribución

Abrir la guía de contribución

Primeros pasos

  1. Lee el issue completo y luego la guía de contribución del proyecto.
  2. Comenta en el issue que vas a ocuparte — evita que dos personas hagan lo mismo.
  3. Haz un fork del repositorio y trabaja en una rama.
  4. Abre un pull request que haga referencia al número del issue.

Línea de trabajo

Comienza con la activity.android.ts extendida y el modal que no ocupa toda la pantalla descrito en los pasos de reproducción. Sigue cómo se comportan dispatchKeyEvent y las notificaciones de la aplicación cuando el modal y su menú desplegable están abiertos, y luego verifica que los eventos de las teclas de flecha del hardware se puedan capturar y registrar en el modal.

Escrito por el modelo de indexación a partir del texto del issue.

Evaluación

Stack tecnológico
android, angular, typescript
Área
mobile
Tipo de issue
Error
Dificultad
4/5
Tiempo estimado
3-5 días
Estado de actividad
Estancado
Claridad
Necesita aclaración
Aptitud para principiantes
25/100

Recibe los nuevos issues en tu correo

Un resumen breve de issues de GitHub para principiantes.