mirror of
https://github.com/facebook/react-native.git
synced 2025-11-01 09:14:26 +00:00
Support setting hitSlop with single value
Summary: The native side supports this in https://github.com/facebook/react-native/blob/main/ReactCommon/react/renderer/graphics/conversions.h#L156 but it fails on the Java side. Changelog: [Android][Fixed] Enable hitSlop to be set using a single number. Reviewed By: yungsters Differential Revision: D32138347 fbshipit-source-id: 266ec061c6849d845b592cf245cc0599055b8522
This commit is contained in:
committed by
Facebook GitHub Bot
parent
00bb2ba62d
commit
a96bdb7154
@@ -13,6 +13,7 @@ import android.os.Build;
|
||||
import android.view.View;
|
||||
import androidx.annotation.NonNull;
|
||||
import androidx.annotation.Nullable;
|
||||
import com.facebook.react.bridge.Dynamic;
|
||||
import com.facebook.react.bridge.JSApplicationIllegalArgumentException;
|
||||
import com.facebook.react.bridge.ReactContext;
|
||||
import com.facebook.react.bridge.ReadableArray;
|
||||
@@ -126,22 +127,35 @@ public class ReactViewManager extends ReactClippingViewManager<ReactViewGroup> {
|
||||
}
|
||||
|
||||
@ReactProp(name = "hitSlop")
|
||||
public void setHitSlop(final ReactViewGroup view, @Nullable ReadableMap hitSlop) {
|
||||
if (hitSlop == null) {
|
||||
view.setHitSlopRect(null);
|
||||
} else {
|
||||
view.setHitSlopRect(
|
||||
new Rect(
|
||||
hitSlop.hasKey("left")
|
||||
? (int) PixelUtil.toPixelFromDIP(hitSlop.getDouble("left"))
|
||||
: 0,
|
||||
hitSlop.hasKey("top") ? (int) PixelUtil.toPixelFromDIP(hitSlop.getDouble("top")) : 0,
|
||||
hitSlop.hasKey("right")
|
||||
? (int) PixelUtil.toPixelFromDIP(hitSlop.getDouble("right"))
|
||||
: 0,
|
||||
hitSlop.hasKey("bottom")
|
||||
? (int) PixelUtil.toPixelFromDIP(hitSlop.getDouble("bottom"))
|
||||
: 0));
|
||||
public void setHitSlop(final ReactViewGroup view, Dynamic hitSlop) {
|
||||
switch (hitSlop.getType()) {
|
||||
case Null:
|
||||
view.setHitSlopRect(null);
|
||||
break;
|
||||
case Map:
|
||||
ReadableMap hitSlopMap = hitSlop.asMap();
|
||||
view.setHitSlopRect(
|
||||
new Rect(
|
||||
hitSlopMap.hasKey("left")
|
||||
? (int) PixelUtil.toPixelFromDIP(hitSlopMap.getDouble("left"))
|
||||
: 0,
|
||||
hitSlopMap.hasKey("top")
|
||||
? (int) PixelUtil.toPixelFromDIP(hitSlopMap.getDouble("top"))
|
||||
: 0,
|
||||
hitSlopMap.hasKey("right")
|
||||
? (int) PixelUtil.toPixelFromDIP(hitSlopMap.getDouble("right"))
|
||||
: 0,
|
||||
hitSlopMap.hasKey("bottom")
|
||||
? (int) PixelUtil.toPixelFromDIP(hitSlopMap.getDouble("bottom"))
|
||||
: 0));
|
||||
break;
|
||||
case Number:
|
||||
int hitSlopValue = (int) PixelUtil.toPixelFromDIP(hitSlop.asDouble());
|
||||
view.setHitSlopRect(new Rect(hitSlopValue, hitSlopValue, hitSlopValue, hitSlopValue));
|
||||
break;
|
||||
default:
|
||||
throw new JSApplicationIllegalArgumentException(
|
||||
"Invalid type for 'hitSlop' value " + hitSlop.getType());
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user