Giter Club home page Giter Club logo

react-native-zoom-reanimated's Introduction

react-native-zoom-reanimated

Zoom component on React Native + react-native-reanimated + react-native-gesture-handler

  • You can zoom any View, Image or whatever
  • Can be used in FlatList (see Preview below)
  • Double tap to zoom in or zoom out
  • Automatically bounces to borders when paning outside of container and leaving the touch

Preview

iOS preview

1.mp4

Android preview

Android.mp4

Getting started

Install the library using either Yarn:

yarn add react-native-zoom-reanimated

or npm:

npm install --save react-native-zoom-reanimated

Required peer dependencies

dependency required version
react-native-reanimated >= 2.0.0
react-native-gesture-handler >= *

Usage

import Zoom from 'react-native-zoom-reanimated'

Example

import Zoom from 'react-native-zoom-reanimated'

...
  <Zoom>
    <Image
      source={{ uri: ... }}
      resizeMode='contain'
      style={{
        width: deviceWidth,
        height: imageHeight * deviceWidth / imageWidth,
       }}
    />
  </Zoom>
...

Parameters

Name Type Required Description
style StyleProp<ViewStyle> No Container style
contentContainerStyle StyleProp<ViewStyle> No Content container style
animationFunction function No Animation function from react-native-reanimated. Default: withTiming. For example, you can use withSpring instead: https://docs.swmansion.com/react-native-reanimated/docs/api/animations/withSpring
animationConfig object No Config for animation function from react-native-reanimated. For example, avaiable options for withSpring animation: https://docs.swmansion.com/react-native-reanimated/docs/api/animations/withSpring#options-object
doubleTapConfig { defaultScale?: number, minZoomScale?: number, maxZoomScale?: number } No Config for zoom on double tap. defaultScale - if you want to have fixed zoom on double tap, or calculated based on dimensions then leave it as it is. minZoomScale and maxZoomScale define range with min zoom & max zoom on double tap

License

The library is released under the MIT licence. For more information see LICENSE.

TODO

  • document useZoomGesture
  • add examples of usage Zoom (with or without different configs), useZoomGesture with react-native app code
  • add examples of list of images with FlatList
  • make list component with https://github.com/callstack/react-native-pager-view and export it for galleries usecase

react-native-zoom-reanimated's People

Contributors

alduzy avatar fede-s avatar hyoper avatar kesha-antonov avatar saeedzhiany avatar vokhuyetoz avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

react-native-zoom-reanimated's Issues

Allow props for scale value on double tap

Currently the new scale is automatically calculated based on a ratio (width / height) and is clamped (1.4 to 1.5).

It would be worth it to allow to pass a props "scaleStep" to override such value. We could also imagine a minScale and maxScale props for other purpose that could also impact the clamped values.

Typescript support

Thanks for the package. is there any plan to support Typescript or even rewrite the package with Typescript?

Zoomed element jumps off position when Pan Gesture starts (Android)

Hi, I'm using this library to zoom images.
I get the error while testing on a Motorola G52 with Android 12.
Works well on iphone simulator.

I have a fix for it. I can send a PR.

Basically when the gesture starts event.translationX and event.translationY have non zero values on Android, the value depends on how much zoom there is. The value on iphone simulator is always 0, which is what it is expected by the library.

The fix consists on listening to Gesture.Pan().onStart() to grab the initial values of event.translationX and event.translationY and use them as offsets for Gesture.Pan().onUpdate() and Gesture.Pan().onEnd()
And it works perfectly because if the initial value is 0 then we have the same result as now, but if the value is non zero it fixes the glitch.

Help needed: callback on zoom?

Hi, thank you for this library, it's exactly what I need!
For my purposes, I need to know when an image is zoomed in and zoomed out. So, I would need something like a callback.
Looking at the source code, I saw both the useZoomGesture hook and the animationFunction prop, but I didn't understand how to use them.
So I'm asking for your help on this.
I don't want to customize or rewrite the entire animation, I just need to know when the zoom is activated or deactivated.
Ideally, I would like to have two callbacks: at the beginning of the animation and at the end of the animation.

Thanks!

Typescript error with animationFunction props

Hello 👋

I get the following error with the latest version :

Capture d’écran 2024-03-19 à 15 48 24

It seems that there is a problem with the animationFunction type.

I think it can be fixed with the following type :

animationFunction?: typeof withTiming;

The PR is already ready if you're ok with that.

sharing example code

Thanks for the awesome project.

Could you share the code that you shown in the video?

It's okay if you could not.
Then, can you tell me what you used for sliding pages?

Thanks in advance!

Minimum zoom inquiry

hello. When using pinch zoom, is there a way to prevent the pinch zoom from being smaller than the initial scale?

Render error

Hello coder team :)

I tried using this lib, but when i wanted to show your component, with an image within it, i get this error:
Transform with key of "scale" must be a number: {"scale": 1}

I use
"typescript": "4.8.4"
"react-native": "0.72.4",
reanimated 3.3.0
"react-native-gesture-handler": "2.16.2",
"react-native-zoom-reanimated": "^1.4.5"

I hope your able to resolve the issue :)

Integration with FastImage library

Hi,

I am having trouble with integrating FastImage library with yours.
Only white color is displayed. For example with react-native-pdf-light i have no problem, it works as expected
Is there something I can do to make it work?

Thank you

TypeScript issue

Current style definitions are wrong

export interface ZoomProps {
  style?: StyleProp<ViewProps>;
  contentContainerStyle?: StyleProp<ViewProps>;
  ...
}

It should be

export interface ZoomProps {
  style?: StyleProp<ViewStyle>;
  contentContainerStyle?: StyleProp<ViewStyle>;
  ...
}

Focal Point?

Pinch to zoom here only zooms in at the center of your screen, have you interacted with focal points to zoom at the position you pinch at?

Reduce bounciness

Hi, thank you for great package :)

Is there a way to reduce the bounciness? Or even remove it, the default settings are kinda too much for my purpose.

Thank you in advance

Is Reanimated 3 supported?

I use Reanimated 3 in the project so when I try to install the lib it fails.

But I see this from package:

"devDependencies": {
    "react-native-reanimated": "^3.2.0",
},
"peerDependencies": {
    "react-native-reanimated": "^2.0.0"
}

Should peerDependencies be bumped to v3 also?

Double tap is ignored when pictured is zoomed in on Android

Hello,

I noticed on Android that the double tap for zooming out does not work.

How to reproduce it:
Zoom in on a FastImage (in my case) and then try to zoom out using double tap. It does not work, tap is ignored.

I have checked the code and I found out why and how it might be fixed.

Why this happens?
The Pan gesture is triggered instead of Tap gesture when the picture is zoomed in.

How could it be fixed?
Replace return Gesture.Race( Gesture.Simultaneous(pinchGesture, panGesture), tapGesture )

with return Gesture.Race( Gesture.Simultaneous(pinchGesture, panGesture, tapGesture) )

I'm not used to the Gesture implementation, but it seems that not allowing for tap simultaneously with pinch & pan creates this situation. I am using Android 13. I'm not 100% sure if that's the only solution, however I don't think it hurts allowing for double tap while simultaneously zooming if, if anyone would want to do so for any reason, the behaviour works fine from what I tested.

I would have created a PR for this, but I don't have write access to it.

Let me know what you think.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.