Skip to content

Instantly share code, notes, and snippets.

@riggaroo
riggaroo / GradientAlongPathAnimation.kt
Last active May 29, 2024 19:11
Gradient along a path using path.flatten in Compose, Inspired by William Candillon https://youtu.be/7SCzL-XnfUU, this uses Jetpack Compose to draw a gradient along a path https://github.com/wcandillon/can-it-be-done-in-react-native/tree/master/bonuses/skia-examples/src/PathGradient
package androidx.compose.samples.animationfactory
import androidx.compose.animation.core.Animatable
import androidx.compose.animation.core.infiniteRepeatable
import androidx.compose.animation.core.tween
import androidx.compose.foundation.Canvas
import androidx.compose.foundation.layout.Box
import androidx.compose.foundation.layout.aspectRatio
import androidx.compose.foundation.layout.fillMaxSize
import androidx.compose.foundation.layout.padding
@riggaroo
riggaroo / CompositingStrategyOffscreenExample.kt
Last active May 27, 2024 16:20
GraphicsLayer CompositingStrategy Example demonstrating offscreen compositing strategy in Jetpack Compose, leveraging BlendMode.Clear to mask some of the image away.
/* Copyright 2022 Google LLC.
SPDX-License-Identifier: Apache-2.0 */
@Composable
fun GraphicsLayerCompositingStrategyExample() {
Image(painter = painterResource(id = R.drawable.dog),
contentDescription = "Dog",
contentScale = ContentScale.Crop,
modifier = Modifier
.size(120.dp)
.aspectRatio(1f)
@cse-ariful
cse-ariful / BaseFragment.kt
Last active November 17, 2022 06:56
A Base Implementation of Fragment and is Very easy to work with fragments. Implemented most of the things you need on regular.
import android.os.Bundle
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import androidx.activity.OnBackPressedCallback
import androidx.fragment.app.Fragment
import androidx.viewbinding.ViewBinding
typealias Inflate<T> = (LayoutInflater, ViewGroup?, Boolean) -> T
@stevdza-san
stevdza-san / HyperlinkText.kt
Last active May 6, 2024 11:14
Embedd a Hyperlink within a Text using Jetpack Compose.
import androidx.compose.foundation.text.ClickableText
import androidx.compose.runtime.Composable
import androidx.compose.ui.Modifier
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.platform.LocalUriHandler
import androidx.compose.ui.text.SpanStyle
import androidx.compose.ui.text.buildAnnotatedString
import androidx.compose.ui.text.font.FontWeight
import androidx.compose.ui.text.style.TextDecoration
import androidx.compose.ui.unit.TextUnit
@trevorhackman
trevorhackman / NullOnDestroy.kt
Created December 11, 2021 23:24
For nulling something on destroy, primary motivation, a better way to do view binding.
/**
* Delegate for use in fragments
*
* When the fragment's view is destroyed the field will be set to null.
* This happens immediately before the fragment's onDestroyView() is called.
*
* Additionally, this delegate gives the same behavior as lateinit.
*
* Property should be a non-nullable var.
*/
@mkovalyk
mkovalyk / PermissionManager.kt
Last active November 2, 2022 08:04
Make Android permission easier
package com.example.myapplication
import android.content.pm.PackageManager
import androidx.activity.result.ActivityResultLauncher
import androidx.activity.result.contract.ActivityResultContracts
import androidx.core.app.ActivityCompat
import androidx.core.content.ContextCompat
import androidx.fragment.app.Fragment
import androidx.lifecycle.Lifecycle
import androidx.lifecycle.LifecycleObserver
@franzwarning
franzwarning / MultipleDeviceScreengrabFastfile
Last active May 24, 2023 13:13
Fastlane capture_android_screenshots/screengrab android on multiple devices at the same time
lane :build_for_screenshots do
gradle(
task: 'assemble',
build_type: 'Screenshots'
)
gradle(
task: 'assemble',
build_type: 'ScreenshotsAndroidTest'
)
end
@collinjackson
collinjackson / nested_scroll_view.dart
Last active September 25, 2022 05:29
nestedscrollview example
// Copyright 2017, the Flutter project authors. Please see the AUTHORS file
// for details. All rights reserved. Use of this source code is governed by a
// BSD-style license that can be found in the LICENSE file.
import 'package:flutter/material.dart';
void main() {
runApp(new TestApp());
}
/*
* Copyright 2017 Google Inc. All rights reserved.
*
* 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
@ilya-g
ilya-g / cancellationTest.kt
Last active December 21, 2018 06:42
Cancellation support interceptor
class JobCancellationInterceptor(val originalInterceptor: ContinuationInterceptor?) :
AbstractCoroutineContextElement(ContinuationInterceptor),
ContinuationInterceptor {
override fun <T> interceptContinuation(continuation: Continuation<T>): Continuation<T> =
CancellableCheckContinuation(continuation).let {
originalInterceptor?.interceptContinuation(it) ?: it
}
class CancellableCheckContinuation<T>(val continuation: Continuation<T>) : Continuation<T> {