Giter Site home page Giter Site logo

glazzes / react-native-zoom-toolkit Goto Github PK

View Code? Open in Web Editor NEW
142.0 3.0 8.0 39.2 MB

Smoothly zoom any image, video or component you want!

Home Page: https://glazzes.github.io/react-native-zoom-toolkit/

License: MIT License

JavaScript 1.70% TypeScript 98.30%
react-native react-native-image-zoom react-native-zoomable zoom pan pinch-to-zoom react-native-zoom zoomable image-zoom react-component-library

react-native-zoom-toolkit's Introduction

Hi there! I'm Santiago ๐Ÿ‘‹

I'm an enthusiast software developer from Manizales, Colombia. I've developing for the last +2 years on a daily basis, I'm focused on backend development with Java and Spring Boot, but i do also like to work in the frontend with React Native for mobile development.

  • I'm currently learning more about the following topics: Gradle, Spring Cloud & Micro services, Math with a foucs in UI interactions
  • One of my personal goals it's to develop native IOS apps
  • I like a good code challenge from time to time Codewars badge

My tech stack (Skills)

Java Kotlin Spring boot Spring boot Typescript React and React native Docker Postgresql Spring boot Spring boot

react-native-zoom-toolkit's People

Contributors

glazzes avatar hadesshadows avatar iqorlobanov avatar tannermares 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

react-native-zoom-toolkit's Issues

[Gallery] Prop support to disable image to zoom at particular index

Hi, hope you are having a great day

Lets say I have a gallery component which render's 10 images. But I dont want all 10 images to be zoomed. I dont want the 5th image in array be zoomed. I want the starting 4 images be zoomed and the last 5 images be zoomed not the middle one.

Is this possible with current version? If we have to add a support for it, then how much effort would that take?

Thankyou

[Bug]: getAspectRatioSize.default is not a function

Summary

After fresh installation and use of CropZoom in my expo app I am instantly receiving such errors on iOS, Is this something connected to usage inside monorepo?:

Simulator Screenshot - iPhone 15 Pro - 2024-08-12 at 11 24 12
Simulator Screenshot - iPhone 15 Pro - 2024-08-12 at 11 23 53

Environment

expo: 51.0.17
react-native: 0.74.1
react-native-reanimated: 3.14.0
react-native-gesture-handler: 2.16.2
react-native-zoom-toolkit: 2.1.2

Note: I am using monorepo.

Steps to Reproduce

  1. Install react-native-zoom-toolkit in monorepo package.json
  2. Use CropZoom inside expo project inside monorepo

[Bug]: Component jumps when lifting one finger

Summary

When zooming with SnapbackZoom or ResumableZoom, lifting one finger changes the focal point and makes the component jump according to the new focal point. This is very commonly noticed since it usually jumps when you let go with both fingers. Both fingers don't always leave the screen at the exact same moment.

Environment

expo 51.0.11
react-native-gesture-handler 2.16.1
react-native-reanimated 3.10.1

Steps to Reproduce

Can be recreated with the most basic example. No props to SnapbackZoom.

// ...

const uri = // ...

// ...

<SnapbackZoom>
  <Image source={{ uri }} />
<SnapbackZoom>

// ...

A minimal fix could be to ignore pinch gestures where numberOfPointers is not equal to 2.

[Gallery]: How to use Gallery with video?

Summary

How to use gallery with video?
Are there examples of use or is this component just for Images? Because the item's gestures overlap the video player's gestures

[Bug]: Error: maxWidth and maxHeight parameters are undefined, provide at least one of them when image is square

Summary

Hi, thank you for creating this module.

I'm encountering this error when the image is a square eg. 1280x1280:

Error: maxWidth and maxHeight parameters are undefined, provide at least one of them

When I change the height:

return getAspectRatioSize({
aspectRatio: aspectRatio,
width: aspectRatio >= 1 ? undefined : maxWidth,
height: aspectRatio > 1 ? maxHeight : undefined,
});

to:
aspectRatio >= 1 ? maxHeight : undefined

The image loads fine and I get this warning:

CropZoom inferred a max crop height of 329.14285714285717, but received a crop height of 386, your cropSize property's height has been clamped to 329.14285714285717

I tried it with this image:

Click me

7515495b-982d-44d2-9931-5a8bbbf27532

I'm not doing something fancy, just followed the common /example

ps. I'm also not rotating or trying to rotate the image.

Environment

rn 0.74.1

Steps to Reproduce

No response

Syncing state with ResumableZoom at the end of panWithPinch

What Would You Like to Know?

Hello, great work on this library! My use case is as follows: I want to use a panWithPinch gesture in the ResumableZoom component. At the end of the gesture, I want to sync global state with the zoom/pan state.

If I provide an onPanEnd and onPinchEnd callback, only the latter is called when the gesture is released. However, even with panMode={PanMode.CLAMP}, I am able to pan beyond the boundaries of the image while pinching. Is this the intended behavior?

The pan gets reset to the bounds after releasing the gesture, but only after onPinchEnd is called, so that won't work for my purpose.

I can update state from within onGestureActive, but this results in many unnecessary updates.

This use case seems like it would be resolved by either fixing panWithPinch so that it doesn't pan beyond bounds when panMode is clamped, or by providing an onGestureEnd callback, similar to SnapbackZoom. What do you think?

[Bug]: Press not working in Gallery renderItem

Summary

Trying to add a pressable component in Gallery renderItem but it's not working. Also Is it possible to disable zoom.

Environment

"react": "18.2.0",
"react-native": "0.72.12",
"react-native-reanimated": "^3.13.0",
"react-native-gesture-handler": "^2.16.2",
"react-native-zoom-toolkit": "^2.0.1",

Steps to Reproduce

No response

Smooth pinch with ResumableZoom

Description

Hey, first of all wanted to say that you've done a fantastic job with this library ๐Ÿ™‡โ€โ™‚๏ธ

Tried the ResumableZoom component and it works well, there's only two places where it "jitters" on iOS device. Did some investigation and here's what I found:

  • When pinch is active and panning just a tiny bit then it "stutters". Traced it down to inaccurate focalX & focalY values on RNGH side software-mansion/react-native-gesture-handler#2833
  • When releasing a pinch, then it often jumps. Apparently there's a few updates that happen with one touch / finger instead of two. This leads to a significant change in focal point. Possible solution is to add a check here to only handle the update if e.numberOfPointers === 2

[Gallery] onZoomBegin callback?

Hello,

It would be really helpful if we can have onZoomBegin and onZoomEnd callback so that we can add animations to other components.

Currently we can only requestState and fetch scale value but thats a ref, so cant detect it

Also there is onPinchStart and no onDoubleTap which again doesnt serve my need

My need: I want to detect when the image has been zoomed and when it is in initial state automatically

[Bug]: extendGestures={true} make pan gesture not work at Android Device

Summary

extendGestures={false} works fine, but I have some button in ResumableZoom, these button can not trigger onPress callback when extendGestures is false. But when extendGestures is true, I can not pan the content to the left side.

Environment

import React from 'react'
import { Image, Pressable, Text, View, useWindowDimensions } from 'react-native'
import { ResumableZoom, getAspectRatioSize, useImageResolution } from 'react-native-zoom-toolkit'

const uri = 'https://assets-global.website-files.com/63634f4a7b868a399577cf37/64665685a870fadf4bb171c2_labrador%20americano.jpg'

const App = () => {
  const { width } = useWindowDimensions()

  // Gets the resolution of your image
  const { isFetching, resolution } = useImageResolution({ uri })
  if (isFetching || resolution === undefined) {
    return null
  }
  return (
    <View style={{
      width: '100%', height: '100%'
    }}>
      < ResumableZoom maxScale={2} extendGestures={true} >
        <View>
          <Pressable onPress={() => { console.log('touch not work') }}><Text> touch me</Text></Pressable>
          <Image source={{ uri }} style={resolution} />
        </View>
      </ResumableZoom >
    </View >
  )
}

