Skip to content

Instantly share code, notes, and snippets.

View cavin-macwan's full-sized avatar
😉
Solving problems you didn't know you were about to have

Cavin cavin-macwan

😉
Solving problems you didn't know you were about to have
View GitHub Profile
@cavin-macwan
cavin-macwan / GradientButton.kt
Created February 13, 2025 17:36
A customizable button with gradient background and loading state
@Composable
fun GradientButton(
text: String,
isLoading: Boolean = false,
onClick: () -> Unit,
modifier: Modifier,
) {
Box(
modifier = modifier
.fillMaxWidth()
@cavin-macwan
cavin-macwan / MarqueeScreen.kt
Created February 3, 2025 18:13
Text that scrolls automatically like a news ticker.
@Composable
fun MarqueeScreen() {
Box(
modifier = Modifier.fillMaxSize(),
contentAlignment = Alignment.Center
) {
val edgeWidth = 80.dp
Text(
"the quick brown fox jumped over the lazy dogs",
Modifier
@cavin-macwan
cavin-macwan / DraggableBoxScreen.kt
Created February 3, 2025 17:59
A draggable Box that follows touch gestures.
@Composable
fun DraggableBoxScreen(modifier: Modifier = Modifier) {
Box(modifier = Modifier.fillMaxSize()){
DraggableBox()
}
}
@Composable
fun DraggableBox() {
var offset by remember { mutableStateOf(Offset.Zero) }
@cavin-macwan
cavin-macwan / ExpandableTextScreen.kt
Last active February 10, 2025 16:36
A Text component that expands or collapses on click.
@Composable
fun ExpandableTextScreen() {
Box(
modifier = Modifier.fillMaxSize(),
contentAlignment = Alignment.Center,
) {
ExpandableText(
text = "This is an example of a very long text and this can take a lot of " +
"space in this text."
)
@cavin-macwan
cavin-macwan / SwipeToDeleteContainer.kt
Created February 3, 2025 17:51
Implements a swipe-to-delete feature using SwipeToDismiss
@Composable
fun <T> SwipeToDeleteContainer(
item: T,
onDelete: (T) -> Unit,
animationDuration: Int = 500,
content: @Composable (T) -> Unit
) {
var isRemoved by remember {
mutableStateOf(false)
}
@cavin-macwan
cavin-macwan / AnimatedFloatingActionButton.kt
Created February 3, 2025 17:24
A FAB that rotates smoothly when clicked, useful for toggling UI elements.
@OptIn(ExperimentalMaterial3Api::class)
@Composable
fun AnimatedFloatingActionButton() {
val context = LocalContext.current
Scaffold(
topBar = { TopAppBar(title = { Text("Floating Action Button") }) },
containerColor = Color.White,
floatingActionButton = {
MultiFloatingActionButton(
@cavin-macwan
cavin-macwan / StickyHeaderList.kt
Created February 3, 2025 17:05
A LazyColumn that groups items under sticky headers, commonly used for categorizing lists.
import androidx.compose.foundation.ExperimentalFoundationApi
import androidx.compose.foundation.background
import androidx.compose.foundation.layout.fillMaxWidth
import androidx.compose.foundation.layout.padding
import androidx.compose.foundation.lazy.LazyColumn
import androidx.compose.foundation.lazy.items
import androidx.compose.material3.ExperimentalMaterial3Api
import androidx.compose.material3.Scaffold
import androidx.compose.material3.Text
import androidx.compose.material3.TopAppBar
@cavin-macwan
cavin-macwan / WallOfTextAnimation.kt
Created October 29, 2024 17:54
Wall of Text Animation
import androidx.compose.animation.Animatable
import androidx.compose.animation.core.Animatable
import androidx.compose.animation.core.LinearEasing
import androidx.compose.animation.core.tween
import androidx.compose.foundation.background
import androidx.compose.foundation.layout.Box
import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.fillMaxSize
import androidx.compose.material3.MaterialTheme
import androidx.compose.material3.Text
@cavin-macwan
cavin-macwan / card_widget.dart
Created June 24, 2023 13:20
Card widget example for inherited widget
class ColorCardWidget extends StatelessWidget {
const ColorCardWidget({super.key});
@override
Widget build(BuildContext context) {
return Container(
color: ColorWidget.of(context)!.color,
height: 500,
width: 500,
);
@cavin-macwan
cavin-macwan / inherited_stateful_wdiget.dart
Created June 24, 2023 13:18
Demo of StatefulWidget for Inherited Widget example
class HomeScreen extends StatefulWidget {
const HomeScreen({super.key});
@override
State<HomeScreen> createState() => _HomeScreenState();
}
class _HomeScreenState extends State<HomeScreen> {
Color color = Colors.red;