Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: properly handle touch events outside the Svg #2611

Merged
merged 3 commits into from
Jan 15, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 8 additions & 4 deletions android/src/main/java/com/horcrux/svg/VirtualView.java
Original file line number Diff line number Diff line change
Expand Up @@ -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());
Expand Down
3 changes: 3 additions & 0 deletions apple/Elements/RNSVGSvgView.mm
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
Loading