Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,9 @@ public void setProperty(T view, String propName, @Nullable Object value) {
case "borderStyle":
mViewManager.setBorderStyle(view, value == null ? "solid" : (String) value);
break;
case "pointerEvents":
mViewManager.setPointerEvents(view, (String) value);
break;
default:
super.setProperty(view, propName, value);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,4 +24,5 @@ public interface RNGestureHandlerButtonManagerInterface<T extends View> extends
void setBorderWidth(T view, float value);
void setBorderColor(T view, @Nullable Integer value);
void setBorderStyle(T view, @Nullable String value);
void setPointerEvents(T view, @Nullable String value);
}
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@ import androidx.core.view.children
import com.facebook.react.R
import com.facebook.react.module.annotations.ReactModule
import com.facebook.react.uimanager.PixelUtil
import com.facebook.react.uimanager.PointerEvents
import com.facebook.react.uimanager.ReactPointerEventsView
import com.facebook.react.uimanager.ThemedReactContext
import com.facebook.react.uimanager.ViewGroupManager
import com.facebook.react.uimanager.ViewManagerDelegate
Expand Down Expand Up @@ -132,6 +134,17 @@ class RNGestureHandlerButtonViewManager :
view.isSoundEffectsEnabled = !touchSoundDisabled
}

@ReactProp(name = ViewProps.POINTER_EVENTS)
override fun setPointerEvents(view: ButtonViewGroup, pointerEvents: String?) {
view.pointerEvents = when (pointerEvents) {
"none" -> PointerEvents.NONE
"box-none" -> PointerEvents.BOX_NONE
"box-only" -> PointerEvents.BOX_ONLY
"auto", null -> PointerEvents.AUTO
else -> PointerEvents.AUTO
}
}

override fun onAfterUpdateTransaction(view: ButtonViewGroup) {
super.onAfterUpdateTransaction(view)

Expand All @@ -142,7 +155,8 @@ class RNGestureHandlerButtonViewManager :

class ButtonViewGroup(context: Context?) :
ViewGroup(context),
NativeViewGestureHandler.NativeViewGestureHandlerHook {
NativeViewGestureHandler.NativeViewGestureHandlerHook,
ReactPointerEventsView {
// Using object because of handling null representing no value set.
var rippleColor: Int? = null
set(color) = withBackgroundUpdate {
Expand Down Expand Up @@ -200,6 +214,8 @@ class RNGestureHandlerButtonViewManager :

var exclusive = true

override var pointerEvents: PointerEvents = PointerEvents.AUTO

private var buttonBackgroundColor = Color.TRANSPARENT
private var needBackgroundUpdate = false
private var lastEventTime = -1L
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -223,12 +223,14 @@ - (void)updateProps:(const Props::Shared &)props oldProps:(const Props::Shared &
_buttonView.hitTestEdgeInsets = UIEdgeInsetsMake(
-newProps.hitSlop.top, -newProps.hitSlop.left, -newProps.hitSlop.bottom, -newProps.hitSlop.right);

const auto &newViewProps = static_cast<const ViewProps &>(newProps);
if (!oldProps) {
_buttonView.pointerEvents = RCTPointerEventsToEnum(newProps.pointerEvents);
_buttonView.pointerEvents = RCTPointerEventsToEnum(newViewProps.pointerEvents);
} else {
const auto &oldButtonProps = *std::static_pointer_cast<const RNGestureHandlerButtonProps>(oldProps);
if (oldButtonProps.pointerEvents != newProps.pointerEvents) {
_buttonView.pointerEvents = RCTPointerEventsToEnum(newProps.pointerEvents);
const auto &oldViewProps = static_cast<const ViewProps &>(oldButtonProps);
if (oldViewProps.pointerEvents != newViewProps.pointerEvents) {
_buttonView.pointerEvents = RCTPointerEventsToEnum(newViewProps.pointerEvents);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import type {
} from 'react-native/Libraries/Types/CodegenTypes';
import type { ViewProps, ColorValue } from 'react-native';

// @ts-ignore - Redefining pointerEvents with WithDefault for codegen, conflicts with ViewProps type but codegen needs it
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Omit is not working with codegen so I had to ignore the error

If anyone has a better idea, don't hesitate 👍

interface NativeProps extends ViewProps {
exclusive?: WithDefault<boolean, true>;
foreground?: boolean;
Expand All @@ -17,6 +18,10 @@ interface NativeProps extends ViewProps {
borderWidth?: Float;
borderColor?: ColorValue;
borderStyle?: WithDefault<string, 'solid'>;
pointerEvents?: WithDefault<
'box-none' | 'none' | 'box-only' | 'auto',
'auto'
>;
}

export default codegenNativeComponent<NativeProps>('RNGestureHandlerButton');
Loading