Skip to content

Instantly share code, notes, and snippets.

View chrisbanes's full-sized avatar

Chris Banes chrisbanes

View GitHub Profile
@chrisbanes
chrisbanes / Sample.kt
Last active April 23, 2024 11:40
Compose Multiplatform UIViewController with transparent background
fun myUIViewController(
content: @Composable () -> Unit,
): UIViewController = ComposeUIViewController {
val controller = LocalUIViewController.current
DisposableEffect(controller) {
controller.forceTransparentBackground()
onDispose { /* no-op */ }
}
// Rest of your Compose code
@chrisbanes
chrisbanes / moved.txt
Last active February 18, 2023 10:43
A prototype #JetpackCompose Painter which draws an Android Drawable
This is now available at https://google.github.io/accompanist/drawablepainter/
Moved to https://google.github.io/accompanist/insets/
@chrisbanes
chrisbanes / bash_aliases
Created March 30, 2020 13:23
Shell function to set default JDK to Android Studio's bundled JDK
function set-studio-jdk() {
export JAVA_HOME=$1/Contents/jre/jdk/Contents/home/
}
@chrisbanes
chrisbanes / themes.xml
Last active May 6, 2022 03:48
edge_to_edge_legacy_theme
<!-- values/themes.xml -->
<style name="Theme.MyApp">
<item name="android:navigationBarColor">
#B3FFFFFF
</item>
</style>
<!-- values-night/themes.xml -->
<style name="Theme.MyApp">
<item name="android:navigationBarColor">
@chrisbanes
chrisbanes / ScopedViewModel.kt
Last active October 25, 2022 21:29
ScopedViewModel
open class ScopedViewModel : ViewModel() {
private val job = Job()
protected val scope: CoroutineScope = job + Dispatchers.Main
override fun onCleared() {
super.onCleared()
job.cancel()
}
}
@chrisbanes
chrisbanes / CoroutineLifecycleObserver.kt
Last active September 9, 2022 14:07
LifecycleObserver which allows easy cancelling of coroutines
/*
* Copyright 2018 Google LLC
*
* 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
@chrisbanes
chrisbanes / Animators.kt
Last active March 7, 2024 11:13
Material Image Loading treatment for Android
/*
* Copyright 2018 Google, Inc.
*
* 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
@chrisbanes
chrisbanes / code.kt
Last active August 10, 2023 10:46
Night Mode inflater
/*
* Copyright 2017 Google, Inc.
*
* 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
/*
* Copyright (C) 2017 The Android Open Source Project
*
* 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