Skip to content

Instantly share code, notes, and snippets.

View yongjhih's full-sized avatar
Working from home

Andrew Chen yongjhih

Working from home
View GitHub Profile
Digipom / Bubble.kt
Created May 31, 2023 14:58
Show bubble tooltip overlays using a similar approach as Android Compose's DropdownMenu.
package com.example.bubble.ui.components
import androidx.compose.animation.core.MutableTransitionState
import androidx.compose.material3.MaterialTheme
import androidx.compose.runtime.Composable
import androidx.compose.runtime.getValue
import androidx.compose.runtime.mutableStateOf
import androidx.compose.runtime.remember
import androidx.compose.runtime.setValue
SylpheM / TooltipShape.kt
Last active March 30, 2024 06:15
A tooltip shape (a rounded rectangle with an arrow or a tick), that can be used with a shadow. Preview included
enum class TickOrientation {
class TooltipShape(
private val cornerRadiusDp: Dp,
private val tickHeight: Dp,
private val tickOrientation: TickOrientation
) : Shape {
amal / Tooltip.kt
Last active December 21, 2023 11:25
How to show a tooltip in AndroidX Jetpack Compose?
// 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
import android.content.Context
import android.os.Bundle
import android.widget.TextView
import androidx.lifecycle.ViewModel
import androidx.lifecycle.ViewModelProvider
Krosxx / flutter_aar_upload.gradle
Created March 11, 2021 10:55
Flutter module upload aar to maven
// This script is used to initialize the build in a module or plugin project.
// During this phase, the script applies the Maven plugin and configures the
// destination of the local repository.
// The local repository will contain the AAR and POM files.
void configureProject(Project project, String mavenUrl, String mavenUser, String mavenPwd, String version) {
if (!project.hasProperty("android")) {
throw new GradleException("Android property not found.")
if (!"libraryVariants")) {
DavidIbrahim / DashedBorder.kt
Last active May 14, 2024 15:13
dashedBorder modifier for android compose
* Copyright 2020 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
gmk57 / 1 ViewBindingDelegates.kt
Last active January 25, 2024 09:01
Kotlin delegates for Android View Binding with usage examples
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import androidx.lifecycle.DefaultLifecycleObserver
import androidx.lifecycle.Lifecycle
import androidx.lifecycle.LifecycleOwner
import androidx.viewbinding.ViewBinding
manuelvicnt / LocationRepository.kt
Last active December 28, 2022 04:17
LocationFlow shareIn
val FusedLocationProviderClient.locationFlow() = callbackFlow<Location> {
// Make the flow follow the applicationScope
// Emit the last emitted element to new collectors
replay = 1,
// Keep the producer active while there are active subscribers
started = SharingStarted.WhileSubscribed()
serhii-pokrovskyi / OnDestroyNullable.kt
Created December 5, 2020 08:03
Property that will be destroyed in onDestoy
fun <T> LifecycleOwner.onDestroyNullable(): ReadWriteProperty<LifecycleOwner, T> =
object : ReadWriteProperty<LifecycleOwner, T>, DefaultLifecycleObserver {
private var value: T? = null
init {
jamiesanson / ViewLifecycleLazy.kt
Last active March 26, 2024 13:17
A Kotlin lazy implementation which automatically clears itself at appropriate times in the View Lifecycle, with a Fragment example
import androidx.lifecycle.DefaultLifecycleObserver
import androidx.lifecycle.LifecycleOwner
import androidx.lifecycle.Observer
import kotlin.reflect.KProperty
fun <T> Fragment.viewLifecycleLazy(initialise: () -> T): ReadOnlyProperty<Fragment, T> =
object : ReadOnlyProperty<Fragment, T>, DefaultLifecycleObserver {