Giter Club home page Giter Club logo

react-native-image-view's Introduction

If you are using React Native >= 0.59.0 it's recommended to use similar package https://github.com/jobtoday/react-native-image-viewing as improved and better supported version!

npm version

React Native modal image view with pinch zoom and carousel.

Try with expo: https://expo.io/@antonkalinin/react-native-image-view

Warning: Breaking changes since v2.0.0:

  • instead of prop source => images
  • no title prop for footer, please use renderFooter instead

Installation

yarn add react-native-image-view

or

npm install --save react-native-image-view

Demo

Usage

import ImageView from 'react-native-image-view';

const images = [
    {
        source: {
            uri: 'https://cdn.pixabay.com/photo/2017/08/17/10/47/paris-2650808_960_720.jpg',
        },
        title: 'Paris',
        width: 806,
        height: 720,
    },
];

<ImageView
    images={images}
    imageIndex={0}
    isVisible={this.state.isImageViewVisible}
    renderFooter={(currentImage) => (<View><Text>My footer</Text></View>)}
/>

Props

Prop name Description Type Default value Platform
animationType Type of animation modal presented with "none", "fade", "slide" "none"
backgroundColor Background color of the modal in HEX (#0099CC) string null
controls Config of available controls (see below) Object {close: true}
glideAlways Emulates ScrollView glide animation if built-in was not triggered boolean false Android
glideAlwaysDelay Defines delay in milliseconds for glideAlways number 75 Android
images Array of images to display, see below image item description array []
imageIndex Current index of image to display number 0
isVisible Is modal shown or not boolean false
isTapZoomEnabled Zoom image when double tapped boolean true
isPinchZoomEnabled Zoom image with pinch gesture boolean true
isSwipeCloseEnabled Close modal with swipe up or down boolean true
onClose Function called on modal closed function none
onImageChange Function called when image is changed function none
renderFooter Function returns a footer element function none

Image item:

{
  source: any, // Image Component source object
  width: ?number, // Width of full screen image (optional but recommended)
  height: ?number, // Height of full screen image (optional but recommended)
  // any other props you need to render your footer
}

It's recommended to specify width and height to speed up rendering, overwise component needs to fetch images sizes and cache them in images objects passed as props.

controls prop:

type ControlType = React.Component<{onPress: () => void}> | null | boolean,

{
  close: ControlType // Component for close button in up right corner, as onPress prop accepts function to close modal
  next: ControlType, // Component for next image button, as onPress prop accepts function to scroll to next image
  prev: ControlType, // Component for previous image button, as onPress prop accepts function to scroll to previous image
}

To use default components just set {next: true, prev: true}, close is showing by default. To create custom controls check src/controls.

License

MIT

react-native-image-view's People

Contributors

0x1a1-1 avatar antonkalinin avatar dickerpulli avatar djschilling avatar hunsu avatar jeffraux avatar webjunkie01 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

react-native-image-view's Issues

Infinite Looping

Is there any plan to support looping in the future? Adding a flag with that would be awesome.

VirtualizedList: You have a large list that is slow to update - make sure your renderItem function renders components that follow React performance best practices like PureComponent, shouldComponentUpdate, etc.

Привет!

I have 12 images in the object, and when i swipe image down or up, sometimes i get that message:

VirtualizedList: You have a large list that is slow to update - make sure your renderItem function renders components that follow React performance best practices like PureComponent, shouldComponentUpdate, etc.
Object {
"contentLength": 4937.14306640625,
"dt": 1646,
"prevDt": 1249,
}

types.js missing in 2.0.6

Since version 2.0.6, the types have been moved to types.js, but this file is not published to npm (it's missing in files in the package.json).

In any case, I think publishing the flow syntax import { type ... } from ... might be problematic for apps that are built with e.g. typescript.

viewer without modal

Can the image viewer be called without modal? I would like to use it as a slideshow inside a view.

Listener on image change?

Is there a way to run a function every time the image is changed? It should receive the index of the new image.

Infinite Loop for Image Slider

three

Hey hi,

     Can you provide us Infinite looping of images while we slide through the image slider. Right now when we move to the last image the right arrow hide and again we have to come to my first image by clicking on left arrow vice versa.

Zoom issue when height is bigger than width

First of all, Thanks for the great work! - Really appreciate it!
I have an issue with zooming image

Issue

If the width is bigger than the height, it's working fine.
But if the width is smaller than the height, zooming does not work properly.

Expected Behavior

Zoomed image should locate in the centher of the screen.

Actual Behavior

Zoomed image is automattically going upper side.

###ScreenShot
Simulator Screen Shot - iPhone X - 2019-10-15 at 09 58 59

White as background color in modal

Is it possible to be able to change the background color of the modal from black to white?
I'm working with png drawings that have transparent backgrounds and only black lines and therefor "disappears" in the black modal.

Jumps on first press

i fixed your onGestureMove

i added const justPressed = Math.abs(dy) < PRESS_TOLLERANCE; justPressed ? null : this.imageTranslateValue.y.setValue(y + dy)

`onGestureMove(event: NativeEventType, gestureState: GestureState) {
if (this.isScrolling && this.state.scrollEnabled) {
return;
}

    if (this.currentTouchesNum === 1 && event.touches.length === 2) {
        this.initialTouches = event.touches;
    }

    const {
        images,
        imageIndex,
        imageScale,
        imageTranslate,
        screenDimensions,
    } = this.state;
    const {screenHeight} = screenDimensions;
    const {touches} = event;
    const {x, y} = imageTranslate;
    const {dx, dy} = gestureState;
    const imageInitialScale = this.getInitialScale();
    const {height} = images[imageIndex];

    if (imageScale !== imageInitialScale) {
        this.imageTranslateValue.x.setValue(x + dx);
    }

    // Do not allow to move image vertically until it fits to the screen
    if (imageScale * height > screenHeight) {
        this.imageTranslateValue.y.setValue(y + dy);
    }

    // if image not scaled and fits to the screen
    if (
        scalesAreEqual(imageScale, imageInitialScale) &&
        height * imageInitialScale < screenHeight
    ) {
        const backgroundOpacity = Math.abs(
            dy * BACKGROUND_OPACITY_MULTIPLIER
        );

        const justPressed = Math.abs(dy) < PRESS_TOLLERANCE;
        justPressed ? null : this.imageTranslateValue.y.setValue(y + dy)
        this.modalBackgroundOpacity.setValue(
            backgroundOpacity > 1 ? 1 : backgroundOpacity
        );
    }

    const currentDistance = getDistance(touches);
    const initialDistance = getDistance(this.initialTouches);
    const scrollEnabled = Math.abs(dy) < FREEZE_SCROLL_DISTANCE;
    this.setState({scrollEnabled});
    

    if (!initialDistance) {
        return;
    }

    if (touches.length < 2) {
        return;
    }

    let nextScale = getScale(currentDistance, initialDistance) * imageScale;

    if (nextScale < imageInitialScale) {
        nextScale = imageInitialScale;
    } else if (nextScale > SCALE_MAXIMUM) {
        nextScale = SCALE_MAXIMUM;
    }

    this.imageScaleValue.setValue(nextScale);
    this.currentTouchesNum = event.touches.length;
}`

would be nice if you can check it and add it too...

Modal background opacity to be customized?

Hello, I was able to set the modal background color to white but I wanted to be able to set it to be opaque too. Is that possible? I was checking for opacity options but didn't find any.

[Question] Is this package support carousel

thanks for this package, really great works 👍

I just wondering if this package support carousel, I mean when I press in image, the modal will pop up and when I drag the image left or right, that image will change to another image. Is that possible
?

Modal freezes when swiping down or up at an angle.

My environment:
-iPhone 8
-react-native-cli: 2.0.1
-react-native: 0.52.0
-react-native-image-view: 2.0.10

When I slide down or up at an angle it sometimes freezes the modal. I think it get's confused as if you are trying to close out of the modal or if you are trying to swipe to the next image. It freezes until you hit the 'X' in the upper right-hand corner. I replicated the issue once on the android expo example online, but it took a while to replicate.

My Usage:
<ImageView
images={this.state.images}
imageIndex={this.state.idx}
isVisible={this.state.visible}
animationType='slide'
onClose={()=>this.imageView()}
renderFooter={(currentImage) => (My footer)}
/>

bug: will open again by any onPress event after being closed

After clossing the view by pressing the close button any other onPress event will open the view again. If closed using the back button it won't happen.

Tested in android

Fixed by using:
onClose={() => this.setState({isImageViewVisible: false})}

Can i disable Up & Down Drag to close functional?

drag_down
drag_up

Hey Hi,
Please give me a solution for my above screenshot, I would like to disable the drag up or drag down to close the image view functionality. I want to close the image viewer by clicking the close button hence i dont want this drab up & down functionality. Is there any Props to disable this feature or we can change any line in the ImageView.js

Vertical image not supported?

When I move the vertical image up and down, it shows the error "Error while updating property 'transform' of a view managed by: RCTImageView".
"null"
"translateY"

But if it's a horizontal image, it is fine.

Double tap to zoom

Hey, thanks for this library, looks very promising!

Would be awesome if you can add double tap to zoom.

It seems in the code that there is support for double tap, but I couldn't get it to work [android], even with the example app

Overlapped image in scaled state prevents normal image dragging

Hello,

Test case:

  1. Open example app https://exp.host/@community/image-gallery-example
  2. Tap the top image (first in vertical list)
  3. Swipe right very slowly to see a part of next image
  4. Before releasing hold your finger to make make sure there is no velocity
  5. Release you finger and observe that right image part still visible
    screenshot_20180730-123027
  6. Double tap the left image to enter scaled mode
    screenshot_20180730-123044
  7. Drag image with one finger gesture

Observed:
Image is being dragged only on release, while actual drag it does not move.

Expected:
Image is being dragged normally during dragging.

Additional notes:
Seems this is normal behaviour for react-native FlatList with horizontal orientation and pagingEnabled to not glide when released with zero velocity (I checked this). But from the first testing of your component I noticed that allowing image to stay overlapped on release worsen UX + it prevents normal dragging.

I can provide a pull request to address the overlapping issue if you want.
Thanks for the good component!

Can I pass android Image URI

Right now I can see image view using http link, But I need to pass android Image URI. For example it show image view when the user selects image from Gallery. Is this working right now ?

Hide Panels some time not working & suggest more features.

Hi,

Thanks for your library, it is good library to use for show image in gallery, I have some suggestions, can you update it.

  1. If I am not in debug mode it show this error.
    screenshot_20180727-150413

  2. I can not tap to hide Panels (Header & Footers), I see the togglePanels in your code to know it has hide panels option.

  3. It is better if you implement double Tabs to zoom in/out one level.

Hope you like that updates.

Unexpected token '*' on any version after 2.0.4

After upgrading to the latest version I'm getting the following error:
selection_042

When I run it in debugger mode, It works perfectly.

When I run in a release version, it just closes right away.

I'm using these react versions:
"react": "^16.3.1",
"react-native": "^0.55.4",

I'm developing on Android.

How to enable previous and next buttons

Hi,

Is there any options to enable Next and Previous buttons on zoom image?

I have 4 images and i can able to view previous next and images using swipe option. But i required to place buttons for view previous and next images.

If this options is already there please tell me how can i enable it.

Thanks,
Jayakumar

Apparently a width and height non determined issue

Issue
Here's my render function:

render(){
    return(
      <View style={{flex: 1, backgroundColor: '#f2f2f2'}}>
	<View style={bar.container}>
	  <Text style={{color: '#808080', fontSize: 24}} > Meus Depoimentos </Text>
         </View>
        <ImageView
          images={this.state.galleryPhotos}
          imageIndex={0}
          animationType="fade"
          isVisible={this.state.galleryOpen}
          onClose={() => this.setState({ galleryOpen: false })}/>
    </View>);

And my function that pack images in objects to set in this.state after :

packImages(photos){
    let result = photos.map(p => {
      return { source: { uri: p }} });
    return result;
  }

Close Icon moves up & hide on pressing the image

one
two

Hey hi,
Is there any functionality to disable "CLOSE ICON" moves to top & disappear when we click/press over the image. Again it drop-down when we click/press the image again. Can you provide us a solution, By default the "CLOSE ICON" should be fixed even we click over the image.

Pool hard cap violation?

During normal use after opening a few images I'm getting this error:

Possible Unhandled Promise Rejection (id: 0):
Error: Pool hard cap violation? Hard cap = 150994944 Used size = 150160000 Free size = 0 Request size = 1920000
Error: Pool hard cap violation? Hard cap = 150994944 Used size = 150160000 Free size = 0 Request size = 1920000

From that point on no other image is shown except for the ones I previously opened. Looks like it runs out of memory or something like that?

Switching portrait to landscape mode (or vice versa) fails

  • I start my app in landscape mode
  • the component containing the ImageView is mounted
  • then I switch to portrait mode
  • I open the ImageView

-> The overlay is displayed incorrectly
-> I think the ImageView stores the initial screen dimensions and doesn't recognize a later change of the dimensions due to a switch from portrait to landscape mode

v.2.0.4

Default values for width and height

In V1 we didn't need to specify a height and width of the image to show. In V2 it is specified but it doesn't work if don't specify one. I get the error:

Error while updating property 'transform' of a view managed by: 'RTCImageView'

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.