mirror of
https://github.com/facebook/react-native.git
synced 2025-11-01 09:14:26 +00:00
da063e3d55
Summary: This is pure cleanup so that we can make sure that all events are living in the same time space (currently nano seconds). Reviewed By: foghina Differential Revision: D3593884 fbshipit-source-id: 71b084362008f1c93c21880630acf11f5c058355
74 lines
2.0 KiB
Java
74 lines
2.0 KiB
Java
/**
|
|
* Copyright (c) 2015-present, Facebook, Inc.
|
|
* All rights reserved.
|
|
*
|
|
* This source code is licensed under the BSD-style license found in the
|
|
* LICENSE file in the root directory of this source tree. An additional grant
|
|
* of patent rights can be found in the PATENTS file in the same directory.
|
|
*/
|
|
|
|
package com.facebook.react.uimanager;
|
|
|
|
import android.support.v4.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> {
|
|
|
|
private static final Pools.SynchronizedPool<OnLayoutEvent> EVENTS_POOL =
|
|
new Pools.SynchronizedPool<>(20);
|
|
|
|
private int mX, mY, mWidth, mHeight;
|
|
|
|
public static OnLayoutEvent obtain(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);
|
|
return event;
|
|
}
|
|
|
|
@Override
|
|
public void onDispose() {
|
|
EVENTS_POOL.release(this);
|
|
}
|
|
|
|
private OnLayoutEvent() {
|
|
}
|
|
|
|
protected void init(int viewTag, int x, int y, int width, int height) {
|
|
super.init(viewTag);
|
|
mX = x;
|
|
mY = y;
|
|
mWidth = width;
|
|
mHeight = height;
|
|
}
|
|
|
|
@Override
|
|
public String getEventName() {
|
|
return "topLayout";
|
|
}
|
|
|
|
@Override
|
|
public void dispatch(RCTEventEmitter rctEventEmitter) {
|
|
WritableMap layout = Arguments.createMap();
|
|
layout.putDouble("x", PixelUtil.toDIPFromPixel(mX));
|
|
layout.putDouble("y", PixelUtil.toDIPFromPixel(mY));
|
|
layout.putDouble("width", PixelUtil.toDIPFromPixel(mWidth));
|
|
layout.putDouble("height", PixelUtil.toDIPFromPixel(mHeight));
|
|
|
|
WritableMap event = Arguments.createMap();
|
|
event.putMap("layout", layout);
|
|
event.putInt("target", getViewTag());
|
|
|
|
rctEventEmitter.receiveEvent(getViewTag(), getEventName(), event);
|
|
}
|
|
}
|