Skip to content

Instantly share code, notes, and snippets.

@Oleur
Created December 13, 2021 18:43
Show Gist options
  • Save Oleur/6993cd1c093613eb1782bd04e8ae5352 to your computer and use it in GitHub Desktop.
Save Oleur/6993cd1c093613eb1782bd04e8ae5352 to your computer and use it in GitHub Desktop.
Credit Card transformation offset mapping from Compose documentation.
// Making XXXX-XXXX-XXXX-XXXX string.
val creditCardOffsetMapping = object : OffsetMapping {
override fun originalToTransformed(offset: Int): Int {
if (offset <= 3) return offset
if (offset <= 7) return offset + 1
if (offset <= 11) return offset + 2
if (offset <= 16) return offset + 3
return 19
}
override fun transformedToOriginal(offset: Int): Int {
if (offset <= 4) return offset
if (offset <= 9) return offset - 1
if (offset <= 14) return offset - 2
if (offset <= 19) return offset - 3
return 16
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment