Skip to content

Instantly share code, notes, and snippets.

View kishan-vadoliya's full-sized avatar

Kishan Vadoliya kishan-vadoliya

View GitHub Profile
@kishan-vadoliya
kishan-vadoliya / ModalBottomSheet.kt
Last active December 30, 2023 12:46
Bottom sheet In JetPack compose
/* Ref: https://www.composables.com/tutorials/bottomsheet */
val sheetState = rememberModalBottomSheetState(
initialValue = ModalBottomSheetValue.Hidden
)
val scope = rememberCoroutineScope()
ModalBottomSheetLayout(sheetState = sheetState, sheetContent = {
Column(Modifier.padding(16.dp)) {
repeat(3) { index ->
@kishan-vadoliya
kishan-vadoliya / ModalBottomSheet.kt
Last active December 30, 2023 12:46
Modal Bottom Sheet Layout Jetpack Compose
// Ref: https://medium.com/@emreuysall/manage-multiple-content-actions-and-states-modalbottomsheetlayout-jetpack-compose-ec4140b2a043
// 1- Identify User Action
// Identify user actions
enum class BottomSheetAction {
INITIAL, // initial case before user action
HIDE, // user wants to hide bottom sheet
SHOW, // user wants to show bottom sheet
TIMED // user wants to see and hide bottom sheet for some time, and disables screen interaction
}
@kishan-vadoliya
kishan-vadoliya / DarkLightTheme.kt
Created October 19, 2023 05:11
Multi theme in jetpack compose
// # Dark and light theme
// 01- Color
val colorBlue = Color(0xFF001E63)
val colorBlue1 = Color(0xFF000063)
val colorRed = Color(0xFF5A0000)
val colorGreen = Color(0xFF003A00)
val colorWhite = Color(0xFFFFFFFF)
val colorBlack = Color(0xE9000000)
@kishan-vadoliya
kishan-vadoliya / ModalSheetWithAnchor.kt
Created October 19, 2023 05:57
ModalSheetWithAnchor
// https://developersbreach.com/modal-bottom-sheet-jetpack-compose-android/
@Composable
fun BottomSheetWithAnchor() {
val sheetState = rememberBottomSheetState(initialValue = BottomSheetValue.Collapsed)
val scope = rememberCoroutineScope()
val sheetScaffoldState = rememberBottomSheetScaffoldState(
bottomSheetState = sheetState
)
@kishan-vadoliya
kishan-vadoliya / ModalBottomSheet.kt
Created October 19, 2023 06:26
ModalBottomSheetLayout for Material 3 Jetpack Compose
import androidx.compose.animation.core.AnimationSpec
import androidx.compose.animation.core.TweenSpec
import androidx.compose.animation.core.animateFloatAsState
import androidx.compose.foundation.Canvas
import androidx.compose.foundation.gestures.Orientation
import androidx.compose.foundation.gestures.detectTapGestures
import androidx.compose.foundation.layout.Box
import androidx.compose.foundation.layout.BoxWithConstraints
import androidx.compose.foundation.layout.Column
@kishan-vadoliya
kishan-vadoliya / ImageGlanceWidget.kt
Last active December 30, 2023 12:45
ImageGlanceWidget using recomposition + coil
// Copyright 2022 Google LLC.
// SPDX-License-Identifier: Apache-2.0
import android.content.Context
import android.graphics.Bitmap
import androidx.compose.runtime.Composable
import androidx.compose.runtime.LaunchedEffect
import androidx.compose.runtime.getValue
import androidx.compose.runtime.mutableStateOf
import androidx.compose.runtime.remember
@kishan-vadoliya
kishan-vadoliya / AppWidget.kt
Last active December 30, 2023 12:45
Android App Widget Development with Glance
// https://medium.com/atlas/android-app-widget-development-with-glance-532a5a8d602c
// User Interface
<!-- API 31 (Android 12 and up) -->
<appwidget-provider xmlns:android="http://schemas.android.com/apk/res/android"
android:description="@string/widget_description"
android:minWidth="200dp"
android:minHeight="200dp"
android:resizeMode="horizontal|vertical"
android:previewImage="@drawable/calendar_widget_preview_image"
@kishan-vadoliya
kishan-vadoliya / ComposeOverlayViewService.kt
Created October 20, 2023 09:04
Jetpack Compose OverlayService. Service ready to display complete view (with the right context to access the window manager and layout inflater if needed, but also access to a saved state registry and a view model store owner). Then a compose overlay service, that use the first one to push a compose view as system overlay, and also proposing a s…
import android.content.Intent
import android.graphics.PixelFormat
import android.os.IBinder
import android.view.Gravity
import android.view.WindowManager
import androidx.compose.foundation.gestures.detectDragGestures
import androidx.compose.foundation.layout.Box
import androidx.compose.foundation.layout.BoxScope
import androidx.compose.runtime.Composable
import androidx.compose.runtime.getValue
@kishan-vadoliya
kishan-vadoliya / InstallReferrerExt.kt
Created October 20, 2023 09:04
Install Referrer KTX - Kotlin Coroutine friendly wrapper for the Google Play's InstallReferrerClient API. This API is used to ask Google Play about where the installation originated.
import android.content.Context
import android.os.RemoteException
import com.android.installreferrer.api.InstallReferrerClient
import com.android.installreferrer.api.InstallReferrerStateListener
import com.android.installreferrer.api.ReferrerDetails
import kotlinx.coroutines.CompletableDeferred
/**
* https://developer.android.com/google/play/installreferrer/library
*
@kishan-vadoliya
kishan-vadoliya / BouncyRopes.kt
Created October 20, 2023 09:25
Jetpack Compose Bouncy Ropes
/* Copyright 2022 Google LLC.
SPDX-License-Identifier: Apache-2.0 */
@Composable
fun BouncyRopes() {
val startCoOrdinate by remember {
mutableStateOf(Offset(0f, 0f))
}
var endCoOrdinate by remember {
mutableStateOf(Offset(100f, 0f))
}