Skip to content

Instantly share code, notes, and snippets.

@vganin
vganin / ComposePathMorphing.kt
Last active March 16, 2023 15:34
Jetpack Compose path morphing animation
@Composable
fun animatePathAsState(path: String): State<List<PathNode>> {
return animatePathAsState(remember(path) { addPathNodes(path) })
}
@Composable
fun animatePathAsState(path: List<PathNode>): State<List<PathNode>> {
var from by remember { mutableStateOf(path) }
var to by remember { mutableStateOf(path) }
val fraction = remember { Animatable(0f) }
@vganin
vganin / DurationPicker.kt
Created November 6, 2021 16:15
Jetpack Compose duration input field
@Composable
fun DurationPicker(
state: MutableState<Duration>,
modifier: Modifier = Modifier,
) {
DurationPicker(
value = state.value,
onValueChange = { state.value = it },
modifier = modifier,
)
@vganin
vganin / FlexRow.kt
Last active September 1, 2024 19:19
[DEPRECATED, use official FlowRow instead] Jetpack Compose simple flex-wrap container
@Composable
fun FlowRow(
horizontalGap: Dp = 0.dp,
verticalGap: Dp = 0.dp,
alignment: Alignment.Horizontal = Alignment.Start,
content: @Composable () -> Unit,
) = Layout(content = content) { measurables, constraints ->
val horizontalGapPx = horizontalGap.toPx().roundToInt()
val verticalGapPx = verticalGap.toPx().roundToInt()
@vganin
vganin / ComposableSwitcher.kt
Last active July 30, 2022 12:19
[DEPRECATED, use AnimatedContent instead] Jetpack Compose tool for screen transitions
enum class ComposableTransitionState {
VISIBLE, ENTERING, EXITING,
}
@Composable
fun <Key, State> ComposableSwitcher(
key: Key,
state: State,
snapOnInitialComposition: Boolean = true,
content: @Composable (Key, State, Transition<ComposableTransitionState>) -> Unit,
@vganin
vganin / ComposeNumberPicker.kt
Last active January 14, 2024 11:53
Jetpack Compose simple number picker
@Composable
fun NumberPicker(
state: MutableState<Int>,
modifier: Modifier = Modifier,
range: IntRange? = null,
textStyle: TextStyle = LocalTextStyle.current,
onStateChanged: (Int) -> Unit = {},
) {
val coroutineScope = rememberCoroutineScope()
val numbersColumnHeight = 36.dp
@vganin
vganin / FragmentArgs.kt
Last active March 4, 2017 17:42
Kotlin FragmentArgs
import android.app.Fragment
import android.os.Bundle
import kotlin.properties.ReadWriteProperty
import kotlin.reflect.KProperty
import android.support.v4.app.Fragment as SupportFragment
inline fun <reified T> Fragment.fragmentArg()
: ReadWriteProperty<Fragment, T> = required({ argumentsRequired })
inline fun <reified T> SupportFragment.fragmentArg()
: ReadWriteProperty<SupportFragment, T> = required({ argumentsRequired })
@vganin
vganin / GridLayoutManager.java
Created October 17, 2015 18:57
Workaround for bug with RecycleView focus scrolling when navigating with d-pad (http://stackoverflow.com/questions/31596801/recyclerview-focus-scrolling)
import android.content.Context;
import android.support.v7.widget.RecyclerView;
import android.util.AttributeSet;
import android.view.View;
/**
* {@link GridLayoutManager} extension which introduces workaround for focus finding bug when
* navigating with dpad.
*
* @see <a href="http://stackoverflow.com/questions/31596801/recyclerview-focus-scrolling">http://stackoverflow.com/questions/31596801/recyclerview-focus-scrolling</a>