Skip to content

Instantly share code, notes, and snippets.

View svenjacobs's full-sized avatar

Sven Jacobs svenjacobs

View GitHub Profile
@svenjacobs
svenjacobs / SegmentedProgressBar.kt
Created April 4, 2024 12:41
Segmented progress bar in Jetpack Compose
import androidx.compose.foundation.background
import androidx.compose.foundation.layout.Arrangement
import androidx.compose.foundation.layout.Box
import androidx.compose.foundation.layout.Row
import androidx.compose.foundation.layout.fillMaxHeight
import androidx.compose.foundation.layout.height
import androidx.compose.foundation.shape.RoundedCornerShape
import androidx.compose.runtime.Composable
import androidx.compose.ui.Modifier
import androidx.compose.ui.draw.clip
@svenjacobs
svenjacobs / MarkdownLinkText.kt
Created April 25, 2023 11:57
Composable for rendering text with Markdown-style hyperlinks
import androidx.compose.foundation.text.ClickableText
import androidx.compose.material.LocalContentAlpha
import androidx.compose.material.LocalContentColor
import androidx.compose.material.LocalTextStyle
import androidx.compose.runtime.Composable
import androidx.compose.runtime.remember
import androidx.compose.ui.Modifier
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.graphics.takeOrElse
import androidx.compose.ui.text.ExperimentalTextApi
@svenjacobs
svenjacobs / StateEvent.kt
Last active January 17, 2023 13:37
An event inside a Compose State or MutableState which should only be handled once
import androidx.compose.runtime.MutableState
import androidx.compose.runtime.State
import androidx.compose.runtime.saveable.Saver
import androidx.compose.runtime.saveable.listSaver
import kotlinx.coroutines.sync.Mutex
import kotlinx.coroutines.sync.withLock
/**
* An event inside a [State] or [MutableState] which should only be handled once, even after
* recomposition. The [consume] function ensures this.
@svenjacobs
svenjacobs / Rfc822InstantParser.kt
Last active August 24, 2022 06:07
RFC 822 date/time parser for kotlinx-datetime
import kotlinx.datetime.*
/**
* RFC 822 date/time format to [Instant] parser.
*
* See https://www.rfc-editor.org/rfc/rfc822#section-5
*/
class Rfc822InstantParser {
private enum class Month {
@svenjacobs
svenjacobs / ContentLoadingLayout.kt
Created January 6, 2022 10:08
A composable inspired by ContentLoadingProgressBar
import androidx.compose.runtime.*
import androidx.compose.runtime.saveable.rememberSaveable
import kotlinx.coroutines.delay
import kotlin.time.Duration
import kotlin.time.ExperimentalTime
/**
* Inspired by View-based [ContentLoadingProgressBar](https://developer.android.com/reference/androidx/core/widget/ContentLoadingProgressBar).
*
* Waits `minDelayDuration` until contents of `loading` composable is shown when `isLoading` is
@svenjacobs
svenjacobs / keybase.md
Created September 11, 2015 07:38
Keybase.io proof

Keybase proof

I hereby claim:

  • I am svenjacobs on github.
  • I am caffeine (https://keybase.io/caffeine) on keybase.
  • I have a public key whose fingerprint is C1F2 ABB7 2F14 18EE 7E75 479C A476 C518 A3A2 383C

To claim this, I am signing this object: