NativeScript / NativeScript/angular

Cannot capture keydown event in a modal

未關閉
#77 0 則留言 0 個 reaction 已指派 0 人 在 GitHub 檢視

還沒有人認領這個 Issue。

主要語言
TypeScript
星號
55
分支
13
平均合併
16 分鐘
30 天內合併 PR
1

描述

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.

貢獻指南

開啟貢獻指南

從這裡開始

  1. 先讀完整個 Issue,再讀專案的貢獻指南。
  2. 在 Issue 下留言說明你要接手 —— 這能避免兩個人做同樣的事。
  3. Fork 儲存庫,在一個分支上完成修改。
  4. 送出 Pull Request,並在描述裡引用這個 Issue 編號。

研究方向

從擴充後的 activity.android.ts dispatchKeyEvent 實作開始,使用包含 dropdown 的非全螢幕 modal 重現問題。比較 modal 中的按鍵處理與正常運作的元件案例,並確認可以擷取及記錄方向鍵事件,同時不會破壞 dropdown 導覽。

由索引模型根據 Issue 內容生成。

評估

技術堆疊
android, angular, typescript
領域
mobile-dev
Issue 類型
缺陷
難度
4/5
預估耗時
3-5 天
活躍度
停滯
描述清晰度
基本清楚
新手友好度
35/100

把新 issue 寄到你的電子郵件信箱

精選適合新手參與的 GitHub issue 摘要。