Git Product home page Git Product logo

dev-yakuza / react-native-image-modal Goto Github PK

View Code? Open in Web Editor NEW
430.0 7.0 40.0 71.11 MB

the simple image modal for React Native

Home Page: https://dev-yakuza.github.io/en/react-native/react-native-image-modal/

License: MIT License

JavaScript 2.64% Java 24.95% Objective-C 3.90% Ruby 2.07% TypeScript 45.61% Starlark 0.98% Makefile 2.49% C++ 11.39% Objective-C++ 5.96%
react react-native react-native-ui image-modal

react-native-image-modal's Introduction

react-native-image-modal

react-native-image-modal is a simple full size modal image for iOS and Android.

You can pinch zoom-in/out, double-tap zoom-in/out, move and swipe-to-dismiss.

Document

Expo

This library does not support Expo anymore. Because this library uses react-native-fast-image.

1.0.16 is deprecated, but the version supports Expo.

npm install --save [email protected]

Blog

There are blog posts about how to use react-native-image-modal.

Installation

This library use react-native-fast-image, so you need to install it.

npm install --save react-native-fast-image
npx pod-install

And then execute the command to install react-native-image-modal.

npm install --save react-native-image-modal

How to use

Import react-native-image-modal.

import ImageModal from 'react-native-image-modal';

Add the source code below to where you want to use it.

return (
  <ImageModal
    resizeMode="contain"
    imageBackgroundColor="#000000"
    style={{
      width: 250,
      height: 250,
    }}
    source={{
      uri: 'https://cdn.pixabay.com/photo/2019/07/25/18/58/church-4363258_960_720.jpg',
    }}
  />
);

Properties

You can use All props of React Native Image for the original image(not full size modal image). Below are react-native-image-modal specific properties.

