Cannot capture keydown event in a modal

Đang mở
#77 0 bình luận 0 reaction 0 người được giao Xem trên GitHub

Chưa có ai nhận issue này.

Đánh giá

Độ khó
4/5
Thời gian dự kiến
3-5 ngày
Mức phù hợp với người mới
35/100
Loại issue
Lỗi
Độ rõ ràng
Khá rõ ràng
Mức độ hoạt động
Đình trệ
Công nghệ
android, angular, typescript
Lĩnh vực
mobile-dev

Hướng nghiên cứu

Bắt đầu với triển khai dispatchKeyEvent mở rộng trong activity.android.ts và tái hiện sự cố với một modal không toàn màn hình có chứa dropdown. So sánh cách xử lý phím trong modal với trường hợp component hoạt động đúng và xác minh rằng các sự kiện phím mũi tên có thể được bắt và ghi log mà không làm hỏng thao tác điều hướng của dropdown.

Do mô hình lập chỉ mục viết ra từ nội dung của issue.

Mô tả

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.

Ngôn ngữ chính
TypeScript
Star
55
Fork
13
Merge trung bình
16 phút
Pull request đã merge (30 ngày)
1

Hướng dẫn đóng góp

Mở hướng dẫn đóng góp

Bắt đầu từ đâu

  1. Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
  2. Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
  3. Fork repository và làm thay đổi trên một nhánh.
  4. Mở pull request có tham chiếu số hiệu của issue.

Issue khác của NativeScript/angular

Tất cả issue của NativeScript/angular

Issue tương tự

Thêm issue về TypeScript

Nhận issue mới trong hộp thư của bạn

Bản tóm tắt ngắn những issue GitHub phù hợp với người mới.