Skip to content

Instantly share code, notes, and snippets.

Avatar

Vsevolod Ganin vganin

  • Russia, Moscow
View GitHub Profile
@vganin
vganin / ComposeNumberPicker.kt
Last active Sep 22, 2020
Jetpack Compose implementation of simple integer picker. Supports fling gestures!
View ComposeNumberPicker.kt
@Composable
fun NumberPicker(
state: MutableState<Int> = remember { mutableStateOf(0) },
modifier: Modifier = Modifier
) {
val numbersColumnHeight = 36.dp
val halvedNumbersColumnHeight = numbersColumnHeight / 2
val halvedNumbersColumnHeightPx = with(DensityAmbient.current) { halvedNumbersColumnHeight.toPx() }
fun animatedStateValue(offset: Float): Int = state.value - (offset / halvedNumbersColumnHeightPx).toInt()
@vganin
vganin / FragmentArgs.kt
Last active Mar 4, 2017
Kotlin FragmentArgs
View FragmentArgs.kt
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 Oct 17, 2015
Workaround for bug with RecycleView focus scrolling when navigating with d-pad (http://stackoverflow.com/questions/31596801/recyclerview-focus-scrolling)
View GridLayoutManager.java
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>
You can’t perform that action at this time.