View BackCompatHandler.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
/** | |
* See Also: BackHandler { onBack() } | |
*/ | |
@Composable | |
fun BackCompatHandler( | |
enabled: Boolean = true, | |
onBack: () -> Unit = {} | |
) { | |
val currentOnBack by rememberUpdatedState(onBack) | |
val backCallback = remember { |
View byWeakReference.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> byWeakReference(initialValue: T? = null): MutableProperty<T?> = mutablePropertyOf(WeakReference(initialValue)).map( | |
set = { if (this.field.get() == it) this.field else WeakReference(it) }, | |
get = { it.get() }, | |
) |
View IBreakIterator.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 android.os.Build | |
import androidx.annotation.RequiresApi | |
import java.text.BreakIterator | |
import java.text.CharacterIterator | |
interface IBreakIterator { | |
fun first(): Int | |
fun last(): Int | |
fun next(): Int | |
fun next(value: Int): Int |
View ModifierBorders.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 Modifier.border( | |
top: Dp = 0.dp, | |
bottom: Dp = 0.dp, | |
start: Dp = 0.dp, | |
end: Dp = 0.dp, | |
color: Color, | |
) = border( | |
top = BorderStroke(top, color), | |
bottom = BorderStroke(bottom, color), | |
start = BorderStroke(start, color), |
View GiphyRepository.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
/** | |
* ``` | |
* val giphyRepository = Retrofit.Builder() | |
* .baseUrl("https://api.giphy.com/") | |
* .addConverterFactory(Json { | |
* ignoreUnknownKeys = true | |
* }.asConverterFactory(contentType)) | |
* .build() | |
* .create<GiphyRepository>() | |
* |
View ViewGroup.childrenByType.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
inline fun <reified T : View> ViewGroup.childrenByType(): Sequence<T> = descendantsBreadth.filterIsInstance<T>() | |
val ViewGroup.descendantsBreadth: Sequence<View> | |
get() = sequence { | |
val queue: Queue<View> = LinkedList() | |
this@descendantsBreadth.forEach { child -> queue.offer(child) } | |
var child = queue.poll() | |
while (child != null) { | |
yield(child) |
View findDeclaredField.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
inline fun <reified T> Any.getDeclaredFieldValue(fieldName: String): T = | |
javaClass.findDeclaredField(fieldName).run { | |
if (!isAccessible) isAccessible = true | |
get(this@getDeclaredFieldValue) as T | |
} | |
inline fun <reified T> Any.getDeclaredFieldValueOrNull(fieldName: String): T? = | |
try { getDeclaredFieldValue(fieldName) } | |
catch (e: NoSuchFieldException) { null } | |
catch (e: SecurityException) { null } |
View NestedScrollingChildImpl-crash.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
private val childHelper by lazy { NestedScrollingChildHelper(this).apply { | |
//isNestedScrollingEnabled = false | |
} } | |
init { | |
isNestedScrollingEnabled = true | |
} | |
override fun setNestedScrollingEnabled(enabled: Boolean) { | |
return childHelper.setNestedScrollingEnabled(enabled) // Caused by: java.lang.NullPointerException: Attempt to invoke interface method 'java.lang.Object kotlin.Lazy.getValue()' on a null object reference |
NewerOlder