Giter Site home page Giter Site logo

repairshopr / react-native-signature-capture Goto Github PK

View Code? Open in Web Editor NEW
962.0 962.0 511.0 1.6 MB

A simple modular component for react native (iOS) to capture a signature as an image

License: MIT License

Objective-C 42.66% JavaScript 12.03% Java 42.64% Ruby 1.87% Starlark 0.80%

react-native-signature-capture's Introduction

react-native-signature-capture

About this

React Native library for capturing signature

User would sign on the app and when you press the save button it returns the base64 encoded png

iOS

Android

Contribution

Contributions are welcome and are greatly appreciated! Every little bit helps, and credit will always be given. Please read our Pull request guidelines before submitting your PR

Install

First you need to install react-native-signature-capture:

npm install react-native-signature-capture --save

Second you need to link react-native-signature-capture:

react-native link react-native-signature-capture

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

iOS

  1. In the XCode's "Project navigator", right click on your project's Libraries folder ➜ Add Files to <...>
  2. Go to node_modules ➜ react-native-signature-capture ➜ ios ➜ select RSSignatureCapture.xcodeproj
  3. Add libRSSignatureCapture.a to Build Phases -> Link Binary With Libraries
  4. Compile and have fun

Android

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

...

include ':reactnativesignaturecapture',':app'
project(':reactnativesignaturecapture').projectDir = new File(settingsDir, '../node_modules/react-native-signature-capture/android')

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

...

dependencies {
    ...
    compile project(':reactnativesignaturecapture') // <-- add this line
}

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

...

import com.rssignaturecapture.RSSignatureCapturePackage; // <-- 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 RSSignatureCapturePackage() // <-- add this line
            );
        }
  }

...
}

Usage

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

...
import React, {Component} from 'react';
import SignatureCapture from 'react-native-signature-capture';

class CustomComponent extends Component {

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

Properties

  • saveImageFileInExtStorage : Make this props true, if you want to save the image file in external storage. Default is false. Warning: Image file will be visible in gallery or any other image browsing app

  • showBorder : If this props is made to false, it will hide the dashed border (the border is shown on iOS only).

  • showNativeButtons : If this props is made to true, it will display the native buttons "Save" and "Reset".

  • showTitleLabel : If this props is made to true, it will display the "x_ _ _ _ _ _ _ _ _ _ _" placeholder indicating where to sign.

  • viewMode : "portrait" or "landscape" change the screen orientation based on boolean value

  • maxSize : sets the max size of the image maintains aspect ratio, default is 500

  • minStrokeWidth : sets the min stroke line width (Android only)

  • maxStrokeWidth : sets the max stroke line width (Android only)

  • backgroundColor: Sets the background color of the component. Defaults to white. May be 'transparent'.

  • strokeColor: Sets the color of the signature. Defaults to black.

Methods

  • saveImage() : when called it will save the image and returns the base 64 encoded string on onSaveEvent() callback

  • resetImage() : when called it will clear the image on the canvas

Callback Props

  • onSaveEvent : Triggered when saveImage() is called, which return Base64 Encoded String and image file path.

  • onDragEvent : Triggered when user marks his signature on the canvas. This will not be called when the user does not perform any action on canvas.

Example

/**
 * Sample React Native App
 * https://github.com/facebook/react-native
 */

var React = require('react');
var ReactNative = require('react-native');

var {Component} = React;

var {
    AppRegistry,
    StyleSheet,
    Text,
    View, TouchableHighlight
} = ReactNative;

import SignatureCapture from 'react-native-signature-capture';

class RNSignatureExample extends Component {
    render() {
        return (
            <View style={{ flex: 1, flexDirection: "column" }}>
                <Text style={{alignItems:"center",justifyContent:"center"}}>Signature Capture Extended </Text>
                <SignatureCapture
                    style={[{flex:1},styles.signature]}
                    ref="sign"
                    onSaveEvent={this._onSaveEvent}
                    onDragEvent={this._onDragEvent}
                    saveImageFileInExtStorage={false}
                    showNativeButtons={false}
                    showTitleLabel={false}
                    backgroundColor="#ff00ff"
                    strokeColor="#ffffff"
                    minStrokeWidth={4}
                    maxStrokeWidth={4}
                    viewMode={"portrait"}/>

                <View style={{ flex: 1, flexDirection: "row" }}>
                    <TouchableHighlight style={styles.buttonStyle}
                        onPress={() => { this.saveSign() } } >
                        <Text>Save</Text>
                    </TouchableHighlight>

                    <TouchableHighlight style={styles.buttonStyle}
                        onPress={() => { this.resetSign() } } >
                        <Text>Reset</Text>
                    </TouchableHighlight>

                </View>

            </View>
        );
    }

