This file contains hidden or 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() | |
| [email protected] { child -> queue.offer(child) } | |
| var child = queue.poll() | |
| while (child != null) { | |
| yield(child) |
This file contains hidden or 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 } |
This file contains hidden or 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 |
This file contains hidden or 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 NestedScrollingChildImpl(val view: View) : NestedScrollingChild3 { | |
| private val childHelper by lazy { NestedScrollingChildHelper(view) } | |
| override fun setNestedScrollingEnabled(enabled: Boolean) { | |
| return childHelper.setNestedScrollingEnabled(enabled) | |
| } | |
| override fun isNestedScrollingEnabled(): Boolean { | |
| return childHelper.isNestedScrollingEnabled | |
| } |
This file contains hidden or 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 |
This file contains hidden or 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 { |
This file contains hidden or 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) } |
This file contains hidden or 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() |