Skip to content

Conversation

@latekvo
Copy link
Member

@latekvo latekvo commented Nov 27, 2024

Description

This PR adds integration with the react-native-svg (RNSVG) to improve hitbox detection of the SVG elements they provide.

blocked by software-mansion/react-native-svg#2583
blocked by nested SvgViews with viewBox prop have invalid hit detection - No issue opened yet

Test plan

  • use the newly added SVG integration example for testing this feature

@latekvo latekvo changed the title Integrate with react-native-svg for improved hit detection of svg elements Add interaction with react-native-svg to improve hit-boxes of svg elements Nov 27, 2024
@latekvo latekvo changed the title Add interaction with react-native-svg to improve hit-boxes of svg elements Add react-native-svg interface Nov 27, 2024
@latekvo
Copy link
Member Author

latekvo commented Nov 28, 2024

Integration works as of bd51ac7, but I have to test it a bit more before it's ready.

jakex7 pushed a commit to software-mansion/react-native-svg that referenced this pull request Nov 28, 2024
…interface (#2555)

<!-- Thanks for submitting a pull request! We appreciate you spending
the time to work on these changes. Please follow the template so that
the reviewers can easily understand what the code changes affect -->

# Summary

Adding an `RNGH <-> RNSVG` interface requires usage of
`RenderableView.hitTest` to work.
([link](software-mansion/react-native-gesture-handler#3242))
Currently, `RenderableView.hitTest` is `package-private`, meaning it
cannot be accessed by other packages.
This change does not change any functionality of the library, it only
exposes existing functions to other libraries.

I only made public those `hitTest` implementation which are strictly
necessary for this interface, this is why multiple, if not most
`hitTest` implementations remain `package-private` despite the changes
made in the PR.

## Test Plan

- open the example app, see how the app builds successfully

### What's required for testing (prerequisites)?

- `RNSVG`'s `paper-example` app

### What are the steps to reproduce (after prerequisites)?

## Compatibility

| OS      | Implemented |
| ------- | :---------: |
| iOS     |    ❌      |
| MacOS   |    ❌      |
| Android |    ✅      |
| Web     |    ❌      |

## Checklist

<!-- Check completed item, when applicable, via: [X] -->

- [X] I have tested this on a device and a simulator
- [ ] I added documentation in `README.md`
- [ ] ~~I updated the typed files (typescript)~~
- [ ] I added a test for the API in the `__tests__` folder
@latekvo latekvo changed the base branch from main to next December 5, 2024 15:17
@latekvo latekvo changed the base branch from next to main December 18, 2024 14:31
jakex7 pushed a commit to software-mansion/react-native-svg that referenced this pull request Jan 15, 2025
<!-- Thanks for submitting a pull request! We appreciate you spending
the time to work on these changes. Please follow the template so that
the reviewers can easily understand what the code changes affect -->

# Summary

This PR reverts #2555, as `RenderableView.hitTest()` can be replaced by
`SvgView.reactTagForTouch()`, which is already `public`.

This PR also changes the `package-private` `getSvgView()` method of
`VirtualView` to `public`.
This change has been made to handle hit detection of transformed
`VirtualView`s, as `RenderableView`'s `hitTest()` doesn't take
transformations into account, while `SvgView`'s `reactTagForTouch()`
does.

Making `getSvgView()` public is necessary for integrating RNSVG support
into RNGH. More details
[here](software-mansion/react-native-gesture-handler#3242).

## Test Plan

Run the example from the RNGH - RNSVG [integration
PR](software-mansion/react-native-gesture-handler#3242).

## Compatibility

| OS      | Implemented |
| ------- | :---------: |
| Android |    ✅      |
Comment on lines +48 to +50
"[react-native-gesture-handler] Unable to resolve react-native location in " +
"node_modules. You should add project extension property (in app/build.gradle) " +
"`REACT_NATIVE_NODE_MODULES_DIR` with path to react-native."
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this done by a formatter?

Copy link
Member Author

@latekvo latekvo Feb 25, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, the formatter.
I debated myself about removing these changes, but figured there's no benefit for deferring them, or opening a separate PR for them.

Comment on lines +89 to +91
return (Integer.parseInt(major) == 15 && Integer.parseInt(minor) == 11 && Integer.parseInt(patch) >= 2) ||
(Integer.parseInt(major) == 15 && Integer.parseInt(minor) > 11) ||
Integer.parseInt(major) > 15
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Comment above states that it is available from 15.11.0, but here we check for 15.11.2

Copy link
Member Author

@latekvo latekvo Feb 25, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed the comment in 98731e5. The correct version is 15.11.2 (source).

Comment on lines 241 to 242
exclude group: 'com.facebook.fbjni'
// resolves "Duplicate class com.facebook.jni.CppException"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If this is also done by formatter, could you please move this comment line above?

Also, what formatter do you use? I do not recall that our formatting script changes gradle files.

Copy link
Member Author

@latekvo latekvo Feb 25, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You're right that :spotlessApply has no effect on gradle files. I ran the built-in android studio Groovy formatter, to format the version-checking part of shouldUseCommonInterfaceFromRNSVG.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

moved comment in 423ac1c

@latekvo latekvo merged commit 5b29e9d into main Feb 25, 2025
5 checks passed
@latekvo latekvo deleted the @latekvo/add-svg-integration branch February 25, 2025 16:23
m-bert added a commit that referenced this pull request Mar 28, 2025
## Description

#3242 introduced new `SVG` interface for better hit tests. Added files were not specified in `package.json` which resulted in builds failing.

## Test plan

Checked that newly created app build when _**Gesture Handler**_ is added.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants