package com.example.base.extensions

import android.os.Handler
import android.widget.TextView

fun TextView.showTextOneByOne(text: String, interval: Long = 50, onCompleted: ((Int) -> Unit)? = null) {
    var index = 0
    val handler = Handler()
    val runnable: Runnable = object : Runnable {
        override fun run() {
            if (index < text.length) {
                val ch = text[index]
                append(ch.toString())
                index++
                handler.postDelayed(this, interval)
                onCompleted?.invoke(1)
            } else {
                onCompleted?.invoke(0)
            }
        }
    }
    runnable.run()
}