A lightweight and customizable OTP input solution built with Jetpack Compose ⚡
- ✅ Simple integration – just drop and use
- 🔢 Supports any OTP length (4, 6, etc.)
- 🎨 Fully customizable using Compose
Modifier
- 🔁 Auto focus and intelligent backspace handling
- 🚀 Callback triggered when OTP entry is completed
dependencyResolutionManagement {
repositories {
maven { url = uri("https://jitpack.io") }
}
}
dependencies {
implementation("com.github.KishanViramgama:Otp:0.0.2")
}
val getOtp = MyOtp(
otpSize = 4,
modifier = Modifier.padding(
start = 10.dp,
end = 10.dp,
top = 10.dp
)
) {
Toast.makeText(context, it, Toast.LENGTH_SHORT).show()
}
Button(onClick = {
if (getOtp.isNotEmpty()) {
Toast.makeText(
context,
"OTP Found: $getOtp",
Toast.LENGTH_SHORT
).show()
} else {
Toast.makeText(
context,
"OTP is empty!",
Toast.LENGTH_SHORT
).show()
}
}) {
Text("Get OTP")
}
🧩 Parameter | 📖 Description |
---|---|
otpSize: Int |
Defines how many digits your OTP input will have. Common values: 4 or 6 . |
modifier: Modifier |
Customize layout using Jetpack Compose's Modifier (padding, width, alignment). |
onOtpComplete: (String) -> Unit |
Callback triggered when all digits are entered. Returns the full OTP string. |
The return value from MyOtp(...)
is a String
that stores the full OTP.
- 📦 Use it on button click or form submission
⚠️ If OTP is incomplete, it will return anempty
string
Tags: Jetpack Compose
, OTP
, Android
, Kotlin
, Authentication
, UI
, Compose UI
, Material Design
Want to improve this library? You're welcome! Fork it, raise a PR, or open an issue with your suggestions. Let's build better together 💪
This project is MIT Licensed
Built with ❤️ by Kishan Viramgama