View registerForActivityResult.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
fun <I> ActivityResultCaller.registerForActivityResult( | |
onCreateIntent: Context.(input: I) -> Intent, | |
callback: ActivityResultCallback<Pair<Int, Intent?>>, | |
) = registerForActivityResult( | |
activityResultContract(onCreateIntent), | |
callback, | |
) | |
/** | |
* ``` |
View DashedBorder.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import androidx.compose.foundation.BorderStroke | |
/* | |
* Copyright 2020 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 |
View side_sheet.dart
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import 'dart:ui'; | |
import 'package:flutter/foundation.dart'; | |
import 'package:flutter/material.dart'; | |
const Duration _sideSheetEnterDuration = Duration(milliseconds: 250); | |
const Duration _sideSheetExitDuration = Duration(milliseconds: 200); | |
const Curve _modalSideSheetCurve = decelerateEasing; | |
const double _minFlingVelocity = 700.0; | |
const double _closeProgressThreshold = 0.5; |
View View.scrollChangesCompact.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@RequiresApi(Build.VERSION_CODES.M) | |
fun View.scrollChanges() = callbackFlow { | |
val listener = View.OnScrollChangeListener { v, scrollX, scrollY, oldScrollX, oldScrollY -> | |
trySendBlocking(Quintuple(v, scrollX, scrollY, oldScrollX, oldScrollY)) | |
} | |
setOnScrollChangeListener(listener) | |
awaitClose { setOnScrollChangeListener(null) } | |
} | |
fun ViewTreeObserver.scrollChanges() = callbackFlow { |
View reflections.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
fun <T : Any> Class<T>.getDeclaredFieldOrNull(name: String): Field? = | |
tryOrNull { getDeclaredField(name) } | |
@Suppress("SpreadOperator") | |
fun <T : Any> Class<T>.getDeclaredMethodOrNull(name: String, vararg parameterTypes: Class<*>): Method? = | |
tryOrNull { getDeclaredMethod(name, *parameterTypes) } | |
@Suppress("SpreadOperator") | |
fun <T : Any> Class<T>.getDeclaredConstructorOrNull(vararg parameterTypes: Class<*>): Constructor<T>? = | |
tryOrNull { getDeclaredConstructor(*parameterTypes) } |
View MemoizedInterceptor.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* Intercepts and caches memoized responses based on the provided LruCache. | |
* | |
* @property cache an instance of LruCache to store the responses. | |
*/ | |
class MemoizedInterceptor(private val cache: LruCache<String, Response>) : Interceptor { | |
/** | |
* Callback that will be invoked when a cached response is found. | |
* @param request the request being executed. | |
* @param isFresh `true` if the cached response is still fresh, `false` otherwise. |
View context.activity.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@JvmName("getActivityInternal") | |
internal tailrec fun Context.getActivity(): Activity? = | |
this as? Activity | |
?: (this as? ContextWrapper)?.baseContext?.getActivity() | |
val Context.activity: Activity? get() = getActivity() | |
val View.activity: Activity? get() = context.getActivity() |
View SimpleLifecycleObserver.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class SimpleLifecycleObserver( | |
var onCreate: SimpleLifecycleObserver.(LifecycleOwner) -> Unit = {}, | |
var onStart: SimpleLifecycleObserver.(LifecycleOwner) -> Unit = {}, | |
var onResume: SimpleLifecycleObserver.(LifecycleOwner) -> Unit = {}, | |
var onPause: SimpleLifecycleObserver.(LifecycleOwner) -> Unit = {}, | |
var onStop: SimpleLifecycleObserver.(LifecycleOwner) -> Unit = {}, | |
var onDestroy: SimpleLifecycleObserver.(LifecycleOwner) -> Unit = {}, | |
) : DefaultLifecycleObserver { | |
fun onCreate(onCreate: SimpleLifecycleObserver.(LifecycleOwner) -> Unit) = apply { | |
this.onCreate = onCreate |
View WipEllipsisText.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@Preview | |
@Composable | |
fun EllipsisTextPreview( | |
) { | |
EllipsisText( | |
text = "This is a very long text that should This is a very long text that should This is a very long text that should bbbThis is a very long text that should be truncated", | |
maxLines = 2, | |
) | |
} |
View EllipseText.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@Composable | |
fun EllipseText( | |
text: String, | |
modifier: Modifier = Modifier, | |
style: TextStyle = LocalTextStyle.current, | |
fontStyle: FontStyle? = null, | |
maxLines: Int = Int.MAX_VALUE, | |
onMoreText: Context.() -> String = { "... Show More" }, | |
moreTextStyle: SpanStyle = SpanStyle(fontWeight = FontWeight.W500), | |
textAlign: TextAlign? = null |
NewerOlder