Skip to content

Instantly share code, notes, and snippets.

View yasukotelin's full-sized avatar

Yasuhiro Kikura yasukotelin

View GitHub Profile
package com.github.moriatsushi.compose
import androidx.compose.ui.Modifier
inline fun <T : Any> Modifier.ifNotNull(value: T?, builder: (T) -> Modifier): Modifier {
return then(if (value != null) builder(value) else Modifier)
}
inline fun Modifier.ifTrue(value: Boolean, builder: () -> Modifier): Modifier {
return then(if (value) builder() else Modifier)
@alexvanyo
alexvanyo / WindowSizeClass.kt
Last active February 3, 2022 10:32
Composable method for observing the current window size class
// Copyright 2022 Google LLC.
// SPDX-License-Identifier: Apache-2.0
enum class WindowSize { Compact, Medium, Expanded }
/**
* Remembers the [WindowSize] class for the window corresponding to the
* current window metrics.
*/
@Composable
@amal
amal / Tooltip.kt
Last active December 21, 2023 11:25
How to show a tooltip in AndroidX Jetpack Compose?
@file:Suppress("INVISIBLE_REFERENCE", "INVISIBLE_MEMBER")
// Tooltip implementation for AndroidX Jetpack Compose
// See usage example in the next file
// Tested with Compose version **1.1.0-alpha06**
// Based on material DropdownMenu implementation.
import androidx.compose.animation.core.MutableTransitionState
import androidx.compose.animation.core.animateFloat
/* Copyright 2019 Google LLC.
SPDX-License-Identifier: Apache-2.0 */
fun <T> LiveData<T>.getOrAwaitValue(
time: Long = 2,
timeUnit: TimeUnit = TimeUnit.SECONDS
): T {
var data: T? = null
val latch = CountDownLatch(1)
val observer = object : Observer<T> {
override fun onChanged(o: T?) {
@asufana
asufana / Java8 クロージャ.md
Last active January 31, 2020 04:57
Java8 クロージャ

Java8 クロージャ

Javaにクロージャが提供されたのか?

Java8にlambda構文が入りましたが、これはクロージャーではない、とされています。

(中略)

結論としては、「Java8のlambdaはクロージャーではないけど、クロージャーでやりたいことはできるし、やってはいけないことができないようになっているので、特に問題はない」と言えると思います。

@jasonm23
jasonm23 / xterm-256color.svg
Last active February 11, 2024 12:33
Xterm 256color mode color chart, organised into sections. (used on Wikipedia/xterm)
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.