Skip to content

Commit 16eb6cb

Browse files
committed
Merge branch 'next' into @mbert/docs-detector
2 parents 4f8e6dc + d548122 commit 16eb6cb

19 files changed

Lines changed: 601 additions & 204 deletions

File tree

packages/react-native-gesture-handler/shared/shadowNodes/react/renderer/components/rngesturehandler_codegen/RNGestureHandlerDetectorShadowNode.cpp

Lines changed: 18 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -34,23 +34,34 @@ void RNGestureHandlerDetectorShadowNode::initialize() {
3434
}
3535

3636
void RNGestureHandlerDetectorShadowNode::layout(LayoutContext layoutContext) {
37-
YogaLayoutableShadowNode::layout(layoutContext);
3837
// TODO: consider allowing more than one child and doing bounding box
3938
react_native_assert(getChildren().size() == 1);
4039

41-
if (!this->yogaNode_.getHasNewLayout()) {
42-
return;
43-
}
44-
4540
auto child = std::static_pointer_cast<const YogaLayoutableShadowNode>(
4641
getChildren()[0]);
42+
auto childWithProtectedAccess =
43+
std::static_pointer_cast<const RNGestureHandlerDetectorShadowNode>(child);
44+
45+
auto shouldSkipCustomLayout =
46+
!childWithProtectedAccess->yogaNode_.getHasNewLayout();
47+
48+
// Do default layout after reading the new layout flag from the child.
49+
// Default layout will reset the flag on the child nodes.
50+
YogaLayoutableShadowNode::layout(layoutContext);
51+
52+
// The child node did not have its layout changed, we can reuse previous
53+
// values
54+
if (shouldSkipCustomLayout) {
55+
react_native_assert(previousLayoutMetrics_.has_value());
56+
setLayoutMetrics(previousLayoutMetrics_.value());
57+
return;
58+
}
4759

4860
child->ensureUnsealed();
4961
auto mutableChild = std::const_pointer_cast<YogaLayoutableShadowNode>(child);
5062

51-
// TODO: figure out the correct way to setup metrics between detector and
52-
// the child
5363
auto metrics = child->getLayoutMetrics();
64+
metrics.frame = child->getLayoutMetrics().frame;
5465
setLayoutMetrics(metrics);
5566

5667
auto childmetrics = child->getLayoutMetrics();

packages/react-native-gesture-handler/shared/shadowNodes/react/renderer/components/rngesturehandler_codegen/RNGestureHandlerDetectorShadowNode.h

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,13 +45,20 @@ class RNGestureHandlerDetectorShadowNode final
4545
const ShadowNode &sourceShadowNode,
4646
const ShadowNodeFragment &fragment)
4747
: ConcreteViewShadowNode(sourceShadowNode, fragment) {
48+
const auto &sourceDetectorNode =
49+
static_cast<const RNGestureHandlerDetectorShadowNode &>(
50+
sourceShadowNode);
51+
previousLayoutMetrics_ = sourceDetectorNode.getLayoutMetrics();
52+
4853
initialize();
4954
}
5055

5156
void layout(LayoutContext layoutContext) override;
5257

5358
private:
5459
void initialize();
60+
61+
std::optional<LayoutMetrics> previousLayoutMetrics_;
5562
};
5663

