Skip to content

Commit f5b4656

Browse files
committed
Merge branch '@mbert/docs-badges' into @mbert/docs-badges-versions
2 parents fbdd4d6 + 549b6a7 commit f5b4656

17 files changed

Lines changed: 258 additions & 175 deletions

packages/docs-gesture-handler/docs/gestures/use-pan-gesture.mdx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -221,7 +221,7 @@ averageTouches: boolean | SharedValue<boolean>;
221221

222222
Android, by default, will calculate translation values based on the position of the leading pointer (the first one that was placed on the screen). This modifier allows that behavior to be changed to the one that is default on iOS - the averaged position of all active pointers will be used to calculate the translation values.
223223

224-
<HeaderWithBadges platforms={['iOS']}>
224+
<HeaderWithBadges platforms={['iOS', 'web']}>
225225
### enableTrackpadTwoFingerGesture
226226
</HeaderWithBadges>
227227

packages/docs-gesture-handler/src/components/HeaderWithBadges/index.tsx

Lines changed: 32 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -5,19 +5,27 @@ import styles from './styles.module.css';
55
import clsx from 'clsx';
66

77
type HeaderWithBadgesProps = {
8-
platforms?: ('android' | 'iOS' | 'web')[];
8+
platforms: string[];
99
version?: string;
1010
children?: React.ReactNode;
1111
};
1212

13+
type Platform = 'android' | 'ios' | 'web';
14+
1315
type PlatformBadgeProps = {
14-
platform: 'android' | 'iOS' | 'web';
16+
platform: Platform;
1517
};
1618

1719
type VersionBadgeProps = {
1820
version: string;
1921
};
2022

23+
const platformNameMap: Record<Platform, string> = {
24+
android: 'Android',
25+
ios: 'iOS',
26+
web: 'Web',
27+
};
28+
2129
export function VersionBadge({ version }: VersionBadgeProps) {
2230
const { colorMode } = useColorMode();
2331
const isDark = colorMode === 'dark';
@@ -35,16 +43,27 @@ export function VersionBadge({ version }: VersionBadgeProps) {
3543
}
3644

3745
export function PlatformBadge({ platform }: PlatformBadgeProps) {
38-
const platformBadge =
39-
platform === 'android'
40-
? styles.androidBadge
41-
: platform === 'iOS'
42-
? styles.iosBadge
43-
: platform === 'web'
44-
? styles.webBadge
45-
: {};
46+
let platformBadgeStyle;
47+
48+
switch (platform) {
49+
case 'android':
50+
platformBadgeStyle = styles.androidBadge;
51+
break;
52+
case 'ios':
53+
platformBadgeStyle = styles.iosBadge;
54+
break;
55+
case 'web':
56+
platformBadgeStyle = styles.webBadge;
57+
break;
58+
default:
59+
platformBadgeStyle = {};
60+
}
4661

47-
return <div className={clsx(styles.badge, platformBadge)}>{platform}</div>;
62+
return (
63+
<div className={clsx(styles.badge, platformBadgeStyle)}>
64+
{platformNameMap[platform]}
65+
</div>
66+
);
4867
}
4968

5069
export default function HeaderWithBadges({
@@ -57,7 +76,8 @@ export default function HeaderWithBadges({
5776
{children}
5877

5978
{platforms
60-
?.sort()
79+
?.map((platform) => platform.toLowerCase() as Platform)
80+
.sort()
6181
.map((platform) => (
6282
<PlatformBadge key={platform} platform={platform} />
6383
))}

packages/docs-gesture-handler/src/components/HeaderWithBadges/styles.module.css

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
}
1616

1717
.androidBadge {
18-
background-color: #0f8142;
18+
background-color: #34a853;
1919
}
2020

2121
.iosBadge {

packages/react-native-gesture-handler/apple/RNGestureHandler.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,7 @@
8585
@property (nonatomic) BOOL dispatchesReanimatedEvents;
8686
@property (nonatomic, weak, nullable) RNGHUIView *hostDetectorView;
8787
@property (nonatomic, nullable, assign) NSNumber *virtualViewTag;
88+
@property (nonatomic, copy, nullable) NSNumber *viewTag;
8889

8990
- (BOOL)isViewParagraphComponent:(nullable RNGHUIView *)view;
9091
- (nonnull RNGHUIView *)chooseViewForInteraction:(nonnull UIGestureRecognizer *)recognizer;

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

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -262,6 +262,8 @@ - (void)bindToView:(RNGHUIView *)view
262262

263263
[recognizerView addGestureRecognizer:self.recognizer];
264264
[self bindManualActivationToView:recognizerView];
265+
266+
self.viewTag = view.reactTag;
265267
}
266268

267269
- (void)unbindFromView
@@ -271,6 +273,7 @@ - (void)unbindFromView
271273

272274
self.hostDetectorView = nil;
273275
self.virtualViewTag = nil;
276+
self.viewTag = nil;
274277

275278
[self unbindManualActivation];
276279
}

packages/react-native-gesture-handler/apple/RNGestureHandlerManager.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,4 +42,6 @@
4242
- (nullable RNGestureHandler *)handlerWithTag:(nonnull NSNumber *)handlerTag;
4343

4444
- (nullable RNGHUIView *)viewForReactTag:(nonnull NSNumber *)reactTag;
45+
46+
- (void)reattachHandlersIfNeeded;
4547
@end

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

Lines changed: 40 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -171,6 +171,21 @@ - (void)attachGestureHandler:(nonnull NSNumber *)handlerTag
171171
}
172172

173173
[_attachRetryCounter removeObjectForKey:viewTag];
174+
[self maybeBindHandler:handlerTag toViewWithTag:viewTag withActionType:actionType withHostDetector:hostDetector];
175+
}
176+
177+
// Resolves a view tag to its native UIView (including contentView unwrapping),
178+
// sets reactTag, and binds the gesture handler to it. No-op if the handler is
179+
// already attached to the correct view.
180+
- (void)maybeBindHandler:(nonnull NSNumber *)handlerTag
181+
toViewWithTag:(nonnull NSNumber *)viewTag
182+
withActionType:(RNGestureHandlerActionType)actionType
183+
withHostDetector:(nullable RNGHUIView *)hostDetector
184+
{
185+
RNGHUIView *view = [_viewRegistry viewForReactTag:viewTag];
186+
if (view == nil || view.superview == nil) {
187+
return;
188+
}
174189

175190
// I think it should be moved to RNNativeViewHandler, but that would require
176191
// additional logic for setting contentView.reactTag, this works for now
@@ -181,12 +196,17 @@ - (void)attachGestureHandler:(nonnull NSNumber *)handlerTag
181196
}
182197
}
183198

