Skip to content

Instantly share code, notes, and snippets.

View ychescale9's full-sized avatar
🏠
Working from home

Yang ychescale9

🏠
Working from home
View GitHub Profile
import android.os.Bundle
import androidx.activity.ComponentActivity
import androidx.activity.compose.setContent
import androidx.compose.animation.animateColorAsState
import androidx.compose.animation.core.tween
import androidx.compose.foundation.layout.Arrangement
import androidx.compose.foundation.layout.Box
import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.Row
import androidx.compose.foundation.layout.Spacer
@Preview(showBackground = true, showSystemUi = true)
@Composable
fun App() {
Column {
MarxistRow {
Text("Left Text", Modifier.background(Color.Red))
Text("Right Text", Modifier.background(Color.Blue))
}
MarxistRow {
@AlexGabor
AlexGabor / LoginScreenExample.kt
Created August 30, 2022 14:38
state holder instead of vm
@Composable
fun LoginScreen(
modifier: Modifier = Modifier,
state: LoginScreenState = rememberLoginScreenState(),
) {
// ...
}
@Composable
fun rememberLoginScreenState(
@AfzalivE
AfzalivE / CustomTestRunner.kt
Last active August 3, 2022 22:30
Disable soft-keyboards for tests
import androidx.test.runner.AndroidJUnitRunner
class CustomJunitRunner : AndroidJUnitRunner() {
private var enabledImes = emptyList<String>()
override fun callApplicationOnCreate(app: Application?) {
super.callApplicationOnCreate(app)
enabledImes = getEnabledImes()
disableSoftKeyboards(enabledImes)
@c5inco
c5inco / SwipeableCards.kt
Last active April 21, 2024 13:06
Jetpack Compose implementation of inspiration: https://twitter.com/philipcdavis/status/1534192823792128000
package des.c5inco.cardswipecompose
import androidx.compose.animation.core.Animatable
import androidx.compose.animation.core.CubicBezierEasing
import androidx.compose.animation.core.LinearOutSlowInEasing
import androidx.compose.animation.core.animateDpAsState
import androidx.compose.animation.core.animateFloatAsState
import androidx.compose.animation.core.calculateTargetValue
import androidx.compose.animation.core.keyframes
import androidx.compose.animation.splineBasedDecay
@AfzalivE
AfzalivE / ComposeLayoutPreviewHelper.kt
Last active February 9, 2023 14:37
AbstractComposeView layout preview helper
package com.yourpackage
import android.os.Bundle
import android.view.View
import androidx.compose.runtime.MonotonicFrameClock
import androidx.compose.runtime.PausableMonotonicFrameClock
import androidx.compose.runtime.Recomposer
import androidx.compose.ui.InternalComposeUiApi
import androidx.compose.ui.platform.AbstractComposeView
import androidx.compose.ui.platform.AndroidUiDispatcher
@JUSTINMKAUFMAN
JUSTINMKAUFMAN / XCFramework.kts
Created November 3, 2021 18:53
Kotlin Multiplatform Build Gradle Task for iOS/macOS Universal Framework
/**
* Kotlin Multiplatform Universal XCFramework Task
*
* Description:
* If your project needs to target *all* possible
* iOS and macOS variants (including Apple Silicon
* hardware, ARM64 iPhone simulators, and so on),
* this task will build the frameworks, lipo those
* that can be combined into a single binary, and
* place them where Xcode expects to find them in
@zach-klippenstein
zach-klippenstein / SegmentedControl.kt
Last active May 3, 2024 11:15
iOS-style segmented control in Compose
import android.annotation.SuppressLint
import androidx.compose.animation.core.animateDpAsState
import androidx.compose.animation.core.animateFloatAsState
import androidx.compose.foundation.Canvas
import androidx.compose.foundation.background
import androidx.compose.foundation.gestures.awaitFirstDown
import androidx.compose.foundation.gestures.forEachGesture
import androidx.compose.foundation.gestures.horizontalDrag
import androidx.compose.foundation.layout.Arrangement.spacedBy
import androidx.compose.foundation.layout.Box
@JorgeCastilloPrz
JorgeCastilloPrz / RatingStars.kt
Last active August 29, 2021 23:43
Composable to show rating stars. Noninteractive.
import androidx.compose.foundation.Image
import androidx.compose.foundation.layout.Row
import androidx.compose.foundation.layout.padding
import androidx.compose.foundation.layout.preferredSize
import androidx.compose.material.MaterialTheme
import androidx.compose.material.Text
import androidx.compose.runtime.Composable
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.graphics.ColorFilter
@objcode
objcode / Permissions.kt
Last active February 21, 2023 23:01
Quick demo of compose permissions using activity result API. Uses Flow instead of State to make it reusable outside of 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
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software