Skip to content

Instantly share code, notes, and snippets.

Avatar

Brandon McAnsh bmc08gt

View GitHub Profile
View AnimatedSwipeDismiss.kt
import androidx.compose.animation.*
import androidx.compose.animation.core.tween
import androidx.compose.material.*
import androidx.compose.runtime.Composable
import androidx.compose.runtime.onCommit
import androidx.compose.ui.Modifier
@OptIn(ExperimentalAnimationApi::class, ExperimentalMaterialApi::class)
@Composable
fun <T> AnimatedSwipeDismiss(
@bmc08gt
bmc08gt / Grid.kt
Last active Aug 23, 2020
Jetpack Compose dynamic grid
View Grid.kt
import androidx.compose.foundation.Box
import androidx.compose.foundation.layout.*
import androidx.compose.runtime.Composable
import androidx.compose.runtime.key
import androidx.compose.ui.Modifier
import androidx.compose.ui.unit.Dp
import androidx.compose.ui.unit.dp
@Composable
fun <T>Grid(
@bmc08gt
bmc08gt / DataStore.kt
Created Aug 12, 2020
Firebase Real-time Database value event listener via Kotlin callbackFlow{} updating Jetpack Compose list
View DataStore.kt
fun locationsFlowable(): Flow<PantryResult<List<ItemLocation>>> {
return getLocationsChange()
}
View ActivityResultsRegistry.kt
@OptIn(ExperimentalComposeApi::class)
@Composable
fun ActivityResultRegistry.googleSignIn(userPrefs: UserPreferences): GoogleSignInState {
val context = ContextAmbient.current
val options: GoogleSignInOptions = GoogleSignInOptions.Builder(GoogleSignInOptions.DEFAULT_SIGN_IN).apply {
requestIdToken(context.getString(R.string.google_client_id))
requestEmail()
}.build()
val signInState: MutableState<UserState<*>> = remember {
@bmc08gt
bmc08gt / TransientSnackbar.kt
Last active Aug 22, 2020
Auto-dismissing Snackbar for Jetpack Compose
View TransientSnackbar.kt
class SnackbarState {
var show by mutableStateOf(false)
}
@Composable
fun TransientSnackbar(
modifier: Modifier = Modifier,
snackbarState: SnackbarState,
text: String,
actionLabel: String,
@bmc08gt
bmc08gt / SwipeToDelete.kt
Last active Oct 2, 2020
Jetpack Compose Modifier extension to implement swipe-to-delete via Modifier.draggable
View SwipeToDelete.kt
import androidx.animation.IntToVectorConverter
import androidx.animation.tween
import androidx.compose.Composable
import androidx.compose.mutableStateOf
import androidx.compose.remember
import androidx.ui.animation.animatedFloat
import androidx.ui.animation.animatedValue
import androidx.ui.core.*
import androidx.ui.core.gesture.scrollorientationlocking.Orientation
import androidx.ui.foundation.animation.FlingConfig
@bmc08gt
bmc08gt / App.kt
Last active Jul 28, 2020
DIY DI delegate acess
View App.kt
class App : Application() {
override fun onCreate() {
super.onCreate()
ComponentRouter.init(this) {
inject(SomeOtherComponentImpl())
inject(XYComponentImpl())
}
}
}
View keybase.md

Keybase proof

I hereby claim:

To claim this, I am signing this object:

@bmc08gt
bmc08gt / DateExtensions.kt
Last active Oct 11, 2019
Helpful extensions for java.util.Date
View DateExtensions.kt
import java.text.SimpleDateFormat
import java.util.*
import java.util.concurrent.TimeUnit
import kotlin.math.round
val now: Date = Date()
val Date.daysFromToday: Long
get() {
val msDiff = now.time - this.time
@bmc08gt
bmc08gt / Toolbar.java
Created Mar 9, 2019
Toolbar subclass to allow custom gravity and coloring for various elements
View Toolbar.java
/**
* Created by bmcansh on 3/3/17.
*/
public class Toolbar extends android.support.v7.widget.Toolbar {
private String mGraphikRegular;
private String mGraphikLight;
private ActionMenuView mActionMenuView;
You can’t perform that action at this time.