1.3.0 • Published 4 months ago

react-native-patternlock-authentication v1.3.0

Weekly downloads
-
License
MIT
Repository
github
Last release
4 months ago

react-native-patternlock-authentication

Pattern Lock Security for both Android and IOS using react native svg.

Featured Pattern Working Gif

Set New Pattern Change Pattern Confirm Pattern

General Pattern Working Gif

General Pattern

Installation

Note: To use this Authentication, ensure that you have react-native-svg and its dependencies (follow this guide).

npm install react-native-patternlock-authentication

Usage

There are two types of PatternLock Available in this Package.

  1. GeneralPatternLock
  2. FeaturedPatternLock

GeneralPatternLock

import { Dimensions } from 'react-native';

// ....

import { GeneralPatternLock } from 'react-native-patternlock-authentication'; // Import Package

const { width, height } = Dimensions.get('window');
const PATTERN_CONTAINER_HEIGHT = height / 2; //you can change it as per your need
const PATTERN_CONTAINER_WIDTH = width; //you can change it as per your need
const PATTERN_DIMENSION = 3; //you can change it as per your need
const CORRECT_UNLOCK_PATTERN = '0123'; //Correct Pattern

// ...

export const App = () => {
  const onPatternMatch = () => {
    // Do your Functionalities
  };

  const onWrongPattern = () => {
    // Do your Functionalities
  };

  const onPatternMatchAfterDelay = () => {
    // Do your Functionalities
  };

  const onWrongPatternAfterDelay = () => {
    // Do your Functionalities
  };

  return (
    //...

    <GeneralPatternLock
      containerDimension={PATTERN_DIMENSION}
      containerWidth={PATTERN_CONTAINER_WIDTH}
      containerHeight={PATTERN_CONTAINER_HEIGHT}
      correctPattern={CORRECT_UNLOCK_PATTERN}
      dotsAndLineColor="blue"
      defaultDotRadius={10}
      snapDotRadius={15}
      snapDuration={100}
      lineStrokeWidth={5}
      wrongPatternColor="red"
      matchedPatternColor="green"
      onPatternMatch={onPatternMatch}
      onWrongPatternAfterDelay={onWrongPatternAfterDelay}
      onPatternMatchAfterDelay={onPatternMatchAfterDelay}
      onWrongPattern={onWrongPattern}

      // ...Use Remaining Props as per your convenience
    />

    //...
  );
};

Props

PropsTypeRequiredDefaultDescription
containerDimensionNumberNo3It Refers the Dimension of the Pattern Dots Array (eg.). 3 means 3 x 3, 4 means 4 x 4.
containerWidthNumberNoDimensions.get('window').width
containerHeightNumberNo(Dimensions.get('window').height)/2
correctPatternStringYes
wrongPatternDelayTimeNumber (MilliSeconds)No1000Pattern draw event disable duration after the Wrong Pattern.
correctPatternDelayTimeNumberNo0Pattern draw event disable duration after the Correct Pattern.
dotsAndLineColorStringNoblue
wrongPatternColorStringNored
lineStrokeWidthNumberNo5Thickness of Line
defaultDotRadiusNumberNo6
snapDotRadiusNumberNo10Snaping radius of Dots When Connecting the Dots.
snapDurationNumberNo100Snaping duration of Dots When Connecting the Dots.
enableHintBooleanNofalse
hintStringNo
hintContainerStyleViewStyleNo
hintTextStyleTextStyleNo{ color: '#000000' }
matchedPatternColorStringNogreen

Methods

onPatternMatch

It will call, when the Pattern is Matched with Correct Pattern.

TypeRequired
functionYes

onWrongPattern

It will call, when the Pattern is Matched with Wrong Pattern.

TypeRequired
functionNo

onPatternMatchAfterDelay

It will call, when the Pattern is Matched with Correct Pattern after the correctPatternDelayTime which is passed as prop by you.

TypeRequired
functionNo

onWrongPatternAfterDelay

It will call, when the Pattern is Matched with Wrong Pattern after the wrongPatternDelayTime which is passed as prop by you.

TypeRequired
functionNo

FeaturedPatternLock

It includes all Pattern Authentication Process like,

  1. Confirm Your Pattern,
  2. Change Pattern
  3. Set New Pattern
import { Dimensions } from 'react-native';

// ....

import {
  FeaturedPatternLock,
  PatternProcess,
} from 'react-native-patternlock-authentication'; // Import Package

const { width, height } = Dimensions.get('window');
const PATTERN_CONTAINER_HEIGHT = height / 2; //you can change it as per your need
const PATTERN_CONTAINER_WIDTH = width; //you can change it as per your need
const PATTERN_DIMENSION = 3; //you can change it as per your need

// ...

export const App = () => {
  const onPatternMatch = () => {
    // Do your Functionalities
  };

  const onWrongPattern = () => {
    // Do your Functionalities
  };

  const onPatternMatchAfterDelay = () => {
    // Do your Functionalities
  };

  const onWrongPatternAfterDelay = () => {
    // Do your Functionalities
  };

  return (
    //...

    <FeaturedPatternLock
      onPatternMatch={onPatternMatch}
      onWrongPattern={onWrongPattern}
      isChangePattern={false}
      processName={PatternProcess.NEW_PATTERN}

      // ...Use Remaining Props as per your convenience
    />

    //...
  );
};

Props

PropsTypeRequiredDefaultDescription
containerDimensionNumberNo3It Refers the Dimension of the Pattern Dots Array (eg.). 3 means 3 x 3, 4 means 4 x 4.
containerWidthNumberNoDimensions.get('window').width
containerHeightNumberNo(Dimensions.get('window').height)/2
correctPatternStringYes - when processName is PatternProcess.CONFIRM_PATTERN. No - when processName is PatternProcess.NEW_PATTERN.
processNameStringNoPatternProcess.NEW_PATTERNPatternProcess Contains two processes. NEW_PATTERN and CONFIRM_PATTERN. processName must be CONFIRM_PATTERN for Change Pattern Process
isChangePatternbooleanNofalseIf the Pattern is working as Change Pattern then change it to true
showHintMessageBooleanNofalse
dotRadiusNumberNo10
dotsColorStringNored
movingLineColorStringNoblue
snapDotRadiusNumberNo15Snaping radius of Dots When Connecting the Dots.
lineStrokeWidthStringNo6
activeLineColorStringNoblue
wrongPatternColorStringNored
snapDurationNumberNo100 (milli seconds)Snaping duration of Dots When Connecting the Dots.
connectedDotsColorStringNoblue
correctPatternColorNumberNogreen
minPatternLengthNumberNo3
newPatternConfirmationMessageStringNoEmpty String
wrongPatternDelayTimeNumberNo1000 (milli seconds)
correctPatternMessageStringNoEmpty String
correctPatternDelayTimeNumberNo1000 (milli seconds)
correctPatternDelayDurationMessageStringNoEmpty String
iswrongPatternCountLimitedBooleanNofalseIf there is maximum limit of Wrong Pattern then change it to true
totalWrongPatternCountNumberNo0If iswrongPatternCountLimited is true then give maximum limit of Wrong Pattern
wrongPatternDelayDurationMessageStringNoEmpty String
minPatternLengthErrorMessageStringNoEmpty String
wrongPatternMessageStringNoEmpty String
changePatternFirstMessageStringNoEmpty String
changePatternDelayTimeNumberNo1000 (milli seconds)
changePatternSecondMessageStringNoEmpty String
isEnableHeadingTextBooleanNofalse
enableDotsJoinVirationBooleanNofalseIf it is true, then the mobile will be vibrate whenever the Pattern Dots Connects (Add Vibration Permissions). Refer React Native Vibration for Permissions.
vibrationPatternArrayNo0, 200Pattern of Vibration for connecting Dots. If enableDotsJoinViration is true then the Mobile Vibrates in this Pattern Refer React Native Vibration
headingTextStringNoEmpty String
enablePatternNotSameConditionBooleanNotrueIf It is true, then the previous Pattern is not allowed for new Pattern when the time of Change Pattern Process. Change it to false, if the Previous Pattern is also allowed for New Pattern
patternTotalCountReachedErrorMessageStringNoEmpty String
newPatternDelayDurationMessageStringNoEmpty String
newPatternMatchedMessageStringNoEmpty String
newPatternDelayTimeNumberNo1000 (milli seconds)
patternCountLimitedErrorMessageStringNoEmpty String
samePatternMatchedMessageStringNoEmpty String
hintTextStyleTextStyleNo{ color: 'blue' }
headingTextStyleTextStyleNo{ color: 'blue' }
hintTextContainerStyleViewStyleNo{ alignItems: 'center' }

Methods

onPatternMatch

It will call, when the Pattern is Matched with Correct Pattern. It will also called after the Confirm Pattern of Set Pattern Process. It returns pattern as callback Parameters.

TypeRequired
functionYes

onWrongPattern

It will call, whenever the Pattern is Matched with Wrong Pattern. It returns pattern and wrongPatternRemainingCount ( if enable iswrongPatternCountLimited ) as callback Parameters.

TypeRequired
functionNo

onPatternMatchAfterDelay

It will call, when the Pattern is Matched with Correct Pattern after the correctPatternDelayTime which is passed as prop by you. It will also called after the Confirm Pattern of Set Pattern Process. It returns pattern as callback Parameters.

TypeRequired
functionNo

onWrongPatternAfterDelay

It will call, when the Pattern is Matched with Wrong Pattern after the wrongPatternDelayTime which is passed as prop by you. It returns pattern and wrongPatternRemainingCount ( if enable iswrongPatternCountLimited ) as callback Parameters.

TypeRequired
functionNo

License

MIT

Would you like to support me?

1.3.0

4 months ago

1.2.4

2 years ago

1.2.3

2 years ago

1.2.2

2 years ago

1.2.1

2 years ago

1.2.0

2 years ago

1.1.0

2 years ago

0.1.0

2 years ago

1.0.0

2 years ago