5764
} // namespace facebook::react

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,8 @@ import { GestureObjects as Gesture } from '../../handlers/gestures/gestureObject
99
import { GestureDetector } from '../../handlers/gestures/GestureDetector';
1010
import {
1111
PressableEvent,
12-
PressableProps,
1312
PressableDimensions,
13+
LegacyPressableProps,
1414
} from './PressableProps';
1515
import {
1616
Insets,
@@ -40,7 +40,7 @@ import { PressableStateMachine } from './StateMachine';
4040
const DEFAULT_LONG_PRESS_DURATION = 500;
4141
const IS_TEST_ENV = isTestEnv();
4242

43-
const Pressable = (props: PressableProps) => {
43+
const Pressable = (props: LegacyPressableProps) => {
4444
const {
4545
testOnly_pressed,
4646
hitSlop,

packages/react-native-gesture-handler/src/components/Pressable/PressableProps.tsx

Lines changed: 42 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import {
99
View,
1010
} from 'react-native';
1111
import { RelationPropType } from '../utils';
12+
import { AnyGesture } from '../../v3/types';
1213

1314
export type PressableDimensions = { width: number; height: number };
1415

@@ -30,7 +31,47 @@ export type InnerPressableEvent = {
3031

3132
export type PressableEvent = { nativeEvent: InnerPressableEvent };
3233

33-
export interface PressableProps
34+
export interface LegacyPressableProps extends CommonPressableProps {
35+
/**
36+
* A gesture object or an array of gesture objects containing the configuration and callbacks to be
37+
* used with the Pressable's gesture handlers.
38+
*/
39+
simultaneousWithExternalGesture?: RelationPropType;
40+
41+
/**
42+
* A gesture object or an array of gesture objects containing the configuration and callbacks to be
43+
* used with the Pressable's gesture handlers.
44+
*/
45+
requireExternalGestureToFail?: RelationPropType;
46+
47+
/**
48+
* A gesture object or an array of gesture objects containing the configuration and callbacks to be
49+
* used with the Pressable's gesture handlers.
50+
*/
51+
blocksExternalGesture?: RelationPropType;
52+
}
53+
54+
export interface PressableProps extends CommonPressableProps {
55+
/**
56+
* A gesture object or an array of gesture objects containing the configuration and callbacks to be
57+
* used with the Pressable's gesture handlers.
58+
*/
59+
simultaneousWith?: AnyGesture;
60+
61+
/**
62+
* A gesture object or an array of gesture objects containing the configuration and callbacks to be
63+
* used with the Pressable's gesture handlers.
64+
*/
65+
requireToFail?: AnyGesture;
66+
67+
/**
68+
* A gesture object or an array of gesture objects containing the configuration and callbacks to be
69+
* used with the Pressable's gesture handlers.
70+
*/
71+
block?: AnyGesture;
72+
}
73+
74+
interface CommonPressableProps
3475
extends AccessibilityProps,
3576
Omit<ViewProps, 'children' | 'style' | 'hitSlop'> {
3677
/**
@@ -149,24 +190,6 @@ export interface PressableProps
149190
*/
150191
unstable_pressDelay?: number;
151192

152-
/**
153-
* A gesture object or an array of gesture objects containing the configuration and callbacks to be
154-
* used with the Pressable's gesture handlers.
155-
*/
156-
simultaneousWithExternalGesture?: RelationPropType;
157-
158-
/**
159-
* A gesture object or an array of gesture objects containing the configuration and callbacks to be
160-
* used with the Pressable's gesture handlers.
161-
*/
162-
requireExternalGestureToFail?: RelationPropType;
163-
164-
/**
165-
* A gesture object or an array of gesture objects containing the configuration and callbacks to be
166-
* used with the Pressable's gesture handlers.
167-
*/
168-
blocksExternalGesture?: RelationPropType;
169-
170193
/**
171194
* @deprecated This property is no longer used, and will be removed in the future.
172195
*/

packages/react-native-gesture-handler/src/components/Pressable/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
export type {
2+
LegacyPressableProps,
23
PressableProps,
34
PressableStateCallbackType,
45
} from './PressableProps';

packages/react-native-gesture-handler/src/components/Pressable/utils.ts

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ import {
1313
InnerPressableEvent,
1414
PressableEvent,
1515
} from './PressableProps';
16+
import { HoverGestureEvent, LongPressGestureEvent } from '../../v3';
1617

1718
const numberAsInset = (value: number): Insets => ({
1819
left: value,
@@ -45,9 +46,12 @@ const touchDataToPressEvent = (
4546
});
4647

4748
const gestureToPressEvent = (
48-
event: GestureStateChangeEvent<
49-
HoverGestureHandlerEventPayload | LongPressGestureHandlerEventPayload
50-
>,
49+
event:
50+
| GestureStateChangeEvent<
51+
HoverGestureHandlerEventPayload | LongPressGestureHandlerEventPayload
52+
>
53+
| HoverGestureEvent
54+
| LongPressGestureEvent,
5155
timestamp: number,
5256
targetId: number
5357
): InnerPressableEvent => ({
@@ -73,9 +77,12 @@ const isTouchWithinInset = (
7377
(touch?.locationY ?? 0) > -(inset.top ?? 0);
7478

7579
const gestureToPressableEvent = (
76-
event: GestureStateChangeEvent<
77-
HoverGestureHandlerEventPayload | LongPressGestureHandlerEventPayload
78-
>
80+
event:
81+
| GestureStateChangeEvent<
82+
HoverGestureHandlerEventPayload | LongPressGestureHandlerEventPayload
83+
>
84+
| HoverGestureEvent
85+
| LongPressGestureEvent
7986
): PressableEvent => {
8087
const timestamp = Date.now();
8188

packages/react-native-gesture-handler/src/index.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -148,9 +148,10 @@ export type {
148148

149149
export type {
150150
PressableProps,
151+
LegacyPressableProps,
151152
PressableStateCallbackType,
152153
} from './components/Pressable';
153-
export { default as Pressable } from './components/Pressable';
154+
export { default as LegacyPressable } from './components/Pressable';
154155

155156
export type { GestureTouchEvent as SingleGestureTouchEvent } from './handlers/gestureHandlerCommon';
156157

packages/react-native-gesture-handler/src/jestUtils/jestUtils.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -445,12 +445,12 @@ function getHandlerData(
445445
};
446446

447447
if (eventName === 'onGestureHandlerStateChange') {
448-
componentOrGesture.detectorCallbacks.onGestureHandlerStateChange({
448+
componentOrGesture.detectorCallbacks.jsEventHandler?.({
449449
oldState: oldState as State,
450450
...event,
451451
});
452452
} else if (eventName === 'onGestureHandlerEvent') {
453-
componentOrGesture.detectorCallbacks.onGestureHandlerEvent?.(event);
453+
componentOrGesture.detectorCallbacks.jsEventHandler?.(event);
454454
}
455455
},
456456
};

0 commit comments

Comments
 (0)