mirror of
https://github.com/zhigang1992/react-native.git
synced 2026-04-07 22:40:55 +08:00
Implement touch intercepting in RCTView
Summary: @public React allows excluding certain elements from touch handling by assigning `PointerEvents` filter to them, such as BOX_NONE - this element will not receive touch but its children will, BOX_ONLY - only this element will receive pointer event and not children, NONE - neither this element nor its children will receive pointer events, and AUTO - pointer events are allowed for both this element and its children. This diff adds PointerEvents support to flat RCTView. Most of the implementation is copied from ReactViewManager/ReactViewGroup. One small change is made to TouchTargetHelper to ensure that it works correctly with virtual nodes when their parent has PointerEvents set to PointerEvents.BOX_NONE. Reviewed By: ahmedre Differential Revision: D2784208
This commit is contained in:
committed by
Ahmed El-Helw
parent
ff77456f26
commit
d23f86e47b
@@ -20,6 +20,7 @@ import com.facebook.react.bridge.ReadableArray;
|
||||
import com.facebook.react.bridge.ReadableMap;
|
||||
import com.facebook.react.common.MapBuilder;
|
||||
import com.facebook.react.uimanager.PixelUtil;
|
||||
import com.facebook.react.uimanager.PointerEvents;
|
||||
import com.facebook.react.uimanager.ReactProp;
|
||||
import com.facebook.react.uimanager.ViewProps;
|
||||
import com.facebook.react.views.view.ReactDrawableHelper;
|
||||
@@ -95,4 +96,26 @@ import com.facebook.react.views.view.ReactDrawableHelper;
|
||||
boolean needsOffscreenAlphaCompositing) {
|
||||
view.setNeedsOffscreenAlphaCompositing(needsOffscreenAlphaCompositing);
|
||||
}
|
||||
|
||||
@ReactProp(name = "pointerEvents")
|
||||
public void setPointerEvents(FlatViewGroup view, @Nullable String pointerEventsStr) {
|
||||
view.setPointerEvents(parsePointerEvents(pointerEventsStr));
|
||||
}
|
||||
|
||||
private static PointerEvents parsePointerEvents(@Nullable String pointerEventsStr) {
|
||||
if (pointerEventsStr != null) {
|
||||
switch (pointerEventsStr) {
|
||||
case "none":
|
||||
return PointerEvents.NONE;
|
||||
case "auto":
|
||||
return PointerEvents.AUTO;
|
||||
case "box-none":
|
||||
return PointerEvents.BOX_NONE;
|
||||
case "box-only":
|
||||
return PointerEvents.BOX_ONLY;
|
||||
}
|
||||
}
|
||||
// default or invalid
|
||||
return PointerEvents.AUTO;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user