/*
 * Copyright (c) Facebook, Inc. and its affiliates.
 *
 * This source code is licensed under the MIT license found in the
 * LICENSE file in the root directory of this source tree.
 */

package com.facebook.react.views.textinput;

import com.facebook.react.bridge.Arguments;
import com.facebook.react.bridge.WritableMap;
import com.facebook.react.uimanager.events.Event;
import com.facebook.react.uimanager.events.RCTEventEmitter;
import com.facebook.react.uimanager.events.RCTModernEventEmitter;

/** Event emitted by EditText native view when key pressed */
public class ReactTextInputKeyPressEvent extends Event<ReactTextInputEvent> {

  public static final String EVENT_NAME = "topKeyPress";

  private String mKey;

  @Deprecated
  ReactTextInputKeyPressEvent(int viewId, final String key) {
    this(-1, viewId, key);
  }

  ReactTextInputKeyPressEvent(int surfaceId, int viewId, final String key) {
    super(surfaceId, viewId);
    mKey = key;
  }

  @Override
  public String getEventName() {
    return EVENT_NAME;
  }

  @Override
  public boolean canCoalesce() {
    // We don't want to miss any textinput event, as event data is incremental.
    return false;
  }

  @Override
  public void dispatch(RCTEventEmitter rctEventEmitter) {
    rctEventEmitter.receiveEvent(getViewTag(), getEventName(), serializeEventData());
  }

  @Override
  public void dispatchModern(RCTModernEventEmitter rctEventEmitter) {
    rctEventEmitter.receiveEvent(
        getSurfaceId(), getViewTag(), getEventName(), serializeEventData());
  }

  private WritableMap serializeEventData() {
    WritableMap eventData = Arguments.createMap();
    eventData.putString("key", mKey);

    return eventData;
  }
}

@@ -227,16 +227,53 @@
 input;%0A%0A
+import androidx.annotation.Nullable;%0A
 import c
@@ -407,134 +407,8 @@
 ent;
-%0Aimport com.facebook.react.uimanager.events.RCTEventEmitter;%0Aimport com.facebook.react.uimanager.events.RCTModernEventEmitter;
 %0A%0A/*
@@ -944,304 +944,179 @@
 %0A  @
-Override%0A  public boolean canCoalesce() %7B%0A    // We don't want to miss any textinput event, as
+Nullable%0A  @Override%0A  protected WritableMap getEventData() %7B%0A    WritableMap
  event
- d
+D
 ata 
-is incremental.%0A    return false;%0A  %7D%0A%0A  @Override%0A  public void dispatch(RCTEventEmitter rctEventEmitter) %7B%0A    rctEventEmitter.receiveEvent(getViewTag(), getEventName(), serializeE
+= Arguments.createMap();%0A    eventData.putString(%22key%22, mKey);%0A    return e
 ventData
 ());
@@ -1103,35 +1103,32 @@
 return eventData
-())
 ;%0A  %7D%0A%0A  @Overri
@@ -1143,319 +1143,111 @@
 lic 
-void dispatchModern(RCTModernEventEmitter rctEventEmitter) %7B%0A    rctEventEmitter.receiveEvent(%0A        getSurfaceId(), getViewTag(), getEventName(), serializeEventData());%0A  %7D%0A%0A  private WritableMap serializeEventData() %7B%0A    WritableMap
+boolean canCoalesce() %7B%0A    // We don't want to miss any textinput event, as
  event
-D
+ d
 ata 
-= Arguments.createMap();%0A    eventData.putString(%22key%22, mKey);%0A
+is incremental.
 %0A   
@@ -1250,29 +1250,25 @@
 %0A    return 
-eventData
+false
 ;%0A  %7D%0A%7D%0A

Support RCTModernEventEmitter+RCTEventEmitter in ReactTextInputKeyPressEvent Event class