Skip to content

Instantly share code, notes, and snippets.

View mxalbert1996's full-sized avatar

Albert Chang mxalbert1996

View GitHub Profile
@mxalbert1996
mxalbert1996 / AutoShrinkText.kt
Created April 6, 2023 07:24
Auto Size (Auto Shrink) Text
import androidx.compose.foundation.text.selection.SelectionContainer
import androidx.compose.material.LocalContentAlpha
import androidx.compose.material.LocalContentColor
import androidx.compose.material.LocalTextStyle
import androidx.compose.material.Text
import androidx.compose.runtime.Composable
import androidx.compose.runtime.remember
import androidx.compose.ui.Modifier
import androidx.compose.ui.draw.drawBehind
import androidx.compose.ui.graphics.Color
@mxalbert1996
mxalbert1996 / HeaderFooterLayout.kt
Created December 8, 2022 10:18
A layout that allows content to flow over header and footer when scrolled.
import androidx.compose.foundation.clickable
import androidx.compose.foundation.layout.Box
import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.fillMaxWidth
import androidx.compose.foundation.layout.height
import androidx.compose.foundation.layout.padding
import androidx.compose.foundation.layout.wrapContentSize
import androidx.compose.foundation.rememberScrollState
import androidx.compose.foundation.verticalScroll
import androidx.compose.material.Card
@mxalbert1996
mxalbert1996 / Scrollbar.kt
Last active December 19, 2024 05:42
Modifiers to draw scrollbars in Jetpack Compose
/*
* MIT License
*
* Copyright (c) 2022 Albert Chang
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
@mxalbert1996
mxalbert1996 / AlertDialog.kt
Last active October 12, 2021 06:59
General-purpose AlertDialog for Jetpack Compose
import androidx.compose.animation.animateContentSize
import androidx.compose.foundation.gestures.detectTapGestures
import androidx.compose.foundation.layout.*
import androidx.compose.material.*
import androidx.compose.runtime.Composable
import androidx.compose.runtime.CompositionLocalProvider
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.input.pointer.pointerInput
import androidx.compose.ui.unit.dp
@mxalbert1996
mxalbert1996 / Pager.kt
Last active July 27, 2023 09:57
Non-lazy horizontal pager implementation in Compose
/*
* Copyright 2020 The Android Open Source Project
* Copyright 2023 Albert Chang
*
* 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
*