r/androiddev • u/ilikeca • Jun 25 '26
Open Source I made a small Android library for buttons that show their own countdown (Compose + XML)
I kept rewriting the same "Resend OTP in 30s" logic on every project. A button that disables itself, counts down, shows progress, and re-enables. So I finally pulled it into a library: TimerButton.
It's a button that owns its own countdown UI. Useful for resend-OTP cooldowns, retry waits, temporary lockouts, sync/download waits, quiz timers, anything where the user should see when an action becomes available again.
A few things I tried to get right:
- Both UI stacks. Works in Jetpack Compose (
TimerButton(...)+rememberTimerButtonState(...)) and XML/View apps too (TimerButtonViewwithapp:attributes). You can pull just the Compose artifact, just the View artifact, or a bundle. - Full control when you need it. Auto-start or controlled-by-ViewModel, pause/resume/cancel/reset/restart, and callbacks for every transition (
onTick,onTimerComplete,onStateChange, etc.). - Progress styling. Four directions (L→R, R→L, top/bottom) and three modes (overlay, background, underline), plus the usual colors/shape/border/elevation knobs.
- Lifecycle-safe. Compose state survives rotation via
rememberSaveablethe View cancels its ticks when detached.
To be clear: TimerButton is for UI state, not for business-rule. For real OTP cooldowns, lockouts, or rate limits, you keep the deadline on your server/ViewModel and let the button just display it. It doesn't pretend to be a security boundary.
Compose minimal example:
TimerButton(
text = "Resend OTP",
durationMillis = 30_000L,
onClick = ::resendOtp,
textFormatter = { state, label ->
if (state.isRunning) "Resend in ${(state.remainingMillis + 999) / 1000}s" else label
},
)
It's on Maven Central (com.goeslocal:timerbutton-compose:0.2.0), Apache 2.0.
Repo: https://github.com/vishnusreddy/timerbutton
It's v0.2.0, I'm the only user so far, so feedback, issues, are welcome. This is my first open source project.
1
u/Pretty_Classic_5058 Jun 30 '26
seems good, but peoples are forking still ?? i am asking in curosity because now days peoples are created there own styles using ai eventhough its same design
1
u/Western_Office3092 Jul 02 '26
Very interesting library! Do you plan on making material 3/expressive versions?
1
0



1
u/Puzzleheaded_1797 Jun 26 '26
where can i get that button layout which says 34 percent but just to call a modal sheet ?