Skip to content

Instantly share code, notes, and snippets.

View TemMax's full-sized avatar
💥

Artsiom Komar TemMax

💥
View GitHub Profile
@TemMax
TemMax / SoftwareLayerComposable.kt
Last active June 24, 2022 10:32
A little hack when you want to use layer type for composable
import android.view.View
import androidx.compose.runtime.Composable
import androidx.compose.ui.Modifier
import androidx.compose.ui.platform.ComposeView
import androidx.compose.ui.viewinterop.AndroidView
@Composable
fun SoftwareLayerComposable(
modifier: Modifier = Modifier,
@TemMax
TemMax / CombinePostProcessors.kt
Last active January 13, 2021 21:35
Postprocessor for Facebook's Fresco library that combines few postprocessors
import android.graphics.Bitmap
import com.facebook.common.references.CloseableReference
import com.facebook.imagepipeline.bitmaps.PlatformBitmapFactory
import com.facebook.imagepipeline.request.BasePostprocessor
class CombinePostProcessors(
private val processors: List<BasePostprocessor>
) : BasePostprocessor() {
@TemMax
TemMax / suspendRetry.kt
Last active January 7, 2021 12:35
A function that wraps another suspend function for exponential retry
/**
* A function that wraps another suspend function for exponential retry
*
* @param count number of retires
* @param initialDelay millis between retries
* @param maxDelay max millis of delay from exponential backoff strategy
* @param factor delay multiplier
* @param predicate true — need continue retries, false — rethrows Throwable to caller
* @param block function to execute
*
@TemMax
TemMax / kba.kt
Last active January 7, 2021 14:59
// ======================= WINDOW INSETS =======================
fun View.addSystemTopPadding(
targetView: View = this,
isConsumed: Boolean = false
) {
doOnApplyWindowInsets { _, insets, initialPadding ->
targetView.updatePadding(
top = initialPadding.top + insets.systemWindowInsetTop
)
@TemMax
TemMax / KeyboardAwareFrameLayout.kt
Last active October 8, 2020 09:51
Keyboard-aware FrameLayout that fits when keyboard is opened. 100 dp is a magic dimension. Waiting for WindowInsets update with Android 11
import android.content.Context
import android.util.AttributeSet
import android.widget.FrameLayout
import androidx.core.view.ViewCompat
import androidx.core.view.WindowInsetsCompat
/**
* Before adding this:
* 1. In AndroidManifest in your <activity/> tag android:windowSoftInputMode="adjustResize"
* 2. Enable "EDGE-TO-EDGE" mode in your activity -> window.decorView.systemUiVisibility = decorView.systemUiVisibility or (View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION or View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN or View.SYSTEM_UI_FLAG_LAYOUT_STABLE)