Socket
Socket
Sign inDemoInstall

react-native-image-cropview

Package Overview
Dependencies
520
Maintainers
1
Versions
1
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

    react-native-image-cropview

A React Native module that allows you to crop photos, built with react native Animated api and react-native-gesture-handler.


Version published
Weekly downloads
7
decreased by-63.16%
Maintainers
1
Created
Weekly downloads
 

Readme

Source

@react-native-image-cropview

A React Native module that allows you to crop photos, built with react native Animated api and react-native-gesture-handler.

AndroidiOS

Getting started

$ npm install react-native-image-cropview --save

or

$ yarn add react-native-image-cropview

Additional steps

If you have react-native-gesture-handler installed ignore this step.

$ npm install react-native-gesture-handler --save

or

$ yarn add react-native-gesture-handler

IOS

No additional step is required.

Android

No additional step is required.

Usage

Import Cropper from react-native-image-cropview:

import { Cropper } from 'react-native-image-cropview';

Create state which will be used to keep the image uri or import from other source

const [imageUri, setImageUri] = useState();

Add Cropper like this:


{
  !!imageUri && (
    <Cropper
      uri={imageUri}
      onDone={onCropDone}
      onCancel={onCropCancel}
      onReset={onReset}
      getImageSize={getImageSize}
    />
  )
}

See Options for further information on options.

If you want to call done/cancel/reset programmatically, pass ref to Cropper:

const cropperRef = useRef();

function done() {
  cropperRef.current.done();
}

function cancel() {
  cropperRef.current.cancel();
}

function reset() {
  cropperRef.current.reset();
}

function getImageSize() {
  // Use any method to find the original image width and height
  return {
    width,
    height
  }
}

return (
  <Cropper
    ref={cropperRef}
    uri={imageUri}
    onDone={onCropDone}
    onCancel={onCropCancel}
    onReset={onReset}
    hideFooter={true}
    getImageSize={getImageSize}
  />
)

See Available Methods for further information.

Done callback will be called with a response object, refer to Response Object.

Options

OptionRequiredDescription
uriYesShow the image specified by the URI param.
getImageSizeYesA method to provide the original image width and height to the cropper. Feel free to use any method to get the original image width and height; Example: https://www.npmjs.com/package/react-native-image-size
onDoneNoCallback invoked when cropping is done
onCancelNoCallback invoked on cancel
onResetNoCallback invoked on cropping reset
aspectRatioNoThe aspect ratio of cropping area: Example: original, 4/3, 2/3, 16/9 ...
roundedNoUse round cropping area
scaleMaxNoMaximum image scale of the image. Example: scaleMax={3} where scale scaleMax <= 20 and scaleMax >= 3
hideFooterNoHide all the cropper actions

Response Object

keyDescription
widthwidth of cropping rectangle relative to the original image size
heightheight of cropping rectangle relative to the original image size
xx position of cropping rectangle relative to the original image size
yy position of cropping rectangle relative to the original image size

Available Methods

MethodDescription
doneProgrammatically call cropping done
cancelProgrammatically call cancel
resetProgrammatically call reset

For more advanced usage check our example app.

FAQs

Last updated on 08 Jun 2022

Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc