Skip to content

Commit 6386f61

Browse files
committed
Merge branch '@mbert/docs-review' into @mbert/docs-root-view
2 parents 4a901f8 + 8232dc8 commit 6386f61

10 files changed

Lines changed: 88 additions & 14 deletions

File tree

packages/docs-gesture-handler/docs/fundamentals/gesture-detector.mdx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ import CollapsibleCode from '@site/src/components/CollapsibleCode';
1010

1111
## Gesture Detector
1212

13-
The `GestureDetector` is a key component of `react-native-gesture-handler`. It supports gestures created either using the hook API or the builder pattern. Additionally, it allows for the recognition of multiple gestures through [gesture composition](/docs/fundamentals/gesture-composition). `GestureDetector` interacts closely with [`Reanimated`](https://docs.swmansion.com/react-native-reanimated/). For more details, refer to the [Integration with Reanimated](/docs/fundamentals/reanimated-interactions) section.
13+
The `GestureDetector` is a key component of `react-native-gesture-handler`. It supports gestures created either using the hook-based API or the builder pattern. Additionally, it allows for the recognition of multiple gestures through [gesture composition](/docs/fundamentals/gesture-composition). `GestureDetector` interacts closely with [`Reanimated`](https://docs.swmansion.com/react-native-reanimated/). For more details, refer to the [Integration with Reanimated](/docs/fundamentals/reanimated-interactions) section.
1414

1515
When using hook API, you can also integrate it directly with the [Animated API](https://reactnative.dev/docs/animated). More on that can be found in [Integration with Animated](/docs/fundamentals/animated-interactions) section.
1616

packages/docs-gesture-handler/docs/fundamentals/installation.mdx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@ Gesture Handler on Android is implemented in Kotlin. If you need to set a specif
9393
```groovy
9494
buildscript {
9595
ext {
96-
kotlinVersion = "1.6.21"
96+
kotlinVersion = "2.1.20"
9797
}
9898
}
9999
```

packages/docs-gesture-handler/docs/fundamentals/state-manager.mdx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,11 +11,11 @@ RNGH3 allows to manually control [gestures lifecycle](/docs/under-the-hood/state
1111

1212
## State management
1313

14-
Manual state management is based on `handlerTag`. There are two ways of manual state control. Some gestures also support [`manualActivation`](#manualactivation) property, which blocks their automatic activation, event if they met specific criteria.
14+
Manual state management is based on `handlerTag`. There are two ways of manual state control. Some gestures also support [`manualActivation`](#manualactivation) property, which blocks their automatic activation, even if they meet their activation criteria.
1515

1616
### Inside gesture definition
1717

18-
If you want to manipulate gesture's state in its callbacks, you can get `handlerTag` from event parameter.
18+
If you want to manipulate gesture's state in its callbacks, you can get `handlerTag` from event parameter.
1919

2020
<CollapsibleCode
2121
label="Show full example"

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

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -105,9 +105,6 @@ const styles = StyleSheet.create({
105105

106106
### direction
107107

108-
```ts
109-
```
110-
111108
<CollapsibleCode
112109
label="Show composed types definitions"
113110
expandedLabel="Hide composed types definitions"

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

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import android.view.ViewGroup
88
import android.widget.EditText
99
import com.facebook.react.uimanager.ReactCompoundView
1010
import com.facebook.react.uimanager.RootView
11+
import com.swmansion.gesturehandler.react.RNGestureHandlerDetectorView
1112
import com.swmansion.gesturehandler.react.RNGestureHandlerRootHelper
1213
import com.swmansion.gesturehandler.react.RNGestureHandlerRootView
1314
import com.swmansion.gesturehandler.react.isHoverAction
@@ -745,9 +746,12 @@ class GestureHandlerOrchestrator(
745746

746747
// TODO: this is not an ideal solution as we only consider ViewGroups that has no background set
747748
// TODO: ideally we should determine the pixel color under the given coordinates and return
748-
// false if the color is transparent
749-
val isLeafOrTransparent = view !is ViewGroup || view.getBackground() != null
750-
return isLeafOrTransparent && isTransformedTouchPointInView(coords[0], coords[1], view)
749+
val isLeaf = view !is ViewGroup
750+
val isNotTransparent = view.getBackground() != null
751+
val isDirectDetectorChild = view.parent is RNGestureHandlerDetectorView
752+
val isPointInView = isTransformedTouchPointInView(coords[0], coords[1], view)
753+
754+
return (isLeaf || isNotTransparent || isDirectDetectorChild) && isPointInView
751755
}
752756

753757
fun transformPointToChildViewCoords(x: Float, y: Float, parent: ViewGroup, child: View, outLocalPoint: PointF) {

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

Lines changed: 38 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,43 @@ class RNGestureHandlerDetectorView(context: Context) : ReactViewGroup(context) {
3737
attachHandlers(newHandlers)
3838
}
3939

40+
override fun onAttachedToWindow() {
41+
super.onAttachedToWindow()
42+
43+
if (moduleId != -1) {
44+
handlersToAttach?.let {
45+
attachHandlers(it)
46+
}
47+
48+
virtualChildrenToAttach?.let {
49+
attachVirtualChildren(it)
50+
}
51+
52+
handlersToAttach = null
53+
virtualChildrenToAttach = null
54+
}
55+
}
56+
57+
override fun onDetachedFromWindow() {
58+
if (attachedHandlers.isNotEmpty()) {
59+
handlersToAttach = attachedHandlers.toMutableList().also {
60+
it.addAll(handlersToAttach ?: emptyList())
61+
}
62+
}
63+
64+
if (attachedVirtualHandlers.isNotEmpty()) {
65+
virtualChildrenToAttach = attachedVirtualHandlers.map {
66+
VirtualChildren(it.value.toList(), it.key)
67+
}.toMutableList().also {
68+
it.addAll(virtualChildrenToAttach ?: emptyList())
69+
}
70+
}
71+
72+
detachAllHandlers()
73+
74+
super.onDetachedFromWindow()
75+
}
76+
4077
fun setModuleId(id: Int) {
4178
assert(this.moduleId == -1) { "Tried to change moduleId of a native detector" }
4279

@@ -192,7 +229,7 @@ class RNGestureHandlerDetectorView(context: Context) : ReactViewGroup(context) {
192229
eventDispatcher?.dispatchEvent(event)
193230
}
194231

195-
fun onViewDrop() {
232+
fun detachAllHandlers() {
196233
val registry = RNGestureHandlerModule.registries[moduleId]
197234
?: throw Exception("Tried to access a non-existent registry")
198235

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ class RNGestureHandlerDetectorViewManager :
4343
}
4444

4545
override fun onDropViewInstance(view: RNGestureHandlerDetectorView) {
46-
view.onViewDrop()
46+
view.detachAllHandlers()
4747
super.onDropViewInstance(view)
4848
}
4949

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

Lines changed: 29 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,11 +28,24 @@ void RNGestureHandlerDetectorShadowNode::initialize() {
2828
children.size() == 1 &&
2929
"RNGestureHandlerDetector received more than one child");
3030

31-
const auto clonedChild = children[0]->clone({});
32-
replaceChild(*children[0], clonedChild);
31+
// Will clone the child and ensure it's not flattened
32+
replaceChild(*children[0], children[0], 0);
3333
}
3434
}
3535

36+
void RNGestureHandlerDetectorShadowNode::appendChild(
37+
const std::shared_ptr<const ShadowNode> &child) {
38+
YogaLayoutableShadowNode::appendChild(unflattenNode(child));
39+
}
40+
41+
void RNGestureHandlerDetectorShadowNode::replaceChild(
42+
const ShadowNode &oldChild,
43+
const std::shared_ptr<const ShadowNode> &newChild,
44+
size_t suggestedIndex) {
45+
YogaLayoutableShadowNode::replaceChild(
46+
oldChild, unflattenNode(newChild), suggestedIndex);
47+
}
48+
3649
void RNGestureHandlerDetectorShadowNode::layout(LayoutContext layoutContext) {
3750
// TODO: consider allowing more than one child and doing bounding box
3851
react_native_assert(getChildren().size() == 1);
@@ -69,4 +82,18 @@ void RNGestureHandlerDetectorShadowNode::layout(LayoutContext layoutContext) {
6982
mutableChild->setLayoutMetrics(childmetrics);
7083
}
7184

85+
std::shared_ptr<const ShadowNode>
86+
RNGestureHandlerDetectorShadowNode::unflattenNode(
87+
const std::shared_ptr<const ShadowNode> &node) {
88+
auto clonedNode = node->clone({});
89+
auto clonedNodeWithProtectedAccess =
90+
std::static_pointer_cast<RNGestureHandlerDetectorShadowNode>(clonedNode);
91+
92+
clonedNodeWithProtectedAccess->traits_.set(ShadowNodeTraits::FormsView);
93+
clonedNodeWithProtectedAccess->traits_.set(
94+
ShadowNodeTraits::FormsStackingContext);
95+
96+
return clonedNode;
97+
}
98+
7299
} // namespace facebook::react

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

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,9 +53,17 @@ class RNGestureHandlerDetectorShadowNode final
5353
initialize();
5454
}
5555

56+
void appendChild(const std::shared_ptr<const ShadowNode> &child) override;
57+
void replaceChild(
58+
const ShadowNode &oldChild,
59+
const std::shared_ptr<const ShadowNode> &newChild,
60+
size_t suggestedIndex = SIZE_MAX) override;
61+
5662
void layout(LayoutContext layoutContext) override;
5763

5864
private:
65+
std::shared_ptr<const ShadowNode> unflattenNode(
66+
const std::shared_ptr<const ShadowNode> &node);
5967
void initialize();
6068

6169
std::optional<LayoutMetrics> previousLayoutMetrics_;

packages/react-native-gesture-handler/src/v3/hooks/useGesture.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,7 @@ export function useGesture<THandlerData, TConfig>(
9090

9191
useEffect(() => {
9292
return () => {
93+
currentGestureRef.current = { type: '', handlerTag: -1 };
9394
NativeProxy.dropGestureHandler(handlerTag);
9495
scheduleFlushOperations();
9596
};

0 commit comments

Comments
 (0)