Repository: software-mansion/react-native-svg (language: java)

Issue:
`RenderableView`s inside `SvgView` call `onPress` when pressed outside of `SvgView`
### Description

Given any `RenderableView` which is larger than the `SvgView` that it's contained in, the `RenderableView` will be pressable even on the areas that are hidden due to the element overflowing out of the `SvgView`

Interesting thing to notice is that when the touches are done inside the bounds of `SvgView`, they are dispatched through `hitTest`. When touches are done outside the bounds of `SvgView`, the `hitTest` methods are never called, and yet the events are still dispatched by other means (i could not find the source of these events).

https://github.com/user-attachments/assets/20b65f44-cfe9-4f6f-a3d2-e0780f0dee51

### Steps to reproduce

- run the provided repro code in place of the `EmptyExample`
- press on the orange rectangle
- press outside of the orange rectangle
- see how the `onPress` is called on each callback regardless of the touch location

<details>
<summary>
Collapsed example code
</summary>

```jsx
import React from 'react';
import {View, StyleSheet} from 'react-native';
import {Rect, Svg} from 'react-native-svg';

function EmptyExample() {
  return (
    <View style={styles.container}>
      <Svg
        height="150"
        width="250"
        onPress={() => console.log('SVG: clicked oob container')}>
        <Rect
          x="-3000"
          y="-3000"
          width="6000"
          height="6000"
          fill="tomato"
          onPress={() => console.log('SVG: clicked oob square')}
        />
      </Svg>
    </View>
  );
}
EmptyExample.title = '';

const icon = (
  <Svg height="30" width="30" viewBox="0 0 20 20">
    <Rect x="0" y="0" width="20" height="20" fill="none" stroke="black" />
  </Svg>
);
const samples = [EmptyExample];

export {icon, samples};

const styles = StyleSheet.create({
  container: {
    alignItems: 'center',
    justifyContent: 'center',
    marginBottom: 48,
    backgroundColor: 'tomato',
  },
});

```

</details>

### Snack or a link to a repository

Code provided in the reproduction steps

### SVG version

15.10.1 - main

### React Native version

0.76.0

### Platforms

Android

### JavaScript runtime

Hermes

### Workflow

React Native

### Architecture

Paper Only (Old Architecture)

### Build type

Debug app & dev bundle

### Device

Real device

### Device model

Xiaomi Redmi Note 8T, Pixel 3a emulator

### Acknowledgements

Yes


Discussion / hints:
Hey! 👋 

The issue doesn't seem to contain a [minimal reproduction](https://stackoverflow.com/help/minimal-reproducible-example).

Could you provide a [snack](https://snack.expo.dev/) or a link to a GitHub repository under your username that reproduces the problem?

Fix patch:
diff --git a/android/src/main/java/com/horcrux/svg/VirtualView.java b/android/src/main/java/com/horcrux/svg/VirtualView.java
index d51601011..815b236d6 100644
--- a/android/src/main/java/com/horcrux/svg/VirtualView.java
+++ b/android/src/main/java/com/horcrux/svg/VirtualView.java
@@ -591,10 +591,14 @@ void setClientRect(RectF rect) {
     int bottom = (int) Math.ceil(mClientRect.bottom);
     setMeasuredDimension(width, height);
     if (!(this instanceof GroupView)) {
-      setLeft(left);
-      setTop(top);
-      setRight(right);
-      setBottom(bottom);
+      SvgView root = this.getSvgView();
+      // Prevent going out of the root view bounds to properly handle touch events
+      if (root != null) {
+        setLeft(Math.max(left, 0));
+        setTop(Math.max(top, 0));
+        setRight(Math.min(right, root.getWidth()));
+        setBottom(Math.min(bottom, root.getHeight()));
+      }
     }
     EventDispatcher eventDispatcher =
         UIManagerHelper.getEventDispatcherForReactTag(mContext, getId());
diff --git a/apple/Elements/RNSVGSvgView.mm b/apple/Elements/RNSVGSvgView.mm
index 7cb97e4d4..a00e14335 100644
--- a/apple/Elements/RNSVGSvgView.mm
+++ b/apple/Elements/RNSVGSvgView.mm
@@ -342,6 +342,9 @@ - (BOOL)pointInside:(CGPoint)point withEvent:(UIEvent *)event
 
 - (RNSVGPlatformView *)hitTest:(CGPoint)point withEvent:(UIEvent *)event
 {
+  if (point.x < 0 || point.y < 0 || point.x > self.bounds.size.width || point.y > self.bounds.size.height) {
+    return nil;
+  }
   CGPoint transformed = point;
   if (self.align) {
     transformed = CGPointApplyAffineTransform(transformed, _invViewBoxTransform);


Test patch: