Files
react-native/ReactAndroid/src/main/java/com/facebook/react/uimanager/OnLayoutEvent.java
T
Mike Lambert 4f5c2b48fe Fix timestamps on android touch events to use milliseconds, to be consistent with iOS
Summary:
So `PanReponder.onPanResponderRelease/onPanResponderTerminate` receive a `gestureState` object containing a `onPanResponderTerminate.vx/vy` property. On Android and iOS, they appear to be orders of magnitude different, which appear to be due to the different scale of timestamps that are used when generating touch events.

This pull request fixes the timestamps to be milliseconds on both platforms (since I assume iOS is the more authoritative one, and is the one that `react-native-viewpager`'s vx thresholds written written to compare against.)

As far as I can tell, the RN code doesn't use the `vx/vy` properties, so they should be okay. And looks like the RN code only cares about relative values of `startTimestamp/currentTimestamp/previousTimestamp` though, so should be fine too. it's quite possible there will be downstream android breakage with this change, particularly for those who are already compensating for the RN discrepancy.
Closes https://github.com/facebook/react-native/pull/8199

Differential Revision: D3528215

Pulled By: dmmiller

fbshipit-source-id: cbd25bb7e7bb87fa77b661a057643a6ea97bc3f1
2016-07-07 05:59:43 -07:00

75 lines
2.1 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.common.SystemClock;
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, SystemClock.elapsedRealtime());
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);
}
}