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

Animated viewBox - transform scale is blury #1451

Closed
harveyconnor opened this issue Sep 10, 2020 · 6 comments
Closed

Animated viewBox - transform scale is blury #1451

harveyconnor opened this issue Sep 10, 2020 · 6 comments
Assignees
Labels

Comments

@harveyconnor
Copy link

Question

My issue is that whenever I animate my svg with a transform function it ends up being blury when I zoom in. The best alternative to this option would be to zoom in via the viewbox which will also offering a panning function.
I'm wondering if anyone has been successful in animating the viewBox?

The closest thing I've gotten to is adding an event listener on the animated value however that doesn't update the viewBox with the new scale adjustments.

Please any suggestions or recommendations are welcome! Thanks!

@guiccbr
Copy link

guiccbr commented Nov 29, 2021

Same with me. @harveyconnor , were you ever able to do that?

@harveyconnor
Copy link
Author

@guiccbr nope I could never get it to work. The support for this repo is dead.

@guiccbr
Copy link

guiccbr commented Dec 6, 2021

@harveyconnor , I got something working that was a good alternative to me. Instead of using the transform prop, I used the style prop on a <G>. The style prop is not typed though, but it works. And it's great because it doesn't distort the child paths.

Style also works for <Paths> btw. In my case I'm even using react-native-reanimated to animate stuff, and everything works great.

@harveyconnor
Copy link
Author

Hi @guiccbr could you please share a repo with us that replicates what you have created :)

@meepak
Copy link

meepak commented Jan 2, 2024

I was able to resolve this by simply changing width height within SVG to 100%, wrap the SVG around the Animated.View and use useAnimatedStyle to change width and height. This way I get the smooth zoom effect on svg whereas transform scale results in pixelated zoom.

My problem is I am unabe to do same with custom exiting animation, width and height manipulation not seems to be working there and transform seems to be the only option, is it?

@bohdanprog bohdanprog assigned bohdanprog and jakex7 and unassigned bohdanprog Jun 17, 2024
jakex7 added a commit that referenced this issue Jun 26, 2024
# Summary

This PR resolves an issue raised in #1451. 
Currently, when a mask is used, we render the element as a bitmap (or
platform equivalent), but the bitmap's size does not update accordingly
with transformations. With these changes, the problem is addressed as
follows:
* **Android**: We utilize the original canvas layers to render the mask
and element with the appropriate blending mode.
* **iOS**: We create an offscreen context with the size multiplied by
the screen scale and apply the original UIGraphics CTM (current
transformation matrix) to the offscreen context. This ensures that the
same transformations are applied as on the original context.

Additionally, there is a significant performance improvement on Android
as we are not creating three new Bitmaps and three new Canvases.

## Test Plan

There are many ways for testing these changes, but the required ones
are:
* `TestsExample` app -> `Test1451.tsx`
* `Example` app -> Mask section
* `FabricExample` app -> Mask section

## Compatibility

| OS      | Implemented |
| ------- | :---------: |
| Android |    ✅     |
| iOS     |    ✅     |

## Preview

<img width="337" alt="image"
src="https://github.com/software-mansion/react-native-svg/assets/39670088/93dbae85-edbd-452a-84b0-9a50107b1361">
<img width="337" alt="image"
src="https://github.com/software-mansion/react-native-svg/assets/39670088/07838dff-cb2d-4072-a2fc-5c16a76f6c33">
@bohdanprog bohdanprog added the bug label Jun 26, 2024
@jakex7
Copy link
Member

jakex7 commented Jun 26, 2024

whereas transform scale results in pixelated zoom.

Hi!
This issue (pixelated zoom) has likely been resolved in #2299 and merged into the main branch. Please feel free to test it and provide feedback before the release.

Thank you!

@jakex7 jakex7 closed this as completed Sep 24, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

5 participants