diff --git a/GaiaXAndroid/src/androidTest/java/com/alibaba/gaiax/GXComponentGridTest.kt b/GaiaXAndroid/src/androidTest/java/com/alibaba/gaiax/GXComponentGridTest.kt index 691c691ea..13a6c3bce 100644 --- a/GaiaXAndroid/src/androidTest/java/com/alibaba/gaiax/GXComponentGridTest.kt +++ b/GaiaXAndroid/src/androidTest/java/com/alibaba/gaiax/GXComponentGridTest.kt @@ -1239,10 +1239,7 @@ class GXComponentGridTest : GXBaseTest() { Assert.assertEquals(1080F.dpToPx(), rootView.width()) Assert.assertEquals(200F.dpToPx(), rootView.height()) Assert.assertEquals(true, (rootView as? RecyclerView)?.layoutManager?.canScrollVertically()) - Assert.assertEquals( - false, - (rootView as? RecyclerView)?.layoutManager?.canScrollHorizontally() - ) + Assert.assertEquals(false, (rootView as? RecyclerView)?.layoutManager?.canScrollHorizontally()) } @Test @@ -1280,14 +1277,8 @@ class GXComponentGridTest : GXBaseTest() { Assert.assertEquals(1080F.dpToPx(), rootView.child(1).width()) Assert.assertEquals(100F.dpToPx(), rootView.child(1).height()) - Assert.assertEquals( - true, - (rootView.child(1) as? RecyclerView)?.layoutManager?.canScrollVertically() - ) - Assert.assertEquals( - false, - (rootView.child(1) as? RecyclerView)?.layoutManager?.canScrollHorizontally() - ) + Assert.assertEquals(true, (rootView.child(1) as? RecyclerView)?.layoutManager?.canScrollVertically()) + Assert.assertEquals(false, (rootView.child(1) as? RecyclerView)?.layoutManager?.canScrollHorizontally()) } @Test @@ -1316,10 +1307,7 @@ class GXComponentGridTest : GXBaseTest() { rootView.executeRecyclerView() - Assert.assertEquals( - Color.parseColor("#e4e4e4"), - (rootView?.background as? GradientDrawable)?.colors?.get(0) - ) + Assert.assertEquals(Color.parseColor("#e4e4e4"), (rootView?.background as? GradientDrawable)?.colors?.get(0)) } @Test @@ -1427,5 +1415,8 @@ class GXComponentGridTest : GXBaseTest() { Assert.assertEquals(1080F.dpToPx(), rootView.width()) Assert.assertEquals(100F.dpToPx() * 2 + 200F.dpToPx(), rootView.height()) + Assert.assertEquals(100F.dpToPx(), rootView.child(0).height()) + Assert.assertEquals(200F.dpToPx(), rootView.child(1).height()) + Assert.assertEquals(100F.dpToPx(), rootView.child(2).height()) } } \ No newline at end of file diff --git a/GaiaXAndroid/src/main/kotlin/com/alibaba/gaiax/GXTemplateEngine.kt b/GaiaXAndroid/src/main/kotlin/com/alibaba/gaiax/GXTemplateEngine.kt index e3da66604..fb4e22b29 100644 --- a/GaiaXAndroid/src/main/kotlin/com/alibaba/gaiax/GXTemplateEngine.kt +++ b/GaiaXAndroid/src/main/kotlin/com/alibaba/gaiax/GXTemplateEngine.kt @@ -690,9 +690,7 @@ class GXTemplateEngine { ): GXTemplateContext { val gxTemplateInfo = data.getTemplateInfo(gxTemplateItem) - val gxTemplateContext = GXTemplateContext.createContext( - gxTemplateItem, gxMeasureSize, gxTemplateInfo, gxExtendParams?.gxVisualTemplateNode - ) + val gxTemplateContext = GXTemplateContext.createContext(gxTemplateItem, gxMeasureSize, gxTemplateInfo, gxExtendParams?.gxVisualTemplateNode) val gxHostTemplateContext = gxExtendParams?.gxHostTemplateContext if (gxHostTemplateContext != null) { @@ -712,9 +710,7 @@ class GXTemplateEngine { * @suppress * @hide */ - fun createViewOnlyViewTree( - gxTemplateContext: GXTemplateContext - ): View? { + fun createViewOnlyViewTree(gxTemplateContext: GXTemplateContext): View? { if (Log.isLog()) { Log.e("createViewOnlyViewTree") } diff --git a/GaiaXAndroid/src/main/kotlin/com/alibaba/gaiax/render/node/GXNodeUtils.kt b/GaiaXAndroid/src/main/kotlin/com/alibaba/gaiax/render/node/GXNodeUtils.kt index e2ed275c1..74d601970 100644 --- a/GaiaXAndroid/src/main/kotlin/com/alibaba/gaiax/render/node/GXNodeUtils.kt +++ b/GaiaXAndroid/src/main/kotlin/com/alibaba/gaiax/render/node/GXNodeUtils.kt @@ -230,8 +230,22 @@ object GXNodeUtils { val itemTemplateItem = itemTemplatePair.first val itemVisualTemplateNode = itemTemplatePair.second - if (gxTemplateContext.gridItemLayoutCache == null) { - gxTemplateContext.gridItemLayoutCache = computeGridItemLayout( + val assumptionItemsSameHeight = gxNode.templateNode.getExtend()?.getBoolean(GXTemplateKey.GAIAX_GRID_EXTEND_ITEM_SAME_HEIGHT) ?: true + + if (assumptionItemsSameHeight) { + if (gxTemplateContext.gridItemLayoutCache == null) { + gxTemplateContext.gridItemLayoutCache = computeGridItemLayout( + gxTemplateContext, + itemViewPort, + itemTemplateItem, + itemVisualTemplateNode, + itemData, + itemCacheKey + ) + } + return gxTemplateContext.gridItemLayoutCache + } else { + return computeGridItemLayout( gxTemplateContext, itemViewPort, itemTemplateItem, @@ -240,7 +254,6 @@ object GXNodeUtils { itemCacheKey ) } - return gxTemplateContext.gridItemLayoutCache } private fun computeScrollItemContainerSize( @@ -531,9 +544,8 @@ object GXNodeUtils { gxItemTemplateItem, itemMeasureSize, itemTemplateData, - gxItemVisualTemplateNode, - itemCacheKey - ) + gxItemVisualTemplateNode + )?.layoutByBind } private fun computeSliderItemLayout( @@ -551,9 +563,8 @@ object GXNodeUtils { gxItemTemplateItem, gxMeasureSize, gxTemplateData, - gxItemVisualTemplateNode, - itemCacheKey - ) + gxItemVisualTemplateNode + )?.layoutByBind } private fun computeScrollItemLayout( @@ -572,8 +583,10 @@ object GXNodeUtils { gxMeasureSize, gxTemplateData, gxItemVisualTemplateNode, - itemCacheKey - ) + )?.apply { + gxTemplateContext.initNodeForScroll() + gxTemplateContext.putNodeForScroll(itemCacheKey, this) + }?.layoutByBind } private fun computeGridItemLayout( @@ -591,9 +604,8 @@ object GXNodeUtils { gxItemTemplateItem, gxMeasureSize, gxTemplateData, - gxItemVisualTemplateNode, - itemCacheKey - ) + gxItemVisualTemplateNode + )?.layoutByBind } fun computeScrollAndGridFooterItemViewPort( @@ -758,15 +770,12 @@ object GXNodeUtils { gxTemplateItem: GXTemplateEngine.GXTemplateItem, gxMeasureSize: GXTemplateEngine.GXMeasureSize, gxTemplateData: GXTemplateEngine.GXTemplateData, - gxVisualTemplateNode: GXTemplateNode?, - itemCacheKey: String - ): Layout? { + gxVisualTemplateNode: GXTemplateNode? + ): GXNode? { val gxItemTemplateInfo = GXTemplateEngine.instance.data.getTemplateInfo(gxTemplateItem) - val gxItemTemplateContext = GXTemplateContext.createContext( - gxTemplateItem, gxMeasureSize, gxItemTemplateInfo, gxVisualTemplateNode - ) + val gxItemTemplateContext = GXTemplateContext.createContext(gxTemplateItem, gxMeasureSize, gxItemTemplateInfo, gxVisualTemplateNode) if (!GXGlobalCache.instance.isExistForPrepareView(gxMeasureSize, gxTemplateItem)) { GXTemplateEngine.instance.render.prepareView(gxItemTemplateContext) @@ -778,10 +787,7 @@ object GXNodeUtils { GXTemplateEngine.instance.render.bindViewDataOnlyNodeTree(gxItemTemplateContext) - gxTemplateContext.initNodeForScroll() - gxTemplateContext.putNodeForScroll(itemCacheKey, gxItemRootNode) - - return gxItemRootNode.layoutByBind + return gxItemRootNode } private fun computeScrollContainerSize( 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 06c89cd03..cddb187c1 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 @@ -75,7 +75,7 @@ data class GXTemplateNode( return dataCache } - fun getExtend(templateData: JSON?): JSONObject? { + fun getExtend(templateData: JSON? = null): JSONObject? { if (dataExtendCache == null) { dataExtendCache = dataBinding?.getExtend(templateData) } diff --git a/GaiaXAndroid/src/main/kotlin/com/alibaba/gaiax/render/view/container/GXContainerViewAdapter.kt b/GaiaXAndroid/src/main/kotlin/com/alibaba/gaiax/render/view/container/GXContainerViewAdapter.kt index ca3a586a2..8109bd70c 100644 --- a/GaiaXAndroid/src/main/kotlin/com/alibaba/gaiax/render/view/container/GXContainerViewAdapter.kt +++ b/GaiaXAndroid/src/main/kotlin/com/alibaba/gaiax/render/view/container/GXContainerViewAdapter.kt @@ -167,8 +167,7 @@ class GXContainerViewAdapter(val gxTemplateContext: GXTemplateContext, private v Log.e("bindGXViewHolder $holder ${holder.itemView} ") } - val templateItem = - holder.templateItem ?: throw IllegalArgumentException("templateItem is null") + val templateItem = holder.templateItem ?: throw IllegalArgumentException("templateItem is null") val isFooterItem = templateItem == footerTemplateItem @@ -178,9 +177,7 @@ class GXContainerViewAdapter(val gxTemplateContext: GXTemplateContext, private v val itemMeasureSize = getMeasureSize(itemViewPort) - val itemContainerSize = getItemContainerSize( - isFooterItem, templateItem, visualNestTemplateNode, itemViewPort - ) + val itemContainerSize = getItemContainerSize(isFooterItem, templateItem, visualNestTemplateNode, itemViewPort) val itemContainerLayoutParams = getItemContainerSize(itemContainerSize) @@ -370,9 +367,7 @@ class GXContainerViewAdapter(val gxTemplateContext: GXTemplateContext, private v ) private fun getItemViewPort(isFooterItem: Boolean) = - if (isFooterItem) GXNodeUtils.computeScrollAndGridFooterItemViewPort( - gxTemplateContext, gxNode - ) + if (isFooterItem) GXNodeUtils.computeScrollAndGridFooterItemViewPort(gxTemplateContext, gxNode) else GXNodeUtils.computeScrollAndGridItemViewPort(gxTemplateContext, gxNode) override fun getItemViewType(position: Int): Int {