199+
RNGestureHandler *handler = [_registry handlerWithTag:handlerTag];
200+
201+
// Already attached to the correct native view, nothing to do.
202+
if (handler != nil && handler.recognizer.view == view && handler.actionType == actionType) {
203+
return;
204+
}
205+
184206
view.reactTag = viewTag; // necessary for RNReanimated eventHash (e.g. "42onGestureHandlerEvent"), also will be
185207
// returned as event.target
186208

187209
[_registry attachHandlerWithTag:handlerTag toView:view withActionType:actionType withHostDetector:hostDetector];
188-
189-
// register view if not already there
190210
[self registerViewWithGestureRecognizerAttachedIfNeeded:view];
191211
}
192212

@@ -224,6 +244,24 @@ - (id)handlerWithTag:(NSNumber *)handlerTag
224244
return [_registry handlerWithTag:handlerTag];
225245
}
226246

247+
- (void)reattachHandlersIfNeeded
248+
{
249+
// Re-bind handlers to their current native views. On Fabric, when a parent view has
250+
// display:none and siblings change, the native UIView backing a component may be recycled
251+
// and replaced. maybeBindHandler is a no-op if the view is nil or unchanged. This is only
252+
// needed for handlers using the old api.
253+
for (RNGestureHandler *handler in _registry.handlers.objectEnumerator) {
254+
if (handler.viewTag == nil || [handler usesNativeOrVirtualDetector]) {
255+
continue;
256+
}
257+
258+
[self maybeBindHandler:handler.tag
259+
toViewWithTag:handler.viewTag
260+
withActionType:handler.actionType
261+
withHostDetector:nil];
262+
}
263+
}
264+
227265
#pragma mark Root Views Management
228266

229267
- (void)registerViewWithGestureRecognizerAttachedIfNeeded:(RNGHUIView *)childView

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

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -171,18 +171,21 @@ - (void)flushOperations
171171
{
172172
// On the new arch we rely on `flushOperations` for scheduling the operations on the UI thread.
173173
// On the old arch we rely on `uiManagerWillPerformMounting`
174-
if (_operations.count == 0) {
175-
return;
176-
}
177-
178174
RNGestureHandlerManager *manager = [RNGestureHandlerModule handlerManagerForModuleId:_moduleId];
179-
NSArray<GestureHandlerOperation> *operations = _operations;
180-
_operations = [NSMutableArray new];
175+
176+
if (_operations.count > 0) {
177+
NSArray<GestureHandlerOperation> *operations = _operations;
178+
_operations = [NSMutableArray new];
179+
180+
[self.viewRegistry_DEPRECATED addUIBlock:^(RCTViewRegistry *viewRegistry) {
181+
for (GestureHandlerOperation operation in operations) {
182+
operation(manager);
183+
}
184+
}];
185+
}
181186

182187
[self.viewRegistry_DEPRECATED addUIBlock:^(RCTViewRegistry *viewRegistry) {
183-
for (GestureHandlerOperation operation in operations) {
184-
operation(manager);
185-
}
188+
[manager reattachHandlersIfNeeded];
186189
}];
187190
}
188191

packages/react-native-gesture-handler/apple/RNGestureHandlerRegistry.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,4 +21,6 @@
2121
- (void)dropHandlerWithTag:(nonnull NSNumber *)handlerTag;
2222
- (void)dropAllHandlers;
2323

24+
@property (nonatomic, readonly, nonnull) NSDictionary<NSNumber *, RNGestureHandler *> *handlers;
25+
2426
@end

packages/react-native-gesture-handler/apple/RNGestureHandlerRegistry.m

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,11 @@ - (instancetype)init
2222
return self;
2323
}
2424

25+
- (NSDictionary<NSNumber *, RNGestureHandler *> *)handlers
26+
{
27+
return _handlers;
28+
}
29+
2530
- (RNGestureHandler *)handlerWithTag:(NSNumber *)handlerTag
2631
{
2732
return _handlers[handlerTag];

0 commit comments

Comments
 (0)