    saveSign() {
        this.refs["sign"].saveImage();
    }

    resetSign() {
        this.refs["sign"].resetImage();
    }

    _onSaveEvent(result) {
        //result.encoded - for the base64 encoded png
        //result.pathName - for the file path name
        console.log(result);
    }
    _onDragEvent() {
         // This callback will be called when the user enters signature
        console.log("dragged");
    }
}

const styles = StyleSheet.create({
    signature: {
        flex: 1,
        borderColor: '#000033',
        borderWidth: 1,
    },
    buttonStyle: {
        flex: 1, justifyContent: "center", alignItems: "center", height: 50,
        backgroundColor: "#eeeeee",
        margin: 10
    }
});

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

Please checkout the example folder (iOS/Android): https://github.com/RepairShopr/react-native-signature-capture/tree/master/Example

Library used:

https://github.com/jharwig/PPSSignatureView

https://github.com/gcacace/android-signaturepad

react-native-signature-capture's People

Contributors

6pm avatar adba avatar amyboyd avatar friederbluemle avatar jalada avatar jedt avatar john1jan avatar katanabe avatar legend1991 avatar nikor avatar peaches avatar qimingfang avatar rmevans9 avatar spencewine avatar timothyosborn avatar tom32i 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  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

react-native-signature-capture's Issues

Unable to sign

Hello team,

I have installed then run my app then my screen look this.

image

And unable to sign please help and suggest me.

saveImage method is unavailable

this.refs['sign'] gives an instance of the signature capture component as expected, but this.refs['sign'].saveImage() method is unavailable and logs as undefined.

React.findNodeHandle is not a function

On commit 321a687 imports of React and ReactNative were changed.
A fix for this might be to change line 68 in SignatureCapture.js from:
React.findNodeHandle(this)
to:
ReactNative.findNodeHandle(this)

and the same change for line 78.

Failed to bind EAGLDrawable - Cannot sign

I got this warning when I open the signature component:
Failed to bind EAGLDrawable: <CAEAGLLayer: 0x6000004326e0> to GL_RENDERBUFFER 1

I use these dependencies for my react-native project.
"react": "15.4.2", "react-native": "0.41.2"

The issue is that I can't sign on the signature component. There is no signature shown

Android installation

I'm trying to install on an existing project, and followed the instructions given. I'm running React Native 0.18.0-rc

When trying to launch the app I get the following error:

* What went wrong:
A problem occurred configuring project ':app'.
> Cannot evaluate module reactnativesignaturecapture : Configuration with name 'default' not found.

onSaveEvent is called n+1 times per use

I've implemented react-native-signature-panel in an app that uses the Navigator component to display it as required, and found that the onSaveEvent callback is called +1 times for each time I mount the scene.

Example code:

const React = require('react-native');
const SignatureCapture = require('react-native-signature-capture');

const {
    StyleSheet,
    View,
} = React;

var SignatureInput = React.createClass({
    componentWillUnmount () {
        console.log('UNMOUNTING');
    },
    onSave (result) {
        console.log('ONSAVE');
        this.props.onSave(result);
        this.props.navigator.pop();
    },
    render() {
        return (
            <View style={styles.view}>
                <SignatureCapture onSaveEvent={this.onSave}/>
            </View>
        );
    }
});

var styles = StyleSheet.create({
    view: {
        flex: 1
    },
});

module.exports = SignatureInput;

In the console, the first time the scene is mounted and the onSaveEvent callback fires, everything happens as expected.

The second time, however, ONSAVE is logged twice. Third time, it's logged three times. And so on.

Scrolling Occurs on iOS

First of all, thank you for creating such a useful package. Installation instructions were accurate, and I am getting successful builds on both iOS and Android. On Android, the SignatureCapture component is working as expected, but I am having issues with iOS. When I try to draw my signature in iOS, my screen scrolls up and down and nothing is drawn on the component.

I tried changing the styling a bit, but this doesn't resolve the issue unfortunately. Please let me know what you think, and thank you.

Latest version of the example does not compile

Code issues with BuildConfig.DEBUG which is not defined as well as scope of method enclosing the call to BuildConfig

@OverRide
protected boolean getUseDeveloperSupport() {
return BuildConfig.DEBUG;
}

=> should be marked as "public" as required by Javac.

This being done, the example does not work on Android

Not seeing a xcodeproj

Following the readme instructions for installation and am not seeing the project file within the node module. Am I missing something?

The signature pad is rotated

The signature pad is rotated. It is possible to rotate it with css, but then it will save the signature as rotated as well.

Not working with React Native 0.11.0

Hello. Wondering whether you are having a problem as well. This is the Xcode error I keep getting when the React Native component is invoked...
screen shot 2015-09-23 at 10 00 58 pm 2

Warning when rendering component

I'm trying to integrate this component to my project and I get this warning when rendering the component:

Warning: forceUpdate(...): Cannot update during an existing state transition (such as within `render` or another component's constructor). Render methods should be a pure function of props and state; constructor side-effects are an anti-pattern, but can be moved to `componentWillMount`.

And the component does not render, is there something I forgot?

The signature image is not stored in the folder (Android)

After using the onSaveEvent method, the result correctly return the path and the base64 encoding, however when I navigate to the given path, the save_signature folder is empty (also the image isn't displayed in the gallery)

Using Android with RN v0.40 and component version v0.4.5

Missing **Android** in header

Were it not pointed out to me by my colleague, I would have totally missed out on the Android support. I remember seeing the header description and moving on because I needed one that had support for both the platform (iOS & Android) but the header seemed to suggest support only for iOS.

signature-capture

Not work after react native >= 0.28

1.React.findNodeHandle is not a function
2.getPackages() now is moved into MainApplication, there should be an activity in RSSignatureCapturePackage constructor, what should it be? new RSSignatureCapturePackage(new MainActivity())?

"saveImageFileInExtStorage" prop doesn't work in iOS

The saveImageFileInExtStorage={false} prop should prevent the image from being saved to the file system.

This works correctly on android (see relevant code here).

However, on iOS, the value of the saveImageFileInExtStorage prop seems to be ignored. The image is saved to the file system regardless of its value. Looking at the code, there does not seem to be any conditional logic wrapping the code which saves to the file system (see relevant code here).

Portrait App

I have an app that I want keep in portrait. I was able to rotate and contain the signature component in iOS like so:

screen shot 2016-01-14 at 12 01 18 pm

The issue I'm having is with Android. When running in a Genymotion emulator, the emulator starts freaking out and rotates back and forth until it crashes. I'm guessing this has to do with the Orientation being set by react-native-signature-capture.

Is this something that could be conditional, or simply not done on the assumption the developer could set it themselves?

Build failed

Hello,

After linked the package, I got this error :
I'm using react-native 0.31.0, when I remove the line of my MainApplication the build is ok

capture d ecran 2016-09-06 a 14 54 03

Thanks

onResetEvent

It would be great to be able to access the Reset button press and run a function.

Currently I have a hint I've added over top the signature pad (with pointerEvents='none') to help the user know what to do:

screen shot 2016-01-21 at 9 42 17 am

I remove the hint by wrapping the signature pad in a TouchableWithoutFeedback object and changing the opacity of the hint to 0 when the user starts signing.

It would be great if the hint could reappear when the user hit Reset.

Not a big deal, but could be a nice feature.

Latest Android version does not compile

After doing all the steps on the tutorial I run the following command: react-native run-android

I'm getting this error:

FAILURE: Build failed with an exception.

  • Where:
    Settings file 'C:\myApp\android\settings.gradle' line: 3

  • What went wrong:
    A problem occurred evaluating settings 'myApp'.

Project with path ':react-native-signature-capture' could not be found.

  • Try:
    Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output.

PS: Line 133 is compile project(':reactnativesignaturecapture')

Error: Attempt to invoke virtual method 'int android.app.Activity.getRequestedOrientation()' on a null object reference

Exception in native call java.lang.NullPointerException: Attempt to invoke virtual method 'int android.app.Activity.getRequestedOrientation()' on a null object reference at com.rssignaturecapture.RSSignatureCaptureMainView.<init>(RSSignatureCaptureMainView.java:46) at com.rssignaturecapture.RSSignatureCaptureViewManager.createViewInstance(RSSignatureCaptureViewManager.java:77) at com.rssignaturecapture.RSSignatureCaptureViewManager.createViewInstance(RSSignatureCaptureViewManager.java:18) at com.facebook.react.uimanager.ViewManager.createView(ViewManager.java:44) at com.facebook.react.uimanager.NativeViewHierarchyManager.createView(NativeViewHierarchyManager.java:211) at com.facebook.react.uimanager.UIViewOperationQueue$CreateViewOperation.execute(UIViewOperationQueue.java:148) at com.facebook.react.uimanager.UIViewOperationQueue$2.run(UIViewOperationQueue.java:776) at com.facebook.react.uimanager.UIViewOperationQueue.flushPendingBatches(UIViewOperationQueue.java:829) at com.facebook.react.uimanager.UIViewOperationQueue.access$1500(UIViewOperationQueue.java:44) at com.facebook.react.uimanager.UIViewOperationQueue$DispatchUIFrameCallback.doFrameGuarded(UIViewOperationQueue.java:868) at com.facebook.react.uimanager.GuardedChoreographerFrameCallback.doFrame(GuardedChoreographerFrameCallback.java:32) at com.facebook.react.uimanager.ReactChoreographer$ReactChoreographerDispatcher.doFrame(ReactChoreographer.java:131) at android.view.Choreographer$CallbackRecord.run(Choreographer.java:856) at android.view.Choreographer.doCallbacks(Choreographer.java:670) at android.view.Choreographer.doFrame(Choreographer.java:603) at android.view.Choreographer$FrameDisplayEventReceiver.run(Choreographer.java:844) at android.os.Handler.handleCallback(Handler.java:739) at android.os.Handler.dispatchMessage(Handler.java:95) at android.os.Looper.loop(Looper.java:148) at android.app.ActivityThread.main(ActivityThread.java:5417) at java.lang.reflect.Method.invoke(Native Method) at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:726) at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:616)

Not working on ios

Hi,

I was trying this component on ios simulator.
I am facing few problems here.

