GithubHelp home page GithubHelp logo

attyou / react-native-photo-view-ex Goto Github PK

View Code? Open in Web Editor NEW

This project forked from amarcruz/react-native-photo-view-ex

0.0 0.0 0.0 554 KB

Pinch-to-zoom view for React Native (both iOS and Android)

License: MIT License

JavaScript 13.73% Java 37.32% Python 3.51% Objective-C 44.43% Ruby 1.01%

react-native-photo-view-ex's Introduction

react-native-photo-view-ex

License npm Version

Provides custom Image view for React Native that allows to perform pinch-to-zoom on images. Works on both iOS and Android.

This component uses PhotoDraweeView for Android and MWPhotobrowser on iOS.

About this fork

This fork is based on the great work of @alwx (Alexander Pantyuhov) and has this changes:

  • Android Build Tools 28.0.3 and targetSdkVersion 28 (configurable).
  • Peer dependent on react-native v0.57 and above.
  • Using the same version of fresco included by react-native.
  • Updated dependencies
  • Changes to gradle config to support the new version.
  • Changes to some properties, mainly androidScaleType replaced by resizeMode.
  • PhotoView as PureComponent.
  • Minor fixes.
  • Typescript definitions.

All this is to adapt it better to my current project (it is not tested on iOS), but feel free to use it.

Usage

import PhotoView from 'react-native-photo-view-ex';

Basics:

  <PhotoView
    source={{uri: 'https://facebook.github.io/react/img/logo_og.png'}}
    minimumZoomScale={0.5}
    maximumZoomScale={3}
    resizeMode="center"
    onLoad={() => console.log("Image loaded!")}
    style={{width: 300, height: 300}}
  />

Properties

Property Type Description
source Object The same as source for other React images, except that it does not handle arrays.
loadingIndicatorSource Object Similarly to source, but used to render the loading indicator. Must be a local image
fadeDuration int Duration of the fade, in milliseconds.
scale float Zoom scale
maximumZoomScale float The maximum allowed zoom scale. The default value is 3.0
minimumZoomScale float The minimum allowed zoom scale. The default value is 1.0
resizeMode String Android only: One of "center", "contain", "cover", "fitStart", "fitEnd", "stretch". The default is "cover"
style Array or Object Subset of react-native style. See index.d.ts
showsHorizontalScrollIndicator bool iOS only: When true, shows a horizontal scroll indicator. The default value is true.
showsVerticalScrollIndicator bool iOS only: When true, shows a vertical scroll indicator. The default value is true.
zoomTransitionDuration int Android only: Double-tap zoom transition duration, in milliseconds.

Events

Name Parameter * Description
onError - Invoked on load error.
onLayout layout: {x, y, width, height} Invoked on mount and layout changes.
onLoad - Invoked when load completes successfully.
onLoadEnd - Invoked when load either succeeds or fails.
onLoadStart - Invoked on load start.
onProgress loaded, total iOS only: Invoked on download progress.
onScale scale, scaleFactor, focusX, focusY Callback function called on scale changes.
onTap scale, x, y Callback function called on image tap.
onViewTap scale, x, y Callback function called on tap outside of the image.

* In the nativeEvent property.

react-native-image-zoom functionality is similar, but there are several major differencies:

  • PhotoView is based on PhotoDraweeView which is the "PhotoView For Fresco". It works better, it supports several important callbacks out-of-box and it is, actually, recommended by Chris Banes, because his PhotoView (base for react-native-image-zoom) doesn't completely support Facebook Fresco.
  • PhotoView has more options like fadeDuration and minimumZoomScale/maximumZoomScale and more important callbacks.
  • PhotoView is written in the same manner as default React Image, and it supports most of the features Image has (the goal is to be fully compaitable with Image and support absolutely everything).
  • It is possible to use PhotoView as a container (currently iOS only)!

Automatic installation

Just two simple steps:

yarn add react-native-photo-view-ex
react-native link react-native-photo-view-ex

Manual installation

Android

  1. Add these lines to android/settings.gradle

    include ':react-native-photo-view-ex'
    project(':react-native-photo-view-ex').projectDir = new File(rootProject.projectDir, '../node_modules/react-native-photo-view-ex/android')
  2. Add the dependency to android/app/build.gradle

    dependencies {
      implementation project(':react-native-photo-view-ex')
    }
  3. Register PhotoViewPackage in your MainApplication.java:

    import io.amarcruz.photoview.PhotoViewPackage;
    
    // ...
    
    public class MainActivity extends ReactActivity {
      // ...
    
      @Override
      protected List<ReactPackage> getPackages() {
        return Arrays.<ReactPackage>asList(
            new MainReactPackage(),
            new PhotoViewPackage() // add this manager
        );
      }
    
      // ...
    }

iOS

  1. Add this line to your podfile

    pod 'react-native-photo-view-ex', path: '../node_modules/react-native-photo-view-ex'
    
  2. Run pod install

react-native-photo-view-ex's People

Contributors

alwx avatar amarcruz avatar enriquefynn avatar thorbenandresen avatar doochik avatar lprhodes avatar ozby avatar zeljkox avatar greedbell avatar cornedor avatar corymsmith avatar dxiao avatar jensdebergh avatar itjesse avatar jadbox avatar laur3y avatar knowbody avatar maraujop avatar moox avatar radko93 avatar vandervidi avatar ivks avatar fschai89 avatar lisitaeugen avatar edwardgalligan avatar pkwak-sf avatar sagexy avatar

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.