|
|
@@ -2,53 +2,44 @@ package com.atmob.keyboard_android.component.base
|
|
|
|
|
|
import android.content.Context
|
|
|
import android.util.AttributeSet
|
|
|
-import android.widget.FrameLayout
|
|
|
-import com.atmob.keyboard_android.component.base.animator.ComponentAnimator
|
|
|
|
|
|
/**
|
|
|
- * 带有路由功能的组件基类
|
|
|
+ * 带路由功能的组件
|
|
|
*/
|
|
|
-abstract class RouteComponent @JvmOverloads constructor(
|
|
|
+class RouteComponent @JvmOverloads constructor(
|
|
|
context: Context, attrs: AttributeSet? = null, defStyleAttr: Int = 0
|
|
|
-) : FrameLayout(context, attrs, defStyleAttr), IUIComponent {
|
|
|
+) : GroupComponent(context, attrs, defStyleAttr) {
|
|
|
/**
|
|
|
- * 动画执行器
|
|
|
+ * 切换子组件,也就是先隐藏掉所有兄弟组件,再显示自己
|
|
|
+ *
|
|
|
+ * @param mutex 是否互斥,如果为true,则会隐藏其他子组件后,再显示自己,为false则是不隐藏兄弟组件,直接显示自己
|
|
|
*/
|
|
|
- private val mComponentAnimator: ComponentAnimator
|
|
|
-
|
|
|
- init {
|
|
|
- mComponentAnimator = getComponentAnimator().newInstance() as ComponentAnimator
|
|
|
- mComponentAnimator.attachUIComponent(this)
|
|
|
- }
|
|
|
-
|
|
|
- override fun show(onStart: (() -> Unit)?, onFinish: (() -> Unit)?) {
|
|
|
- mComponentAnimator.show(onStart, onFinish = {
|
|
|
- onComponentShow()
|
|
|
- onFinish?.invoke()
|
|
|
- })
|
|
|
- }
|
|
|
-
|
|
|
- override fun hide(onStart: (() -> Unit)?, onFinish: (() -> Unit)?) {
|
|
|
- mComponentAnimator.hide(onStart, onFinish = {
|
|
|
- onComponentHide()
|
|
|
- onFinish?.invoke()
|
|
|
- })
|
|
|
- }
|
|
|
-
|
|
|
- /**
|
|
|
- * 获取组件的动画执行器
|
|
|
- */
|
|
|
- protected abstract fun getComponentAnimator(): Class<*>
|
|
|
-
|
|
|
- /**
|
|
|
- * 组件打开时回调
|
|
|
- */
|
|
|
- protected fun onComponentShow() {
|
|
|
- }
|
|
|
-
|
|
|
- /**
|
|
|
- * 组件关闭时回调
|
|
|
- */
|
|
|
- protected fun onComponentHide() {
|
|
|
+ fun <T : IUIComponent> toggleChildComponent(
|
|
|
+ targetComponentClass: Class<T>,
|
|
|
+ mutex: Boolean = true
|
|
|
+ ) {
|
|
|
+ // 获取所有直接子组件
|
|
|
+ val directChildComponentList = getDirectChildComponentList()
|
|
|
+
|
|
|
+ // 找到目标组件
|
|
|
+ val targetComponent: IUIComponent? = directChildComponentList.find {
|
|
|
+ // 检查当前子View,是否是目标类型
|
|
|
+ targetComponentClass.isInstance(it)
|
|
|
+ }
|
|
|
+
|
|
|
+ if (targetComponent != null) {
|
|
|
+ // 找到兄弟组件
|
|
|
+ if (mutex) {
|
|
|
+ val siblingComponentList = directChildComponentList.filter {
|
|
|
+ !targetComponentClass.isInstance(it)
|
|
|
+ }.toList()
|
|
|
+ // 先隐藏所有兄弟
|
|
|
+ siblingComponentList.forEach {
|
|
|
+ it.hide()
|
|
|
+ }
|
|
|
+ }
|
|
|
+ // 再显示自己
|
|
|
+ targetComponent.show()
|
|
|
+ }
|
|
|
}
|
|
|
}
|