mirror of
https://github.com/zoriya/react-native-svg.git
synced 2026-06-01 06:07:41 +00:00
feat: introduce hitSlop prop (#2407)
# Summary Explain the **motivation** for making this change: here are some points to help you: * What issues does the pull request solve? Please tag them so that they will get automatically closed once the PR is merged * What is the feature? (if applicable) * How did you implement the solution? * What areas of the library does it impact? ## Test Plan Demonstrate the code is solid. Example: The exact commands you ran and their output, screenshots / videos if the pull request changes UI. ### What's required for testing (prerequisites)? ### What are the steps to reproduce (after prerequisites)? ## Compatibility | OS | Implemented | | ------- | :---------: | | iOS | ✅ | | MacOS | ✅❌ | | Android | ✅ | | Web | ✅❌ |
This commit is contained in:
@@ -10,8 +10,10 @@ package com.horcrux.svg;
|
||||
|
||||
import android.graphics.Rect;
|
||||
import android.util.SparseArray;
|
||||
import com.facebook.common.logging.FLog;
|
||||
import com.facebook.react.bridge.Dynamic;
|
||||
import com.facebook.react.bridge.ReadableMap;
|
||||
import com.facebook.react.common.ReactConstants;
|
||||
import com.facebook.react.uimanager.PixelUtil;
|
||||
import com.facebook.react.uimanager.PointerEvents;
|
||||
import com.facebook.react.uimanager.ThemedReactContext;
|
||||
@@ -285,24 +287,37 @@ class SvgViewManager extends ReactViewManager
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setHitSlop(SvgView view, @Nullable ReadableMap hitSlopMap) {
|
||||
public void setHitSlop(SvgView view, Dynamic hitSlop) {
|
||||
// we don't call super here since its signature changed in RN 0.69 and we want backwards
|
||||
// compatibility
|
||||
if (hitSlopMap != null) {
|
||||
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));
|
||||
switch (hitSlop.getType()) {
|
||||
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:
|
||||
FLog.w(ReactConstants.TAG, "Invalid type for 'hitSlop' value " + hitSlop.getType());
|
||||
/* falls through */
|
||||
case Null:
|
||||
view.setHitSlopRect(null);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
+1
-1
@@ -127,7 +127,7 @@ public class RNSVGSvgViewAndroidManagerDelegate<T extends View, U extends BaseVi
|
||||
mViewManager.setNeedsOffscreenAlphaCompositing(view, value == null ? false : (boolean) value);
|
||||
break;
|
||||
case "hitSlop":
|
||||
mViewManager.setHitSlop(view, (ReadableMap) value);
|
||||
mViewManager.setHitSlop(view, new DynamicFromObject(value));
|
||||
break;
|
||||
case "borderTopColor":
|
||||
mViewManager.setBorderTopColor(view, ColorPropConverter.getColor(value, view.getContext()));
|
||||
|
||||
+1
-1
@@ -49,7 +49,7 @@ public interface RNSVGSvgViewAndroidManagerInterface<T extends View> {
|
||||
void setBackfaceVisibility(T view, @Nullable String value);
|
||||
void setBorderStyle(T view, @Nullable String value);
|
||||
void setNeedsOffscreenAlphaCompositing(T view, boolean value);
|
||||
void setHitSlop(T view, @Nullable ReadableMap value);
|
||||
void setHitSlop(T view, Dynamic value);
|
||||
void setBorderTopColor(T view, @Nullable Integer value);
|
||||
void setNextFocusLeft(T view, int value);
|
||||
void setBorderTopRightRadius(T view, double value);
|
||||
|
||||
Reference in New Issue
Block a user