Skip to content

Instantly share code, notes, and snippets.

@msomu
msomu / DateVisualTransformation.kt
Created June 30, 2021 17:26
UseVisualTransformation to Create Date TextField in Jetpack Compose
import androidx.compose.ui.text.AnnotatedString
import androidx.compose.ui.text.input.OffsetMapping
import androidx.compose.ui.text.input.TransformedText
import androidx.compose.ui.text.input.VisualTransformation
class DateVisualTransformation : VisualTransformation {
override fun filter(text: AnnotatedString): TransformedText {
// Make the string DD-MM-YYYY
val trimmed = if (text.text.length >= 8) text.text.substring(0..7) else text.text
var output = ""
@filipkowicz
filipkowicz / HeaderItemDecoration.kt
Last active April 19, 2024 15:37
Item Decorator for sticky headers in Kotlin
package com.filipkowicz.headeritemdecorator
/*
solution based on - based on Sevastyan answer on StackOverflow
changes:
- take to account views offsets
- transformed to Kotlin
- now works on viewHolders