export default App

Steps to Reproduce

pan to left but not scroll

Ensure Image Stays within Container During Zooming

954a54f6-7f63-46c9-8aea-69d675d8dd01.mp4

Summary

I'm encountering an issue where the height of the image increases when zooming using the react-native-zoom-toolkit library. However, the expected behavior is to maintain a fixed height for the image within its container, even when zooming in.

Issue

When I zoom in on the image, the text below the image overlaps with it. but, expected behavior would be, image should stay within its container even after zooming, without overlapping the below text.

Screen.Recording.2024-04-09.at.12.21.24.PM.mov

Steps to Reproduce

  1. Import the ResumableZoom component from react-native-zoom-toolkit.
  2. Wrap an Image component with ResumableZoom.
  3. Attempt to zoom in on the image.

[Question]: Is there a way to integrate the Gallery Component with react-native-modal?

Summary

I've been trying to use it with react-native-modal to achieve the same result as the Twitter/Facebook Gallery, where I can close modal by swiping down. But every time I try to use it I end up having a conflict between swipes.
Is there a way to fix it? Or even achieve the result using react-native's own modal? Ty

Currently code, using the example provided

import React, { useCallback, useEffect, useRef, useState } from 'react';
import { Text, View } from 'react-native';
import { useSharedValue } from 'react-native-reanimated';
import { Gallery, type GalleryType } from 'react-native-zoom-toolkit';
import {
  getAssetsAsync,
  requestPermissionsAsync,
  type Asset,
} from 'expo-media-library';

import GalleryImage from './GalleryImage';
import { StyleSheet } from 'react-native';
import { TouchableOpacity } from 'react-native-gesture-handler';
import Modal from 'react-native-modal';

type SizeVector = { width: number; height: number };

const GalleryExample = () => {
  const ref = useRef<GalleryType>(null);

  const [assets, setAssets] = useState<Asset[]>([]);
  const [scales, setScales] = useState<SizeVector[]>([]);
  const [open, setOpen] = useState<boolean>(false);

  const activeIndex = useSharedValue<number>(0);

  const renderItem = useCallback(
    (item: Asset, index: number) => {
      return (
        <GalleryImage asset={item} index={index} activeIndex={activeIndex} />
      );
    },
    [activeIndex]
  );

  useEffect(() => {
    const requestAssets = async () => {
      const { granted } = await requestPermissionsAsync();
      if (granted) {
        const page = await getAssetsAsync({
          first: 100,
          mediaType: 'photo',
          sortBy: 'creationTime',
        });

        const pageScales: SizeVector[] = [];
        for (let asset of page.assets) {
          pageScales.push({ width: asset.width, height: asset.height });
        }

        setAssets(page.assets);
        setScales(pageScales);
      }
    };

    requestAssets();
  }, []);

  if (assets.length === 0 || scales.length === 0) {
    return null;
  }

  return (
    <View style={styles.container}>
      <Text>Open</Text>
      <TouchableOpacity onPress={() => setOpen(true)}>
        <Text>Open</Text>
      </TouchableOpacity>
      <Modal
        isVisible={open}
        style={styles.root}
        onSwipeComplete={() => setOpen(false)}
        onBackButtonPress={() => setOpen(false)}
      >
        <Gallery
          ref={ref}
          data={assets}
          keyExtractor={(item, index) => `${item.uri}-${index}`}
          renderItem={renderItem}
          maxScale={scales}
          onIndexChange={(idx) => {
            activeIndex.value = idx;
          }}
        />
      </Modal>
    </View>
  );
};

const styles = StyleSheet.create({
  root: {
    flex: 1,
    backgroundColor: '#000000',
    margin: 0,
  },
  container: {
    flex: 1,
    alignItems: 'center',
    justifyContent: 'center',
    backgroundColor: 'white',
  },
});

export default GalleryExample;

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.