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 @@ -30,6 +30,7 @@ open class GestureHandler {
private var trackedPointersIDsCount = 0
private val windowOffset = IntArray(2) { 0 }
var tag = 0
var testID: String? = null
var view: View? = null
private set

Expand Down Expand Up @@ -126,6 +127,7 @@ open class GestureHandler {
}

open fun resetConfig() {
testID = null
needsPointerData = DEFAULT_NEEDS_POINTER_DATA
manualActivation = DEFAULT_MANUAL_ACTIVATION
shouldCancelWhenOutside = DEFAULT_SHOULD_CANCEL_WHEN_OUTSIDE
Expand Down Expand Up @@ -844,7 +846,7 @@ open class GestureHandler {
open fun wantsToAttachDirectlyToView() = false

override fun toString(): String {
val viewString = if (view == null) null else view!!.javaClass.simpleName
val viewString = testID ?: view?.javaClass?.simpleName
return this.javaClass.simpleName + "@[" + tag + "]:" + viewString
}

Expand Down Expand Up @@ -896,6 +898,9 @@ open class GestureHandler {
if (config.hasKey(KEY_MOUSE_BUTTON)) {
handler.mouseButton = config.getInt(KEY_MOUSE_BUTTON)
}
if (config.hasKey(KEY_TEST_ID)) {
handler.testID = config.getString(KEY_TEST_ID)
}
}

abstract fun createEventBuilder(handler: T): GestureHandlerEventDataBuilder<T>
Expand All @@ -917,6 +922,7 @@ open class GestureHandler {
private const val KEY_HIT_SLOP_HORIZONTAL = "horizontal"
private const val KEY_HIT_SLOP_WIDTH = "width"
private const val KEY_HIT_SLOP_HEIGHT = "height"
private const val KEY_TEST_ID = "testID"

private fun handleHitSlopProperty(handler: GestureHandler, config: ReadableMap) {
if (config.getType(KEY_HIT_SLOP) == ReadableType.Number) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@
@property (nonatomic, weak, nullable) id<RNGestureHandlerEventEmitter> emitter;
@property (nonatomic, readonly, nullable) UIGestureRecognizer *recognizer;
@property (nonatomic, readonly, nullable) RNGestureHandlerPointerTracker *pointerTracker;
@property (nonatomic, nullable) NSString *testID;
@property (nonatomic) BOOL enabled;
@property (nonatomic) RNGestureHandlerActionType actionType;
@property (nonatomic) BOOL shouldCancelWhenOutside;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,7 @@ - (instancetype)initWithTag:(NSNumber *)tag
- (void)resetConfig
{
self.enabled = YES;
self.testID = nil;
self.manualActivation = NO;
_shouldCancelWhenOutside = NO;
_hitSlop = RNGHHitSlopEmpty;
Expand All @@ -125,6 +126,11 @@ - (void)updateConfig:(NSDictionary *)config
self.enabled = [RCTConvert BOOL:prop];
}

prop = config[@"testID"];
if (prop != nil) {
self.testID = [RCTConvert NSString:prop];
}

prop = config[@"shouldCancelWhenOutside"];
if (prop != nil) {
_shouldCancelWhenOutside = [RCTConvert BOOL:prop];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,11 @@ export const allowedNativeProps = new Set<
'needsPointerData',
]);

// Don't pass testID to the native side in production
if (!__DEV__) {
allowedNativeProps.delete('testID');
}

export const HandlerCallbacks = new Set<
keyof Required<GestureCallbacks<unknown>>
>([
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ export default abstract class GestureHandler implements IGestureHandler {
private forAnimated: boolean = false;
private forReanimated: boolean = false;
private _handlerTag!: number;
private _testID?: string = undefined;

private hitSlop?: HitSlop = undefined;
private manualActivation: boolean = false;
Expand Down Expand Up @@ -743,6 +744,10 @@ export default abstract class GestureHandler implements IGestureHandler {
this.validateHitSlops();
}

if (config.testID !== undefined) {
this._testID = config.testID;
}

if (config.dispatchesAnimatedEvents !== undefined) {
this.forAnimated = config.dispatchesAnimatedEvents;
}
Expand Down Expand Up @@ -936,6 +941,7 @@ export default abstract class GestureHandler implements IGestureHandler {
}

protected resetConfig(): void {
this._testID = undefined;
this.manualActivation = false;
this.shouldCancelWhenOutside = false;
this.mouseButton = undefined;
Expand Down Expand Up @@ -965,6 +971,10 @@ export default abstract class GestureHandler implements IGestureHandler {
this._handlerTag = value;
}

public get testID() {
return this._testID;
}

public get delegate() {
return this._delegate;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ export default interface IGestureHandler {
activationIndex: number;
awaiting: boolean;
handlerTag: number;
readonly testID?: string;
readonly delegate: GestureHandlerDelegate<unknown, this>;
readonly tracker: PointerTracker;
readonly name: SingleGestureName;
Expand Down
2 changes: 2 additions & 0 deletions packages/react-native-gesture-handler/src/web/interfaces.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ export interface Handler {
type ConfigArgs =
| number
| boolean
| string
| HitSlop
| UserSelect
| TouchAction
Expand All @@ -57,6 +58,7 @@ export interface Config extends Record<string, ConfigArgs> {
dispatchesAnimatedEvents?: false;
dispatchesReanimatedEvents?: boolean;
needsPointerData?: false;
testID?: string;

activateAfterLongPress?: number;
failOffsetXStart?: number;
Expand Down
Loading