mirror of
https://github.com/facebook/react-native.git
synced 2025-11-01 09:14:26 +00:00
Support RCTModernEventEmitter+RCTEventEmitter in OnLayoutEvent Event class
Summary: Support RCTModernEventEmitter +RCTEventEmitter in an Event class(es). This improves perf in Fabric. Migrate any constructor callsites to the new constructor and deprecate the previous one. Changelog: [Internal] Reviewed By: mdvacca Differential Revision: D26054856 fbshipit-source-id: 228cc08a624e793aff4caf36e1df8285f3b3519d
This commit is contained in:
committed by
Facebook GitHub Bot
parent
5d2f77553c
commit
70073664ab
@@ -7,11 +7,11 @@
|
||||
|
||||
package com.facebook.react.uimanager;
|
||||
|
||||
import androidx.annotation.Nullable;
|
||||
import androidx.core.util.Pools;
|
||||
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;
|
||||
|
||||
/** Event used to notify JS component about changes of its position or dimensions */
|
||||
public class OnLayoutEvent extends Event<OnLayoutEvent> {
|
||||
@@ -21,12 +21,18 @@ public class OnLayoutEvent extends Event<OnLayoutEvent> {
|
||||
|
||||
private int mX, mY, mWidth, mHeight;
|
||||
|
||||
@Deprecated
|
||||
public static OnLayoutEvent obtain(int viewTag, int x, int y, int width, int height) {
|
||||
return obtain(-1, viewTag, x, y, width, height);
|
||||
}
|
||||
|
||||
public static OnLayoutEvent obtain(
|
||||
int surfaceId, int viewTag, int x, int y, int width, int height) {
|
||||
OnLayoutEvent event = EVENTS_POOL.acquire();
|
||||
if (event == null) {
|
||||
event = new OnLayoutEvent();
|
||||
}
|
||||
event.init(viewTag, x, y, width, height);
|
||||
event.init(surfaceId, viewTag, x, y, width, height);
|
||||
return event;
|
||||
}
|
||||
|
||||
@@ -37,8 +43,13 @@ public class OnLayoutEvent extends Event<OnLayoutEvent> {
|
||||
|
||||
private OnLayoutEvent() {}
|
||||
|
||||
@Deprecated
|
||||
protected void init(int viewTag, int x, int y, int width, int height) {
|
||||
super.init(viewTag);
|
||||
init(-1, viewTag, x, y, width, height);
|
||||
}
|
||||
|
||||
protected void init(int surfaceId, int viewTag, int x, int y, int width, int height) {
|
||||
super.init(surfaceId, viewTag);
|
||||
mX = x;
|
||||
mY = y;
|
||||
mWidth = width;
|
||||
@@ -50,8 +61,9 @@ public class OnLayoutEvent extends Event<OnLayoutEvent> {
|
||||
return "topLayout";
|
||||
}
|
||||
|
||||
@Nullable
|
||||
@Override
|
||||
public void dispatch(RCTEventEmitter rctEventEmitter) {
|
||||
protected WritableMap getEventData() {
|
||||
WritableMap layout = Arguments.createMap();
|
||||
layout.putDouble("x", PixelUtil.toDIPFromPixel(mX));
|
||||
layout.putDouble("y", PixelUtil.toDIPFromPixel(mY));
|
||||
@@ -61,7 +73,6 @@ public class OnLayoutEvent extends Event<OnLayoutEvent> {
|
||||
WritableMap event = Arguments.createMap();
|
||||
event.putMap("layout", layout);
|
||||
event.putInt("target", getViewTag());
|
||||
|
||||
rctEventEmitter.receiveEvent(getViewTag(), getEventName(), event);
|
||||
return event;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -958,6 +958,7 @@ public class UIImplementation {
|
||||
if (frameDidChange && cssNode.shouldNotifyOnLayout()) {
|
||||
mEventDispatcher.dispatchEvent(
|
||||
OnLayoutEvent.obtain(
|
||||
-1, /* surfaceId not used in classic renderer */
|
||||
tag,
|
||||
cssNode.getScreenX(),
|
||||
cssNode.getScreenY(),
|
||||
|
||||
@@ -118,7 +118,13 @@ public class UIViewOperationQueue {
|
||||
uiManager
|
||||
.getEventDispatcher()
|
||||
.dispatchEvent(
|
||||
OnLayoutEvent.obtain(mTag, mScreenX, mScreenY, mScreenWidth, mScreenHeight));
|
||||
OnLayoutEvent.obtain(
|
||||
-1 /* SurfaceId not used in classic renderer */,
|
||||
mTag,
|
||||
mScreenX,
|
||||
mScreenY,
|
||||
mScreenWidth,
|
||||
mScreenHeight));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user