Prop required Type Description
renderToHardwareTextureAndroid X boolean It is for Android animation. Default is true. If you don't want to use Hardware Texture on Android, set false.
isTranslucent X boolean if you use translucent status bar in android, set true to prevent wrong position animation. (In Expo, translucent default is true)
swipeToDismiss X boolean set true to swipe to dismiss (default: true)
imageBackgroundColor X string background color for the original image
overlayBackgroundColor X string background color for the full size modal(default: #000000)
modalRef X ImageDetail You can use this Ref for closing the Modal programmatically.
disabled X boolean disable opening the modal
modalImageStyle X ImageStyle Image Style in Modal
resizeMode X ResizeMode('contain', 'cover', 'stretch','center') Image resizeMode
modalImageResizeMode X ResizeMode('contain', 'cover', 'stretch','center') Image resizeMode for modal image. If it is not passed, it will follow the resizeMode.
hideCloseButton X boolean hide hide the default close button
onLongPressOriginImage X () => void long press event callback for the original image
renderHeader X (close: () => void) => JSX. You can customize the header of the full size modal with react native components
renderFooter X (close: () => void) => JSX. You can customize the footer of the full size modal with react native components
isRTL X boolean You can use this library with right-to-left-devices. (#35)
onTap X (eventParams: {locationX: number; locationY: number; pageX: number; pageY: number;}) => void one tap event callback for the full size modal
onDoubleTap X () => void double tap event callback for the full size modal
onLongPress X () => void long press event callback for the full size modal
onOpen X () => void open event callback for the full size modal
didOpen X () => void event callback after open for the full size modal
onMove X (position: {type: string; positionX: number; positionY: number; scale: number; zoomCurrentDistance: number;}) => void move event callback for the full size modal
responderRelease X (vx?: number, scale?: number) => void responder release event callback for the full size modal
willClose X () => void event callback before close for the full size modal
onClose X () => void close event callback for the full size modal

Demo

  • Open and close the image modal.

open and close image modal

  • Pinch zoom in/out and move.

pinch zoom in/out and move

  • Double tap zoom in/out.

double tap zoom in/out

  • Swipe to dismiss.

swipe to dismiss

  • Customize the component with the close button.

customize the component

Example code

You can see the example code and demo.

Clone the repository

git clone https://github.com/dev-yakuza/react-native-image-modal.git

Install libraries

cd Example
npm install

# iOS
cd ios
pod install

Execute the example project.

# Example folder
# iOS
npm run ios
# Android
npm run android

Contribute

You can follow below to contribute react-native-image-modal.

Clone the repository.

git clone https://github.com/dev-yakuza/react-native-image-modal.git

Install libraries and Lefthook.

npm install
npx @arkweid/lefthook install

Execute the following command to start the project.

npm start

Execute the Develop project via the commands below.

cd Develop
npm install

# android
npm run android

# ios
cd ios
pod install
cd ..
npm run ios

react-native-image-modal's People

Contributors

alessiocancian avatar andreialecu avatar dependabot[bot] avatar dev-yakuza avatar diaazzawi 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  avatar  avatar  avatar

react-native-image-modal's Issues

Image in modal is blur in Android

Description

Hi there! I am using this package inside my app project. The function is working perfectly inside iOS, while in Android the image is blurred inside the modal when I click the image and open it. Does anyone encounter this issue? How do you solve it? Appreciate any help or suggestion.

Background

Working or not:

✅ iOS simulators
✅ iOS real devices
❌ Android emulators
❌ Android real devices


Codes

<ImageModal resizeMode="contain" source={{ uri: imageUrl }} style={{ height: 100, width: 100 }} />

package.json

...
"react": "16.11.0",
"react-native": "0.62.2",
"react-native-fast-image": "8.3.4",
"react-native-image-modal": "2.0.3",
...

The screenshot

image

Android Only - Images when opened are blurry

When any image is opened, the quality of the image drops. The image is blurry and doesnt appear right. Currently this issue is only on android, is this being faced by anyone else as well?

  • Using latest version of the package
  • React native version 0.63.4

Animation problem on Expo

I started using your lib and it works perfectly on bare react native.

Sadly, I need to use expo and I found a small bug: When closing the modal, the animation stops a few pixels below the starting point, freezes there a few milliseconds, and teleports to its original position.

See the following GIF:
image-modal-bug

Steps to reproduce:

  • Start a new expo project with expo init
  • Copy the code from the example and paste it in your new project App.js (removing jsx related anotations if needed).
  • Start the project on emulator or real device with expo start

The same code works perfectly on the same emulator when using only react native and not expo.

Hope you will be able to find a fix!

`useNativeDriver` was not specified. This is a required option and must be explicitly set to `true` or `false`

Warning: useNativeDriver was not specified. This is a required option and must be explicitly set to true or false

This warning was displayed when i updated expo to version 38.0.0

"expo": "^38.0.0",
"react-native": "https://github.com/expo/react-native/archive/sdk-38.0.0.tar.gz",
"react-native-image-modal": "^1.0.8",

It still works, but it would be nice to fix it. This parameter must have become required in the most recent version of react native.

question about performance

Hi, do you ever test the performance, because i saw each image = (animatedview + modal), it's required more view hierarchy structure.

I have large list of image, display as GridView, if I used react-native-image-modal, does it's took a lot of performance in my situation? Thanks

modalImageStyle doesn't works

hello guys,

my code:
<ImageModal
resizeMode="cover"
modalImageResizeMode="contain"
overlayBackgroundColor={colors.black}
imageBackgroundColor={colors.primary}
style={{ width: 45, height: 45 }}
modalImageStyle={{ width: 800, height: 800 }}
source={
uri
? { uri: uri }
: require('@assets/images/without-user-profile.jpeg')
}
onLoad={() => setShowShimmer(true)}
/>

what's happening:
my image has 45px of width and height when is outside modal, when I click at the image, it does not open with 800px like I put in modalImageStyle, it continues with 45px, but stretched

Zoom under fingers

Right now, the zoom works quite well but can feel counter intuitive when zooming at details not in the image's center.

Desired behavior:
When using pinch-to-zoom, zoom under fingers and allow image panning while holding with two fingers.

Current behavior:
When using pinch-to-zoom, the image zooms at the center of the screen, which is not necessarily where the user has its fingers.

[Android] Malformed calls from JS: field sizes are different

RN version: 0.63.2
react-native-image-modal version: ^1.0.16

Hi! I'm having this issue only in Android when I press in the image and try to open the modal
image

And in console the error says:
image

It's only happening on Android, in iOS works fine. Do you know why it could be? Thanks

Almost there

First, thank you for this repo! A few things I've noticed:

1.- When you tap the image, it flickers first
2.- The pinch-to-zoom is still a bit buggy
3.- I'd like to be able to adjust the speed - and perhaps the easing - when you release the image

My goal is to try and replicate the behavior that you get on Apple News. So yes, you're almost there!!

ResizeMode for Modal Image

Hey, I really like this library and I am currently using it in my react native application.

The thing I want to achieve is to have my Viewable Image with resizeMode cover while the Image Modal to have a different resizeMode, like contain.

is there any possible way to achieve this?

i can't interative with custom renderFooter

I'm trying to use TouchableOpacity of react-native-gesture-handler and the onPress function never work.

With react-native button works, but i need the other component.

i'm using:

  • React Native 0.68.1
  • react-native-image-modal 2.0.4
  • react-native-gesture-handler 2.4.1

modalImageResizeMode not working

Hi, I am trying to use modalImageResizeMode, but it doesn't work. It copies the behavior of resizeMode. I believe it's because I am using expo. Do you have any plans to fix it for expo? Thank you.
Here is my code
<ImageModal resizeMode="cover" modalImageResizeMode="contain" imageBackgroundColor="#000000" style={{ width: width, height: 250, }} source={{uri: file.item.path}} />

RTL Support

This is a very nice library but, unfortunately, it has a bug in right-to-left (RTL) devices. This is my scenario:

  1. Device language is Arabic (RTL).
  2. I have tow images side by side.
  3. If I open the left image then close the ImageModal, the image animates to the right spot then adjusts itself to the correct position (left spot), which is funny. The opposite happens when opening and closing the right image. What I expect is closing the modal of any of the images should animate to the correct position.

I would really love to have a solution for this issue as soon as possible. Any quick workaround is also appreciated.

Thanks for this great library!

Invariant Violation: Tried to register two views with the same name FastImageView

Hello,

  • ERROR Invariant Violation: Tried to register two views with the same name FastImageView
  • ERROR Invariant Violation: Module AppRegistry is not a registered callable module (calling runApplication). A frequent cause of the error is that the application entry file path is incorrect. This can also happen when the JS bundle is corrupt or there is an early initialization error when loading React Native.
  • ERROR Invariant Violation: Module AppRegistry is not a registered callable module (calling runApplication). A frequent cause of the error is that the application entry file path is incorrect. This can also happen when the JS bundle is corrupt or there is an early initialization error when loading React Native.

i have installed fastimage package with latest version,
and then today i try this package, starting metro as usual and it goes to error

Styling issue for model image

Hi, first of all library is great and works smooth.
Now I cam across an issue in the scenario where origin image is round (has border radius) so model image opens complete and in square or rectangle form that's fine too, but when its closing with animation of square and when it reaches origin we see a jerk where model small size image is rectangle and then origin comes with border radius.
For the time being I applied borderRadius to modelImageStyle and it now closes with circle so removes that jerk but issue is that model image now has border radius, attaching ScreenShot for reference.
Simulator Screen Shot - iPhone 8 - 2021-12-09 at 13 10 50

Multiple image slider

The zoom functionality works flawlessly and much better compared to other image slider libraries available out there

Can you please add the functionality of multiple images

Use auto height

Hello @dev-yakuza,

Is there an option or what is the best way to use auto height ?
We want to show the image at 100% width with height based on the image.

about image style size and resizeMode

I am going to make 40x40 image.

<ImageModal style={{width: 40, height: 40}} />

However, if do this, the quality of the picture becomes extremely poor in modal image like a forced extension of a 40x40 image.

  • Can the original image size be 40x40 while maintaining the quality of the modal image?
  • And can I set the reziseMode props of the original image and the modal image differently?

Closing the full modal

How do i programmatically close the full screen view without having to tap the X ?
<ImageModal ref = {ref => this.previewBox = ref}...
this.previewBox.close() or something ?

Image not rendering?

Hey, tried to use this lib, seemed exactly what I need... but for some reason it is not loading the image...

Here is my code:

<ImageModal
    resizeMode="contain"
    imageBackgroundColor="#000000"
    style={{
     height: 300, borderRadius: 15
}}
    source={{
        uri: converted,
    }}
/>
                                            <Image style={{
                                                    height: 300, borderRadius: 15
                                                }}
                                                source={{
                                                    uri: converted,
                                                }}/> 

Result:

Simulator Screen Shot - iPhone 11 - 2020-08-29 at 14 22 41

Add test code

There is no test code. Let's try to add test code.

Cannot interact with renderHeader and renderFooter

I can't click on Tounchopacity
instead of clicking tounchopacity it is zoomed
<ImageModal
isTranslucent={false}
resizeMode="contain"
imageBackgroundColor={COLORS.background}
overlayBackgroundColor="rgba(0,0,0,0.3)"
source={item.picture_url}
renderFooter={(onClose) => (
<TouchableOpacity
onPress={onClose}
style={{
backgroundColor: '#FFFFFF',
height: 100,
justifyContent: 'center',
alignItems: 'center',
}}>
CloseButton

)}
/>

Add modalRef open method

I can't open programmatically, I see close function only, is it possible to add open function too?

Origin Image Border Radius

Hi there. How would we go about adding a border radius to the origin image? Seems like something with the background is preventing the entire component from inheriting the radius.

Quickly flicking on a modal item on list causes momentum zoom glitch

Basically, when you have a react-native-image-modal item on a flatlist, there is always the risk that the user would scroll so fast it's almost tapping, and this triggers both opening of the modal, and momentum scrolling of the list.

As a result the item animates back to the wrong position on the list because the list moved while it was fullscreen.

A potentially easy workaround could be exposing a modal close method so the modal could be dismissed when the list scrolls - ideally it wouldn't register both tap and scroll events at the same time (not sure why this happens)

Image orientation

Image opened in potrait mode does not change to landscape when device rotated.it is locked in potrait mode.

Current behaviour: image clicked in potrait mode take full screen.it remains in potrait even device is rotated.

Expected behaviour: image rotate with the device rotation.

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.