Skip to content

Instantly share code, notes, and snippets.

View alexvanyo's full-sized avatar

Alex Vanyo alexvanyo

View GitHub Profile
@Composable
@Preview(widthDp = 400, heightDp = 600)
@Preview(widthDp = 400, heightDp = 500)
@Preview(widthDp = 400, heightDp = 450)
@Preview(widthDp = 400, heightDp = 400)
@Preview(widthDp = 400, heightDp = 350)
@Preview(widthDp = 400, heightDp = 300)
private fun TextTruncation() {
Surface {
Layout(
@alexvanyo
alexvanyo / PowerableUpdatable.kt
Last active April 11, 2024 17:39
Updatable and PoweredUpdatable
/*
* Copyright 2024 The Android Open Source Project
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
@alexvanyo
alexvanyo / EdgeToEdgeAlertDialog.kt
Last active January 30, 2024 01:28
EdgeToEdgeDialogs
/*
* Copyright 2024 The Android Open Source Project
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
@alexvanyo
alexvanyo / SnapshotStateSet.kt
Created April 5, 2023 21:56
An implementation of a MutableSet backed by snapshot state
/*
* Copyright 2022 The Android Open Source Project
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
@alexvanyo
alexvanyo / Fixed6SpacerTest.kt
Last active January 25, 2023 22:08
A fixed test that verifies the rounding behavior that occurs on device
/* Copyright 2023 Google LLC.
SPDX-License-Identifier: Apache-2.0 */
@Test
fun checkHeightOfColumn() {
lateinit var density: Density
lateinit var layoutCoordinates: LayoutCoordinates
composeTestRule.setContent {
density = LocalDensity.current
Column(
@alexvanyo
alexvanyo / Flaky6SpacerTest.kt
Last active January 25, 2023 22:08
A flaky test with behavior that depends on the density of the device
/* Copyright 2023 Google LLC.
SPDX-License-Identifier: Apache-2.0 */
@Ignore("Flaky test, don't do this!)
@Test
fun checkHeightOfColumn() {
lateinit var density: Density
lateinit var layoutCoordinates: LayoutCoordinates
composeTestRule.setContent {
density = LocalDensity.current
@alexvanyo
alexvanyo / ScreenshotTests.kt
Last active April 11, 2024 08:34
Automatic @Preview screenshot tests with Showkase and Paparazzi
// Copyright 2022 Google LLC.
// SPDX-License-Identifier: Apache-2.0
import androidx.compose.foundation.layout.Box
import androidx.compose.runtime.Composable
import androidx.compose.runtime.CompositionLocalProvider
import androidx.compose.ui.platform.LocalInspectionMode
import app.cash.paparazzi.DeviceConfig
import app.cash.paparazzi.Paparazzi
import com.airbnb.android.showkase.models.Showkase
@alexvanyo
alexvanyo / HomeListWithArticleDetailsScreen.kt
Last active January 14, 2022 20:36
Usage of notifyInput in HomeListWithArticleDetailScreen
// Copyright 2022 Google LLC.
// SPDX-License-Identifier: Apache-2.0
@Composable
fun HomeListWithArticleDetailsScreen(
onInteractWithList: () -> Unit,
onInteractWithDetail: (String) -> Unit,
// ...
) {
Row {
@alexvanyo
alexvanyo / NotifyInput.kt
Last active January 14, 2022 21:06
A Modifier to track all touch inputs on a Composable
// Copyright 2022 Google LLC.
// SPDX-License-Identifier: Apache-2.0
/**
* A [Modifier] that tracks all input, and calls [block] every time input is received.
*/
private fun Modifier.notifyInput(block: () -> Unit): Modifier =
composed {
val currentBlock by rememberUpdatedState(block)
pointerInput(Unit) {
while (currentCoroutineContext().isActive) {
@alexvanyo
alexvanyo / HomeRouteScrollState.kt
Last active January 14, 2022 20:35
The scroll state hoisting for the HomeRoute
// Copyright 2022 Google LLC.
// SPDX-License-Identifier: Apache-2.0
@Composable
fun HomeRoute(
isExpandedScreen: Boolean,
isArticleOpen: Boolean,
selectedArticleId: String,
onSelectArticle: (String) -> Unit,
onArticleBackPress: () -> Unit,