npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

react-native-cropper-tool

v1.0.1

Published

image cropper tool for react-native

Downloads

6

Readme

React Native Cropper Tool

npm version npm downloads

React Native Cropper Tool for Android

NOTE: The iOS side of this module will be included when i have figured it out.

Installation

First you need to install react-native-cropper-tool:

npm install react-native-cropper-tool --save
or 
yarn add react-native-cropper-tool

Second you need to link react-native-cropper-tool:

react-native link react-native-cropper-tool

Use above react-native link command to automatically complete the installation, or link manually like so:

Android

Add these lines in your file: android/settings.gradle

...

include ':react-native-cropper-tool'
project(':react-native-cropper-tool').projectDir = new File(rootProject.projectDir, '../node_modules/react-native-cropper-tool/android')

Add line in your file: android/app/build.gradle

...

dependencies {
    ...
    compile project(':react-native-cropper-tool') // <-- add this line
}

Add import and line in your file: android/app/src/main/java/<...>/MainApplication.java

...

import com.emekalites.rcropper.tool.CropperToolPackage; // <-- add this import

public class MainApplication extends Application implements ReactApplication {

    private final ReactNativeHost mReactNativeHost = new ReactNativeHost(this) {

        @Override
        protected List<ReactPackage> getPackages() {
            return Arrays.<ReactPackage>asList(
                new MainReactPackage(),
                new CropperToolPackage() // <-- add this line
            );
        }
  }

...
}

Usage

Then you can use CropperToool component in your react-native's App, like this:

...
import React, { Component } from 'react';
import ImageCropperTool from 'react-native-cropper-tool';

class CustomComponent extends Component {

  ...
  render() {
    return (
      <ImageCropperTool
        {...someProps}
      />
    );
  }
}

Properties

  • source : image url

  • folderName : Name of folder where images will be stored could be the name of your application.

Methods

  • cropImage() : when called it will crop the image, save the image and return the file path of the cropped image on onCrop() callback

Callback Props

  • onCrop : Triggered when cropImage() is called and also if there is any exception.

Callback Response

  • Object : returns an object after the onCrop callback. { uri: 'cropped image path or empty string', error: 'error if available or empty string' }

Example


import React, { Component } from 'react';
import { View, TouchableHighlight, Text, StyleSheet, PermissionsAndroid, Dimensions, Image } from 'react-native';
import ImageCropperTool from 'react-native-cropper-tool';

const APP_NAME = "Image Cropper";
const { width } = Dimensions.get('window');
const uri = "http://www.hippieshop.com/mas_assets/adrotator/599.jpg";

class CropperToolExample extends Component {
	constructor(props, context) {
		super(props, context);
		this.state = {
			permitted: false,
			h: 0,
			w: 0,
		};
	}
	
	requestStoragePermission = async () => {
		let p1, p2 = false;

        try {
            const grantedRead = await PermissionsAndroid.request(
                PermissionsAndroid.PERMISSIONS.READ_EXTERNAL_STORAGE,
                {
                    'title': `${APP_NAME} Read Storage Permission`,
                    'message': `${APP_NAME} needs access to read your storage.`
                }
            )
            p1 = grantedRead === PermissionsAndroid.RESULTS.GRANTED;
        } catch (err) {
            console.warn(err);
        }

        try {
            const grantedWrite = await PermissionsAndroid.request(
                PermissionsAndroid.PERMISSIONS.WRITE_EXTERNAL_STORAGE,
                {
                    'title': `${APP_NAME} Write Storage Permission`,
                    'message': `${APP_NAME} needs access to write to your storage.`
                }
            )
            p2 = grantedWrite === PermissionsAndroid.RESULTS.GRANTED;
        } catch (err) {
            console.warn(err);
		}
		
		if(p1 && p2){
			this.setState({ permitted: true });
		}
	}
	
	componentWillMount() {
		this.requestStoragePermission();
		Image.getSize(uri, (wt, ht) => {
			const aspectRatio = width / wt;
			const h = aspectRatio * ht;
			this.setState({ w: width, h });
		});
	}
	
    cropImage = () => this.crop.cropImage();

    _onCrop = (result) => {
		//result.uri - for the file path uri
        //result.error - for the eror message
		alert(JSON.stringify(result));
		this.setState({ cropImage: result.uri });
    }
	
	render() {
		const { permitted, h, w, cropImage } = this.state;
		return (
			permitted ? 
				<View style={{ flex: 1 }}>
					<View style={{width: w, height: h}}>
						<ImageCropperTool
							ref={ref => {
								this.crop = ref;
							}}
							source={uri}
							folderName="Cropper"
							onCrop={this._onCrop}
						/>
					</View>
					<View style={{padding: 8}}>
						<TouchableHighlight style={styles.buttonStyle} onPress={() => this.cropImage()}>
							<Text>Crop Image</Text>
						</TouchableHighlight>
					</View>
					<View>
						<Image
							resizeMode={'contain'}
							source={{uri: cropImage}}
							style={{width: 200, height: 200}}
						/>
					</View>
				</View> : 
				<View style={{ flex: 1 }}>
					<Text>Waiting for permission</Text>
				</View>
		);
	}
}

const styles = StyleSheet.create({
    buttonStyle: {
        alignItems: "center", height: 50,
        backgroundColor: "#eeeeee",
        margin: 10
    }
});

AppRegistry.registerComponent('CropperToolExample', () => CropperToolExample);

Library used:

https://github.com/ArthurHub/Android-Image-Cropper