Installations
npm install react-native-onetapinput
Developer Guide
Typescript
Yes
Module System
CommonJS
Node Version
20.9.0
NPM Version
10.1.0
Releases
Unable to fetch releases
Contributors
Unable to fetch Contributors
Developer
ReactMaverick
Download Statistics
Total Downloads
1,001
Last Day
2
Last Week
10
Last Month
47
Last Year
1,001
GitHub Statistics
2 Stars
7 Commits
1 Watching
1 Branches
1 Contributors
Bundle Size
5.17 kB
Minified
2.23 kB
Minified + Gzipped
Package Meta Information
Latest Version
1.5.1
Package Id
react-native-onetapinput@1.5.1
Unpacked Size
77.70 kB
Size
16.74 kB
File Count
46
NPM Version
10.1.0
Node Version
20.9.0
Publised On
09 Nov 2024
Total Downloads
Cumulative downloads
Total Downloads
1,001
Last day
100%
2
Compared to previous day
Last week
-23.1%
10
Compared to previous week
Last month
4.4%
47
Compared to previous month
Last year
0%
1,001
Compared to previous year
Daily Downloads
Weekly Downloads
Monthly Downloads
Yearly Downloads
Peer Dependencies
3
Dev Dependencies
3
OneTapInput and ResendOTPButton Components
The OneTapInput and ResendOTPButton are custom, reusable components for React-Native applications. They are designed to handle OTP (One Time Password) input and resend OTP functionality respectively. This component utilizes the react-native-otp-verify
component for OTP Autofill functionality.
Prerequisites
Before you can use the OneTapInput and ResendOTPButton components, you need to install the react-native-otp-verify
package. You can do this by running the following command in your terminal:
1npm install react-native-otp-verify
or if you are using yarn:
1yarn add react-native-otp-verify
▶️ View Live on Expo Snack ▶️
Usage
Permissions: Android
Before using the OneTapInput and ResendOTPButton components on android, you need to add the following permissions in your AndroidManifest.xml file for otp verify to work:
1<uses-permission android:name="android.permission.RECEIVE_SMS" /> 2<uses-permission android:name="android.permission.READ_SMS" />
Hash Code During Development
For otp auto verify to work, you need to format the incoming sms in this way: <#> Your Otp is: 123ABC78. Use this code to log in. YOURHASHCODE <#> You have to replace YOURHASHCODE with the hash code you are getting from getHashCode function.
Hash Code During Production
To generate the hash code for production, you need to follow these steps:
-
Obtain the SHA-256 certificate fingerprints for your app. You can do this by running the following command in your terminal:
1keytool -list -v -keystore my-release-key.keystore
Replace my-release-key.keystore with the path and name of your actual keystore file.
-
Once you have the SHA-256 certificate fingerprint, you can use it to generate your app's hash string. The hash string is created by concatenating your app's package name with the SHA-256 certificate, and then applying a specific algorithm to it. You can use an online tool like this one provided by Google to generate the hash string. You can use an online tool like this one provided by Google to generate the hash string.
-
After generating the hash string, replace YOURHASHCODE in the SMS format with this hash string. Please note that the hash code for debug and release versions will be different due to the different signing keys used.
1// If you are using js/jsx instead of ts/tsx, remove the types. (i.e.: <string>, :string, type declaration/s). 2import { useState } from "react"; 3import { OneTapInput, ResendOTPButton } from "react-native-onetapinput"; 4 5const App = () => { 6 const [hash, setHash] = useState<string[]>([]); 7 const [otp, setOtp] = useState<string>(""); 8 9 return ( 10 <> 11 <OneTapInput 12 getFinalOtp={(otp: string) => { 13 console.log("Final OTP: ", otp); 14 setOtp(otp); 15 }} 16 getHashCode={(hash: string[]) => { 17 console.log("Hash code ===> ", hash); 18 setHash(hash); // The hash to be used in the SMS receiver app format: <#> Your Otp is: 123ABC78. Use this code to log in. YOURHASHCODE <#> (You have to place the hashcode at the end of your sms) 19 }} 20 /> 21 <ResendOTPButton 22 onResendOtp={() => { 23 // Handle Resend OTP Logic 24 }} 25 /> 26 </> 27 ); 28}; 29 30export default App;
Reference Image
Props
The OneTapInput component accepts the following props (Important & useful props are shown first and are in bold) [All props are optional]:
-
getHashCode
: Function to get the hash code for the OTP message.-
Usage:
1<OneTapInput 2 //.... Other Props 3 getHashCode={(hash: string[]) => { 4 console.log("Hash code ===> ", hash); 5 setHash(hash); // The hash to be used in the SMS receiver app format: <#> Your Otp is: 123ABC78. Use this code to log in. D2GX4obkbds <#> 6 }} 7 //... Other Props 8/>
-
-
otpCount
: Number of OTP digits.-
Usage:
1<OneTapInput 2 //.... Other Props 3 otpCount={4} // Default is 6 4 //... Other Props 5/>
-
-
getFinalOtp
: Function to get the final OTP value.-
Usage:
1<OneTapInput 2 //.... Other Props 3 getFinalOtp={(otp: string) => { 4 console.log("Final OTP: ", otp); // You will get the final OTP here 5 }} 6 //... Other Props 7/>
-
-
value
: Initial value of the OTP input.-
Usage:
1<OneTapInput 2 //.... Other Props 3 value="123456" 4 //... Other Props 5/>
-
-
otpType
: Type of OTP. It can be 'number', 'alpha', 'alphanumeric', or 'custom'.-
Usage:
1<OneTapInput 2 //.... Other Props 3 otpType="alphanumeric" // Default is number 4 //... Other Props 5/>
-
-
handleOtpChange
: Function to call when the OTP changes.-
Usage:
1<OneTapInput 2 //.... Other Props 3 handleOtpChange={(otp: string) => { 4 console.log("OTP: ", otp); // You will get the changed OTP here 5 }} 6 //... Other Props 7/>
-
-
hiddenText
: Boolean to hide/show the OTP text.-
Usage:
1<OneTapInput 2 //.... Other Props 3 hiddenText={true} // Default is false 4 //... Other Props 5/>
-
-
error
: Boolean to indicate if there is an error.-
Usage:
1<OneTapInput 2 //.... Other Props 3 error={true} // Default is false 4 //... Other Props 5/>
-
-
errorText
: Error text to display below the OTP Input component.-
Usage:
1<OneTapInput 2 //.... Other Props 3 errorText="Invalid OTP" // If error is true and errorText is given, this error will show below component 4 //... Other Props 5/>
-
-
otpBoxStyle
: Style object for the OTP box.-
Usage:
1<OneTapInput 2 //.... Other Props 3 otpBoxStyle={{ 4 width: 40, 5 height: 40, 6 borderWidth: 1, 7 borderRadius: 20, 8 justifyContent: "center", 9 alignItems: "center", 10 }} 11 //... Other Props 12/>
-
-
otpTextStyle
: Style object for the OTP text.-
Usage:
1<OneTapInput 2 //.... Other Props 3 otpTextStyle={{ 4 fontSize: 12, 5 }} 6 //... Other Props 7/>
-
-
otpBoxBorderColor
: Border color for the OTP box.-
Usage:
1<OneTapInput 2 //.... Other Props 3 otpBoxBorderColor="blue" 4 //... Other Props 5/>
-
-
otpContainerStyle
: Style object for the OTP container.-
Usage:
1<OneTapInput 2 //.... Other Props 3 otpContainerStyle={{ 4 flexDirection: "row", 5 justifyContent: "center", 6 alignItems: "center", 7 gap: 5, 8 }} 9 //... Other Props 10/>
-
-
blinkingCursor
: Boolean to enable/disable the blinking cursor.-
Usage:
1<OneTapInput 2 //.... Other Props 3 blinkingCursor={false} // Default is true 4 //... Other Props 5/>
-
-
blinkingCursorAnimationDuration
: Duration of the blinking cursor animation.-
Usage:
1<OneTapInput 2 //.... Other Props 3 blinkingCursorAnimationDuration={400} // Default is 500 ms 4 //... Other Props 5/>
-
-
cursorPosition
: Position of the cursor. It can be 'left', 'middle', or an object specifying the left and top positions.-
Usage:
1<OneTapInput 2 //.... Other Props 3 cursorPosition={"left"} // Or cursorPosition={{ left: 5, top: 5,}} 4 //... Other Props 5/>
-
-
cursorColor
: Color of the cursor.-
Usage:
1<OneTapInput 2 //.... Other Props 3 cursorColor="blue" 4 //... Other Props 5/>
-
-
cursorWidth
: Width of the cursor.-
Usage:
1<OneTapInput 2 //.... Other Props 3 cursorWidth={1} // Default is 2 4 //... Other Props 5/>
-
-
cursorHeight
: Height of the cursor.-
Usage:
1<OneTapInput 2 //.... Other Props 3 cursorHeight={15} // Default is 20 4 //... Other Props 5/>
-
-
autoFocus
: Boolean to enable/disable autofocus on the OTP input.-
Usage:
1<OneTapInput 2 //.... Other Props 3 autoFocus={false} // Default is true 4 //... Other Props 5/>
-
-
hiddenTextSymbol
: Symbol to show when the OTP text is hidden.-
Usage:
1<OneTapInput 2 //.... Other Props 3 hiddenTextSymbol="*" // Default is '●' 4 //... Other Props 5/>
-
-
touchEffectTransparency
: Transparency of the touch effect of OTP Box.-
Usage:
1<OneTapInput 2 //.... Other Props 3 touchEffectTransparency={0.2} // Default is 0.5 4 //... Other Props 5/>
-
-
errorTextStyle
: Style object for the error text.-
Usage:
1<OneTapInput 2 //.... Other Props 3 errorTextStyle={{ 4 fontSize: 16, 5 }} 6 //... Other Props 7/>
-
-
errorContainerStyle
: Style object for the error container.-
Usage:
1<OneTapInput 2 //.... Other Props 3 errorContainerStyle={{ 4 position: "absolute", 5 bottom: 0, 6 left: 0, 7 }} 8 //... Other Props 9/>
-
ResendOTPButton Props
The ResendOTPButton component accepts the following props (Important & useful props are shown first and are in bold) [All props are optional.]:
-
onResendOtp
: Function to call when the resend OTP button is clicked.-
Usage:
1<ResendOTPButton 2 //.... Other Props 3 onResendOtp={() => { 4 // Handle Resend OTP Functionality 5 }} 6 //... Other Props 7/>
-
-
intervalTime
: Interval time for the resend OTP functionality.-
Usage:
1<ResendOTPButton 2 //.... Other Props 3 intervalTime={10} // Default is 30 seconds 4 //... Other Props 5/>
-
-
timerUnit
: Unit for the timer. It can be 'seconds' or 'minutes'.-
Usage:
1<ResendOTPButton 2 //.... Other Props 3 timerUnit="minutes" // Default is "seconds" 4 //... Other Props 5/>
-
-
resendText
: Function to format the resend text.-
Usage:
1<ResendOTPButton 2 //.... Other Props 3 resendText={(timer, timerUnit) => 4 `Please wait ${timer + " " + timerUnit} before resending.` 5 } // You can customize the resend text here 6 //... Other Props 7/>
-
-
resendOtpText
: Text for the resend OTP button.-
Usage:
1<ResendOTPButton 2 //.... Other Props 3 resendOtpText="Send OTP Again" // Default is Resend OTP 4 //... Other Props 5/>
-
-
resendButtonStyle
: Style object for the resend OTP button.-
Usage:
1<ResendOTPButton 2 //.... Other Props 3 resendButtonStyle={{ 4 marginTop: 20, 5 marginBottom: 20, 6 }} 7 //... Other Props 8/>
-
-
resendButtonColor
: Color for the resend OTP button.-
Usage:
1<ResendOTPButton 2 //.... Other Props 3 resendButtonColor="green" 4 //... Other Props 5/>
-
-
resendButtonTextColor
: Text color for the resend OTP button.-
Usage:
1<ResendOTPButton 2 //.... Other Props 3 resendButtonTextColor="black" 4 //... Other Props 5/>
-
-
resendButtonTextStyle
: Style object for the resend OTP button text.-
Usage:
1<ResendOTPButton 2 //.... Other Props 3 resendButtonTextStyle={{ 4 color: "black", 5 fontSize: 16, 6 }} 7 //... Other Props 8/>
-
-
resendTextStyle
: Style object for the resend text.-
Usage:
1<ResendOTPButton 2 //.... Other Props 3 resendTextStyle={{ 4 fontSize: 16, 5 }} 6 //... Other Props 7/>
-
-
hideResendText
: Boolean to hide/show the resend text.-
Usage:
1<ResendOTPButton 2 //.... Other Props 3 hideResendText={true} // Default is false 4 //... Other Props 5/>
-
-
mainContainerStyle
: Style object for the main container.-
Usage:
1<ResendOTPButton 2 //.... Other Props 3 mainContainerStyle={{ 4 position: "absolute", 5 }} 6 //... Other Props 7/>
-
-
disabledButtonStyle
: Style object for the disabled resend OTP button.-
Usage:
1<ResendOTPButton 2 //.... Other Props 3 disabledButtonStyle={{ display: "none" }} 4 //... Other Props 5/>
-
Changelog
All notable changes to this project will be documented here.
[1.5.1] - 2024-09-11
- Minor fixes.
[1.5.0] - 2024-09-11
- Updated code to be compatible with Latest React Native Version.
[1.4.2] - 2024-06-18
Fixed
- Updated auto receive sms from messages functionality (Android).
[1.3.0] - 2024-06-17
Changed
- Updated README with new instructions and details.
[1.2.0] - 2024-06-17
Changed
- Updated Read Me.
[1.1.0] - 2024-06-17
Fixed
- Imported React in the ResendOTPButton component to fix a runtime error.
[1.0.0] - 2024-06-17
Added
- Initial upload of the OneTapInput and ResendOTPButton components.
- OneTapInput: A custom, reusable component for handling OTP (One Time Password) input in React-Native applications. It utilizes the
react-native-otp-verify
component for OTP Autofill functionality. - ResendOTPButton: A custom, reusable component for handling resend OTP functionality in React-Native applications.
- Provided usage examples and prop descriptions in the README.
- OneTapInput: A custom, reusable component for handling OTP (One Time Password) input in React-Native applications. It utilizes the
![Empty State](/_next/static/media/empty.e5fae2e5.png)
No vulnerabilities found.
![Empty State](/_next/static/media/empty.e5fae2e5.png)
No security vulnerabilities found.