Created
June 15, 2021 08:03
-
-
Save dzungvu/0cedd043801c628fc79fe71ac2d17292 to your computer and use it in GitHub Desktop.
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 TraverseLayoutInterceptorCompositor( | |
private val interceptors: Map<Class<out View>, TraverseLayoutInterceptor<out View>> | |
) : TraverseLayoutInterceptor<View> { | |
override fun interceptAttrs(view: View, attrs: AttributeSet) { | |
(peekInterceptor(view) as? TraverseLayoutInterceptor<View>)?.run { | |
interceptAttrs(view, attrs) | |
} ?: Log.d("InterceptorCompositor", "Get view interceptor failure") | |
} | |
private fun peekInterceptor(view: View) = | |
interceptors[view::class.java] ?: searchAssignableInterceptor(view) | |
private fun searchAssignableInterceptor(view: View): TraverseLayoutInterceptor<out View>? { | |
interceptors.forEach { (clz, interceptor) -> | |
if (clz.isAssignableFrom(view::class.java)) { | |
return interceptor | |
} | |
} | |
return null | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment