Add key action info to Android EventHandler events. (#25300)

Summary:
Add event key action for Android EventHandler events, helps to know if the key event is a up (key release, value is 1) or down (key pressed, value is 0) action.

## Changelog

[ANDROID] [ADDED] - Add event key action to EventHandler events.
Pull Request resolved: https://github.com/facebook/react-native/pull/25300

Test Plan: No test added

Differential Revision: D15897484

Pulled By: cpojer

fbshipit-source-id: fdb3d5413d9da3dd5f46d41e31ac60f0b341f3eb
This commit is contained in:
aamalric
2019-06-21 02:57:11 -07:00
committed by Facebook Github Bot
parent fc82c59be7
commit d010fc3bf4
@@ -58,8 +58,8 @@ public class ReactAndroidHWInputDeviceHelper {
public void handleKeyEvent(KeyEvent ev) {
int eventKeyCode = ev.getKeyCode();
int eventKeyAction = ev.getAction();
if (eventKeyAction == KeyEvent.ACTION_UP && KEY_EVENTS_ACTIONS.containsKey(eventKeyCode)) {
dispatchEvent(KEY_EVENTS_ACTIONS.get(eventKeyCode), mLastFocusedViewId);
if ((eventKeyAction == KeyEvent.ACTION_UP || eventKeyAction == KeyEvent.ACTION_DOWN) && KEY_EVENTS_ACTIONS.containsKey(eventKeyCode)) {
dispatchEvent(KEY_EVENTS_ACTIONS.get(eventKeyCode), mLastFocusedViewId, eventKeyAction);
}
}
@@ -88,8 +88,13 @@ public class ReactAndroidHWInputDeviceHelper {
}
private void dispatchEvent(String eventType, int targetViewId) {
dispatchEvent(eventType, targetViewId, -1);
}
private void dispatchEvent(String eventType, int targetViewId, int eventKeyAction) {
WritableMap event = new WritableNativeMap();
event.putString("eventType", eventType);
event.putInt("eventKeyAction", eventKeyAction);
if (targetViewId != View.NO_ID) {
event.putInt("tag", targetViewId);
}