Skip to content

Commit 69087cb

Browse files
committed
Pass moduleId to the button
1 parent ffb9a5f commit 69087cb

5 files changed

Lines changed: 14 additions & 0 deletions

File tree

packages/react-native-gesture-handler/android/src/main/java/com/swmansion/gesturehandler/react/RNGestureHandlerButtonViewManager.kt

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -152,6 +152,11 @@ class RNGestureHandlerButtonViewManager :
152152
view.hasLongPressHandler = hasLongPressHandler
153153
}
154154

155+
// No-op — only iOS needs the module id to resolve the handler manager, Android
156+
// gets the module from the view's context.
157+
@ReactProp(name = "moduleId")
158+
override fun setModuleId(view: ButtonViewGroup, moduleId: Int) = Unit
159+
155160
@ReactProp(name = "foreground")
156161
override fun setForeground(view: ButtonViewGroup, useDrawableOnForeground: Boolean) {
157162
view.useDrawableOnForeground = useDrawableOnForeground

packages/react-native-gesture-handler/apple/RNGestureHandlerButtonComponentView.mm

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ @interface RNGestureHandlerButtonComponentView () <RCTRNGestureHandlerButtonView
3535
@implementation RNGestureHandlerButtonComponentView {
3636
RNGestureHandlerButton *_buttonView;
3737
BOOL _needsAnimationStateReset;
38+
int _moduleId;
3839
}
3940

4041
#if TARGET_OS_OSX
@@ -59,6 +60,7 @@ - (instancetype)initWithFrame:(CGRect)frame
5960
if (self = [super initWithFrame:frame]) {
6061
static const auto defaultProps = std::make_shared<const RNGestureHandlerButtonProps>();
6162
_props = defaultProps;
63+
_moduleId = -1;
6264
_buttonView = [[RNGestureHandlerButton alloc] initWithFrame:self.bounds];
6365
_buttonView.animationTarget = self;
6466

@@ -367,6 +369,7 @@ - (void)updateProps:(const Props::Shared &)props oldProps:(const Props::Shared &
367369
oldButtonProps.defaultUnderlayOpacity != newProps.defaultUnderlayOpacity;
368370
}
369371

372+
_moduleId = newProps.moduleId;
370373
_buttonView.userEnabled = newProps.enabled;
371374
_buttonView.tapAnimationInDuration = newProps.tapAnimationInDuration > 0 ? newProps.tapAnimationInDuration : 0;
372375
_buttonView.tapAnimationOutDuration = newProps.tapAnimationOutDuration > 0 ? newProps.tapAnimationOutDuration : 0;

packages/react-native-gesture-handler/src/components/GestureHandlerButton.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ export interface ButtonProps extends ViewProps, AccessibilityProps {
2222
enabled?: boolean | undefined;
2323

2424
hasLongPressHandler?: boolean | undefined;
25+
moduleId?: number | undefined;
2526
handlerTag?: number | undefined;
2627
cancelOnLeave?: boolean | undefined;
2728
gestureTestID?: string | undefined;

packages/react-native-gesture-handler/src/specs/RNGestureHandlerButtonNativeComponent.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,10 @@ interface NativeProps extends ViewProps {
2727
| undefined;
2828

2929
hasLongPressHandler?: CodegenTypes.WithDefault<boolean, false>;
30+
// Used on iOS to resolve the gesture handler module instance managing the
31+
// handler created for `handlerTag`. Android resolves the module from the
32+
// view's context instead.
33+
moduleId?: CodegenTypes.WithDefault<CodegenTypes.Int32, -1>;
3034
handlerTag?: CodegenTypes.Double | undefined;
3135
cancelOnLeave?: CodegenTypes.WithDefault<boolean, true>;
3236
gestureTestID?: string;

packages/react-native-gesture-handler/src/v3/components/Touchable/Touchable.android.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -179,6 +179,7 @@ export const Touchable = (props: TouchableProps) => {
179179
{...resolvedDurations}
180180
ref={ref ?? null}
181181
enabled={!disabled}
182+
moduleId={globalThis._RNGH_MODULE_ID}
182183
handlerTag={handlerTag}
183184
cancelOnLeave={cancelOnLeave}
184185
gestureTestID={props.testID}

0 commit comments

Comments
 (0)