  1. It is not coming in the landscape mode even when I set the viewMode value to "landscape"
  2. On save or reset button click it is throwing error.

Below are the screenshots

simulator screen shot 29-nov-2016 7 42 04 pm
simulator screen shot 29-nov-2016 7 43 38 pm

Stroke color changing

Hi,

Is any parameter to change the stroke color?
Or how to change from the source code?

Thanks in advance

Remove dotted line

Hello Team,

I'm using this but facing problem to remove dotted line like

image

For android and iOS both, please suggest
And also need to decode image for web module

Android bug when trying to save blank Signature

I'm having problems when trying to save a blank signature on Android.

It either accepts the blank or returns this error:

Unrecognized signal `RESPONDER_RELEASE` or state `undefined` for Touchable responder `null`

Dotted line does not expand

The dotted signature line does not expand with the width of the signature component as shown in this image.

image

Image sporadically fails to save when using non-native buttons

I'm encountering an issue on iOS in React Native 0.38.0.

I'm finding that while the native buttons work consistently, using the saveImage method with my own buttons fails sporadically and unpredictably; sometimes it will work 3-4 times after first boot, sometimes it won't work at all. Once it has failed, it will fail every subsequent try as well, and resetImage also stops functioning as expected.

I don't know C, but I threw in some logs to try to get a sense of what was happening. The problem seems to occur in RSSignatureView/saveImage where the image apparently fails to save: isSuccess comes up null and the directory where signature.png is saved remains empty.

Happy to provide more information as necessary.

Option to rotate??

Any chance we can get an option to rotate the final signature before saving??

Android support?

Hey guys, love this plugin to bits!
Any chance of one being developed for Android or know anyone who would know to develop one for Android?
Thanks

Save signature as JSON

I've tried decoding the result and converting it to JSON with something similar to:

var str = btoa(result.encoded)
var json = JSON.stringify(eval("(" + str + ")"));

but have had no success getting this to work.

Is it possible to save as JSON so I can save it in Postgres on my backend?

Make dashed signature lines optional

Hi, I want to remove the dashed lines in the signature pad without going in to native code. Something like

<SignatureCapture
    displayDashedBorders={false}
/>

Is it doable?

The resetImage method does not work on iOS.

When calling the resetImage method of the component, this error is thrown:

ExceptionsManager.js:61 React.findNodeHandle is not a function

I was able to fix this by replacing React with ReactNative. But now a new error is thrown, saying:

ExceptionsManager.js:76 Argument 1 (NSInteger) of RCTUIManager.dispatchViewManagerCommand must not be null

It seems that line 76 in SignatureCapture.js (UIManager.RSSignatureView.Commands.resetImage) is returning a null value. With further inspection I found that the UIManager.RSSignatureView.Commands object itself is empty. I am running RN 0.30.0. Any ideas for what could be causing this issue?

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.