diff --git a/GaiaXAdapterAndroid/src/main/java/com/alibaba/gaiax/adapter/GXAdapterLottieAnimation.kt b/GaiaXAdapterAndroid/src/main/java/com/alibaba/gaiax/adapter/GXAdapterLottieAnimation.kt index 3064d5e58..fc1283def 100644 --- a/GaiaXAdapterAndroid/src/main/java/com/alibaba/gaiax/adapter/GXAdapterLottieAnimation.kt +++ b/GaiaXAdapterAndroid/src/main/java/com/alibaba/gaiax/adapter/GXAdapterLottieAnimation.kt @@ -174,7 +174,6 @@ class GXAdapterLottieAnimation : GXLottieAnimation() { if (lottieContainer.childCount == 0) { lottieView.isClickable = false - lottieContainer.isClickable = false lottieContainer.addView(lottieView) } } @@ -269,7 +268,6 @@ class GXAdapterLottieAnimation : GXLottieAnimation() { if (lottieContainer.childCount == 0) { lottieView.isClickable = false - lottieContainer.isClickable = false lottieContainer.addView(lottieView) } } diff --git a/GaiaXAndroid/src/main/kotlin/com/alibaba/gaiax/data/GXDataImpl.kt b/GaiaXAndroid/src/main/kotlin/com/alibaba/gaiax/data/GXDataImpl.kt index 8f5497b02..010d1a67b 100644 --- a/GaiaXAndroid/src/main/kotlin/com/alibaba/gaiax/data/GXDataImpl.kt +++ b/GaiaXAndroid/src/main/kotlin/com/alibaba/gaiax/data/GXDataImpl.kt @@ -76,7 +76,7 @@ class GXDataImpl(val context: Context) { dataSourceSorted.forEach { it -> it.source.getTemplate(gxTemplateItem)?.let { return it } } - throw IllegalArgumentException("Not found target template path, templateItem = $gxTemplateItem") + throw IllegalArgumentException("Not found target gxTemplate, templateItem = $gxTemplateItem") } fun registerByPriority(source: GXRegisterCenter.GXIExtensionTemplateSource, priority: Int) { @@ -139,7 +139,7 @@ class GXDataImpl(val context: Context) { dataSourceSorted.forEach { it.source.getTemplateInfo(gxTemplateItem)?.let { return it } } - throw IllegalStateException("Template exist but reference is null") + throw IllegalArgumentException("Not found target gxTemplateInfo, templateItem = $gxTemplateItem") } fun registerByPriority( diff --git a/GaiaXAndroid/src/main/kotlin/com/alibaba/gaiax/data/cache/GXTemplateInfoSource.kt b/GaiaXAndroid/src/main/kotlin/com/alibaba/gaiax/data/cache/GXTemplateInfoSource.kt index 397d23a0b..397e26b5d 100644 --- a/GaiaXAndroid/src/main/kotlin/com/alibaba/gaiax/data/cache/GXTemplateInfoSource.kt +++ b/GaiaXAndroid/src/main/kotlin/com/alibaba/gaiax/data/cache/GXTemplateInfoSource.kt @@ -19,7 +19,7 @@ class GXTemplateInfoSource(val context: Context) : GXRegisterCenter.GXIExtension override fun getTemplateInfo(gxTemplateItem: GXTemplateEngine.GXTemplateItem): GXTemplateInfo? { return if (exist(gxTemplateItem.bizId, gxTemplateItem.templateId)) { dataCache[gxTemplateItem.bizId]?.get(gxTemplateItem.templateId) - ?: throw IllegalStateException("Template exist but reference is null") + ?: throw IllegalArgumentException("Template exist but reference is null") } else { val template = GXTemplateInfo.createTemplate(gxTemplateItem) return template.apply { diff --git a/GaiaXAndroid/src/main/kotlin/com/alibaba/gaiax/render/node/GXTemplateNode.kt b/GaiaXAndroid/src/main/kotlin/com/alibaba/gaiax/render/node/GXTemplateNode.kt index 789978ee5..a6dcdabbc 100644 --- a/GaiaXAndroid/src/main/kotlin/com/alibaba/gaiax/render/node/GXTemplateNode.kt +++ b/GaiaXAndroid/src/main/kotlin/com/alibaba/gaiax/render/node/GXTemplateNode.kt @@ -21,6 +21,7 @@ import com.alibaba.fastjson.JSONObject import com.alibaba.gaiax.context.GXTemplateContext import com.alibaba.gaiax.template.* import com.alibaba.gaiax.template.animation.GXAnimationBinding +import java.lang.IllegalArgumentException /** * @suppress @@ -218,7 +219,7 @@ data class GXTemplateNode( visualTemplateNode: GXTemplateNode? = null ): GXTemplateNode { val layer = template.findLayer(viewId) - ?: throw IllegalStateException("Not found layer by view id, viewId = $viewId") + ?: throw IllegalArgumentException("Not found layer by view id, viewId = $viewId") val css = template.findCss(viewId) ?: GXCss.create() val dataBinding = template.findData(viewId) val eventBinding = template.findEvent(viewId) diff --git a/GaiaXAndroidDemo/app/src/main/assets/templates/gx-content-uper-top/index.databinding b/GaiaXAndroidDemo/app/src/main/assets/templates/gx-content-uper-top/index.databinding index 2b373188e..4afbea45f 100755 --- a/GaiaXAndroidDemo/app/src/main/assets/templates/gx-content-uper-top/index.databinding +++ b/GaiaXAndroidDemo/app/src/main/assets/templates/gx-content-uper-top/index.databinding @@ -29,9 +29,9 @@ "value": "$recReason.title" }, "follow-text": { - "value":"'按钮'", + "value":"$isFollowed ? '已关注' : '关注'", "extend":{ - "color":"'#24a5ff'" + "color":"$isFollowed ? '#24a5ff' : 'red'" } }, "follow-bg": { diff --git a/GaiaXAndroidDemo/app/src/main/kotlin/com/alibaba/gaiax/demo/EventTemplateActivity.kt b/GaiaXAndroidDemo/app/src/main/kotlin/com/alibaba/gaiax/demo/EventTemplateActivity.kt index a7e8076c1..77d14522c 100644 --- a/GaiaXAndroidDemo/app/src/main/kotlin/com/alibaba/gaiax/demo/EventTemplateActivity.kt +++ b/GaiaXAndroidDemo/app/src/main/kotlin/com/alibaba/gaiax/demo/EventTemplateActivity.kt @@ -1,12 +1,12 @@ package com.alibaba.gaiax.demo import android.os.Bundle -import android.util.Log import androidx.appcompat.app.AppCompatActivity import androidx.appcompat.widget.LinearLayoutCompat import com.alibaba.gaiax.GXTemplateEngine import com.alibaba.gaiax.demo.utils.AssetsUtils import com.alibaba.gaiax.utils.GXScreenUtils +import com.alibaba.gaiax.utils.setValueExt class EventTemplateActivity : AppCompatActivity() { companion object { @@ -20,6 +20,8 @@ class EventTemplateActivity : AppCompatActivity() { renderTemplate1(this) } + var isFollowed = false + private fun renderTemplate1(activity: EventTemplateActivity) { // 初始化 GXTemplateEngine.instance.init(activity) @@ -31,24 +33,30 @@ class EventTemplateActivity : AppCompatActivity() { val size = GXTemplateEngine.GXMeasureSize(GXScreenUtils.getScreenWidthPx(this), null) // 模板数据 - val templateData = - GXTemplateEngine.GXTemplateData(AssetsUtils.parseAssets(activity, "data/uper.json")) + val data = AssetsUtils.parseAssets(activity, "data/uper.json") + val templateData = GXTemplateEngine.GXTemplateData(data) + + // 创建模板View + val view = GXTemplateEngine.instance.createView(params, size) + templateData.eventListener = object : GXTemplateEngine.GXIEventListener { override fun onGestureEvent(gxGesture: GXTemplateEngine.GXGesture) { super.onGestureEvent(gxGesture) - Log.d(TAG, "onGestureEvent() called with: gxGesture = $gxGesture") - } - - override fun onScrollEvent(gxScroll: GXTemplateEngine.GXScroll) { - super.onScrollEvent(gxScroll) - Log.d(TAG, "onScrollEvent() called with: gxScroll = $gxScroll") + if (gxGesture.nodeId == "follow") { + if (isFollowed) { + data.setValueExt("data.isFollowed", false) + GXTemplateEngine.instance.bindData(view, templateData) + isFollowed = false + } else { + data.setValueExt("data.isFollowed", true) + GXTemplateEngine.instance.bindData(view, templateData) + isFollowed = true + } + } } } - // 创建模板View - val view = GXTemplateEngine.instance.createView(params, size) - // 绑定数据 GXTemplateEngine.instance.bindData(view, templateData)