Skip to content

Instantly share code, notes, and snippets.

View jershell's full-sized avatar
🙆‍♂️
😓😘😨😭😸€

jershell jershell

🙆‍♂️
😓😘😨😭😸€
View GitHub Profile
@jershell
jershell / UtilsKtTest.kt
Created March 19, 2024 11:52
compose color to html color
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.graphics.toArgb
import io.ktor.util.*
import kotlin.math.roundToInt
import kotlin.test.DefaultAsserter.assertEquals
import kotlin.test.Test
class UtilsKtTest {
private val dataSet = listOf(
@jershell
jershell / compose.kt
Created October 23, 2023 13:17
Cargo11.kt
package cargo
import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.fillMaxWidth
import androidx.compose.material.Text
import androidx.compose.runtime.Composable
import androidx.compose.ui.Modifier
// Exception in thread "main" java.lang.NullPointerException: Parameter specified as non-null is null:
// method cargo.ComponentScopeImpl.Child, parameter modifier
@jershell
jershell / toUIColor.kt
Last active October 14, 2023 15:23
compose Color to UIColor
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.graphics.toArgb
import platform.UIKit.UIColor
fun Color.toUIColor(): UIColor {
val argb = this.toArgb()
val blue = argb and 0xff;
val green = argb shr 8 and 0xff;
val red = argb shr 16 and 0xff;
@jershell
jershell / Cargo8.kt
Last active October 20, 2023 09:33
seiko example svg
package cargo
import androidx.compose.foundation.Image
import androidx.compose.foundation.border
import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.fillMaxHeight
import androidx.compose.foundation.layout.fillMaxWidth
import androidx.compose.foundation.layout.width
import androidx.compose.material.Text
import androidx.compose.runtime.Composable
@jershell
jershell / scaffold.kt
Last active October 25, 2022 12:46
BottomSheetScaffold scaffoldState jetpack compose
@Composable fun Example() {
val colors = remember { listOf<Color>(Color.Blue, Color.Gray, Color.Green, Color.Magenta, Color.Yellow, Color.Cyan) }
val scope = rememberCoroutineScope()
val scaffoldState = rememberBottomSheetScaffoldState()
BottomSheetScaffold(
sheetContent = {
Box(
Modifier.fillMaxWidth().height(128.dp),
contentAlignment = Alignment.Center
) {
@jershell
jershell / SwipeToRemove.kt
Created February 23, 2022 08:24
compose swipe to remove
package com.github.gismenu.ui.components
import androidx.compose.animation.animateContentSize
import androidx.compose.animation.core.animateIntAsState
import androidx.compose.foundation.gestures.detectHorizontalDragGestures
import androidx.compose.foundation.layout.Box
import androidx.compose.foundation.layout.fillMaxSize
import androidx.compose.foundation.layout.offset
import androidx.compose.runtime.*
import androidx.compose.ui.Modifier
@jershell
jershell / Input.kt
Created January 6, 2022 13:08
Example of composable Input
@OptIn(ExperimentalComposeUiApi::class)
@Composable
fun Input(
value: TextFieldValue,
onValueChange: (TextFieldValue) -> Unit,
modifier: Modifier = Modifier,
placeholder: String? = null,
enabled: Boolean = true,
singleLine: Boolean = true,
onFocusChanged: (Boolean) -> Unit = {},
@jershell
jershell / full_screen.kt
Created August 10, 2021 12:44
popup full screen compose dialog
package components
import androidx.compose.foundation.background
import androidx.compose.foundation.layout.Box
import androidx.compose.foundation.layout.fillMaxSize
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.Color
@jershell
jershell / baseLayout.kt
Created November 6, 2020 22:52
jetpack compose desktop base layout
package io.resound.ui.components
import androidx.compose.foundation.background
import androidx.compose.foundation.border
import androidx.compose.foundation.layout.*
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.Color
@jershell
jershell / svgAsset.kt
Last active March 19, 2022 18:07
jetpack compose desktop svg loader
// implementation("org.apache.xmlgraphics:batik-all:1.13")
// and load svg from resources/svg/pic.svg
// use like Icon(asset = svgAsset("svg/play-button.svg"), modifier = Modifier.width(36.dp) + Modifier.height(36.dp))
import androidx.compose.ui.graphics.ImageAsset
import androidx.compose.ui.graphics.asImageAsset
import org.apache.batik.transcoder.TranscoderInput
import org.apache.batik.transcoder.TranscoderOutput
import org.apache.batik.transcoder.image.PNGTranscoder
import org.jetbrains.skija.Image
import java.io.ByteArrayOutputStream