Skip to content

Instantly share code, notes, and snippets.

@robertlevonyan
Last active September 29, 2019 09:14
Show Gist options
  • Save robertlevonyan/56ff29edb6d5c6d2da7fb051d2eee771 to your computer and use it in GitHub Desktop.
Save robertlevonyan/56ff29edb6d5c6d2da7fb051d2eee771 to your computer and use it in GitHub Desktop.
fun setTextAsync(textView: TextView, longString: String) {
val params = textView.textMetricsParams
val ref = WeakReference(textView)
CoroutineScope.launch(Dispatchers.Default) {
val pText = PrecomputedText.create(longString, params)
withContext(Dispatchers.Main) {
ref.get()?.let { textView ->
textView.text = pText
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment