NativeScript / NativeScript/angular
Cannot capture keydown event in a modal
Dieses Issue hat noch niemand übernommen.
- Vorherrschende Sprache
- TypeScript
- Sterne
- 55
- Forks
- 13
- Ø Merge
- 16 Min.
- Gemergte PRs (30 T.)
- 1
Beschreibung
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: 14
- Cross-platform modules:
- Android Runtime: 8.2
- iOS Runtime:
- Plugin(s):
- NativeScript-Angular: 13
- Angular: 13.2
Describe the bug
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.
Sample project
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.
Beitragsleitfaden
Erste Schritte
- Lies das ganze Issue und danach den Beitragsleitfaden des Projekts.
- Schreib ins Issue, dass du es übernimmst — das erspart doppelte Arbeit.
- Forke das Repository und arbeite in einem Branch.
- Öffne einen Pull Request, der die Issue-Nummer nennt.
Rechercherichtung
Beginne mit der erweiterten activity.android.ts-Implementierung von dispatchKeyEvent und reproduziere das Problem mit einem nicht bildschirmfüllenden Modal, das das Dropdown enthält. Vergleiche die Tastenbehandlung im Modal mit dem funktionierenden Komponentenfall und überprüfe, dass Pfeiltastenereignisse erfasst und protokolliert werden können, ohne die Dropdown-Navigation zu beeinträchtigen.
Vom Indexierungsmodell aus dem Issue-Text verfasst.
Bewertung
- Tech-Stack
- android, angular, typescript
- Bereich
- mobile-dev
- Issue-Typ
- Bug
- Schwierigkeit
- 4/5
- Geschätzter Aufwand
- 3-5 Tage
- Aktivitätsstatus
- Veraltet
- Klarheit
- Größtenteils klar
- Anfängerfreundlichkeit
- 35/100