Skip to content

Commit ae0525c

Browse files
biezhihua慕晗
and
慕晗
authored
GitHub main (#499)
* Slider支持滚动到指定位置 * Slider支持滚动到指定位置 * test slider * revert instance * update bootstrap * fix target index calculate error * fix crash * fix slider * YKIndicator * fix scroll event * fix selected * fix selected * 移除holding-offset等属性 * fix slider item width * 修复Slider数据不更新的问题,POSITION_NONOE数据总是需要更新 * fix event * keep * 修复Grid数据为0时高度计算错误的问题 * fix grdis * fix fastpreview * open createTemplateContext * fix pageSize 0 * 缓存计算结果 * fix blur android.renderscript.RSIllegalArgumentException: Invalid object. * fix crash * 自定义View兜底 --------- Co-authored-by: 慕晗 <muhan.zq@antfin.com>
1 parent f7ff8c9 commit ae0525c

File tree

30 files changed

+932
-686
lines changed

30 files changed

+932
-686
lines changed

GaiaXAndroid/.idea/codeStyles/Project.xml

+1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

GaiaXAndroid/src/androidTest/java/com/alibaba/gaiax/GXComponentGridTest.kt

+1-1
Original file line numberDiff line numberDiff line change
@@ -749,7 +749,7 @@ class GXComponentGridTest : GXBaseTest() {
749749
rootView.executeRecyclerView()
750750

751751
Assert.assertEquals(1080F.dpToPx(), rootView.width())
752-
Assert.assertEquals(100F.dpToPx(), rootView.height())
752+
Assert.assertEquals(0F.dpToPx(), rootView.height())
753753
}
754754

755755
@Test

GaiaXAndroid/src/androidTest/java/com/alibaba/gaiax/GXComponentScrollTest.kt

+2-8
Original file line numberDiff line numberDiff line change
@@ -987,10 +987,7 @@ class GXComponentScrollTest : GXBaseTest() {
987987
val rootView = GXTemplateEngine.instance.createView(templateItem, size)
988988
GXTemplateEngine.instance.bindData(rootView, templateData)
989989

990-
Assert.assertEquals(
991-
0,
992-
((rootView as RecyclerView).layoutManager as LinearLayoutManager).getFieldInt("mPendingScrollPosition")
993-
)
990+
Assert.assertEquals(0, ((rootView as RecyclerView).layoutManager as LinearLayoutManager).getFieldInt("mPendingScrollPosition"))
994991

995992
GXRegisterCenter.instance.extensionScroll = null
996993
}
@@ -1053,10 +1050,7 @@ class GXComponentScrollTest : GXBaseTest() {
10531050
val rootView = GXTemplateEngine.instance.createView(templateItem, size)
10541051
GXTemplateEngine.instance.bindData(rootView, templateData)
10551052

1056-
Assert.assertEquals(
1057-
3,
1058-
((rootView as RecyclerView).layoutManager as LinearLayoutManager).getFieldInt("mPendingScrollPosition")
1059-
)
1053+
Assert.assertEquals(3, ((rootView as RecyclerView).layoutManager as LinearLayoutManager).getFieldInt("mPendingScrollPosition"))
10601054

10611055
GXTemplateEngine.instance.bindData(rootView,
10621056
GXTemplateEngine.GXTemplateData(JSONObject().apply {

GaiaXAndroid/src/main/kotlin/com/alibaba/gaiax/GXTemplateEngine.kt

+7-5
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,6 @@ import app.visly.stretch.Size
2626
import com.alibaba.fastjson.JSONObject
2727
import com.alibaba.gaiax.context.GXTemplateContext
2828
import com.alibaba.gaiax.context.clearLayout
29-
import com.alibaba.gaiax.context.isExistNodeForScroll
30-
import com.alibaba.gaiax.context.obtainNodeForScroll
3129
import com.alibaba.gaiax.data.GXDataImpl
3230
import com.alibaba.gaiax.data.assets.GXAssetsBinaryWithoutSuffixTemplate
3331
import com.alibaba.gaiax.data.assets.GXAssetsTemplate
@@ -484,6 +482,10 @@ class GXTemplateEngine {
484482
fun key(size: GXMeasureSize): String {
485483
return "${bizId}-${templateId}-${size.width}"
486484
}
485+
486+
fun key(): String {
487+
return "${bizId}-${templateId}"
488+
}
487489
}
488490

489491
internal lateinit var context: Context
@@ -497,7 +499,7 @@ class GXTemplateEngine {
497499
GXRenderImpl()
498500
}
499501

500-
internal fun createTemplateContext(
502+
fun createTemplateContext(
501503
gxTemplateItem: GXTemplateItem,
502504
gxMeasureSize: GXMeasureSize,
503505
gxVisualTemplateNode: GXTemplateNode?
@@ -689,8 +691,8 @@ class GXTemplateEngine {
689691
val gxHostTemplateContext = gxExtendParams?.gxHostTemplateContext
690692
if (gxHostTemplateContext != null) {
691693
val itemCacheKey = "${gxExtendParams.gxItemPosition}-${gxExtendParams.gxItemData.hashCode()}"
692-
if (gxHostTemplateContext.isExistNodeForScroll(itemCacheKey)) {
693-
gxTemplateContext.rootNode = gxHostTemplateContext.obtainNodeForScroll(itemCacheKey)
694+
if (gxHostTemplateContext.scrollNodeCache?.containsKey(itemCacheKey) == true) {
695+
gxTemplateContext.rootNode = gxHostTemplateContext.scrollNodeCache?.remove(itemCacheKey)
694696
gxTemplateContext.isReuseRootNode = true
695697
return gxTemplateContext
696698
}

GaiaXAndroid/src/main/kotlin/com/alibaba/gaiax/context/GXTemplateContext.kt

+13-6
Original file line numberDiff line numberDiff line change
@@ -112,13 +112,21 @@ class GXTemplateContext private constructor(
112112
* key is itemCacheKey ${itemPosition}-${itemData.hashCode()}.
113113
* value is item layout.
114114
*/
115-
var scrollItemLayoutCache: MutableMap<Any, Layout>? = null
115+
val scrollItemLayoutCache: MutableMap<String, Layout>? by lazy {
116+
mutableMapOf()
117+
}
116118

117-
var sliderItemLayoutCache: Layout? = null
119+
val sliderItemLayoutCache: MutableMap<String, Layout>? by lazy {
120+
mutableMapOf()
121+
}
118122

119-
var gridItemLayoutCache: Layout? = null
123+
val gridItemLayoutCache: MutableMap<String, Layout>? by lazy {
124+
mutableMapOf()
125+
}
120126

121-
var scrollNodeCache: MutableMap<Any, GXNode>? = null
127+
val scrollNodeCache: MutableMap<String, GXNode>? by lazy {
128+
mutableMapOf()
129+
}
122130

123131
/**
124132
* Is dirty
@@ -149,8 +157,7 @@ class GXTemplateContext private constructor(
149157

150158
fun release() {
151159
flags = 0
152-
sliderItemLayoutCache = null
153-
gridItemLayoutCache = null
160+
sliderItemLayoutCache?.clear()
154161
scrollItemLayoutCache?.clear()
155162
containers?.clear()
156163
isDirty = false

GaiaXAndroid/src/main/kotlin/com/alibaba/gaiax/context/GXTemplateContextExt.kt

+4-50
Original file line numberDiff line numberDiff line change
@@ -2,65 +2,19 @@ package com.alibaba.gaiax.context
22

33
import app.visly.stretch.Layout
44
import com.alibaba.gaiax.render.node.GXNode
5-
import com.alibaba.gaiax.utils.Log
6-
import com.alibaba.gaiax.utils.runE
7-
8-
fun GXTemplateContext.initLayoutForScroll() {
9-
if (scrollItemLayoutCache == null) {
10-
scrollItemLayoutCache = mutableMapOf()
11-
}
12-
}
135

146
fun GXTemplateContext.clearLayout() {
15-
sliderItemLayoutCache = null
16-
gridItemLayoutCache = null
7+
sliderItemLayoutCache?.clear()
8+
gridItemLayoutCache?.clear()
179
scrollItemLayoutCache?.clear()
1810
}
1911

20-
fun GXTemplateContext.isExistForScroll(key: Any): Boolean {
21-
return scrollItemLayoutCache?.containsKey(key) == true
22-
}
23-
24-
fun GXTemplateContext.putLayoutForScroll(key: Any, value: Layout) {
25-
Log.runE("GXTemplateContextExt") { "putLayoutForScroll key=$key value=$value" }
26-
scrollItemLayoutCache?.put(key, value)
27-
}
28-
29-
fun GXTemplateContext.getLayoutForScroll(key: Any): Layout? {
30-
return scrollItemLayoutCache?.get(key)
31-
}
32-
3312
fun GXTemplateContext.getMaxHeightLayoutForScroll(): Layout? {
34-
return scrollItemLayoutCache?.maxWithOrNull { a, b ->
35-
a.value.height.compareTo(b.value.height)
36-
}?.value
13+
return scrollItemLayoutCache?.maxWithOrNull { a, b -> a.value.height.compareTo(b.value.height) }?.value
3714
}
3815

39-
4016
fun GXTemplateContext.getMinHeightLayoutForScroll(): Layout? {
41-
return scrollItemLayoutCache?.minWithOrNull { a, b ->
42-
a.value.height.compareTo(b.value.height)
43-
}?.value
44-
}
45-
46-
47-
fun GXTemplateContext.initNodeForScroll() {
48-
if (scrollNodeCache == null) {
49-
scrollNodeCache = mutableMapOf()
50-
}
17+
return scrollItemLayoutCache?.minWithOrNull { a, b -> a.value.height.compareTo(b.value.height) }?.value
5118
}
5219

53-
fun GXTemplateContext.isExistNodeForScroll(key: Any): Boolean {
54-
return scrollNodeCache?.containsKey(key) ?: false
55-
}
56-
57-
fun GXTemplateContext.obtainNodeForScroll(key: Any): GXNode? {
58-
val value = scrollNodeCache?.remove(key)
59-
Log.runE("GXTemplateContextExt") { "obtainNodeForScroll key=$key value=$value" }
60-
return value
61-
}
6220

63-
fun GXTemplateContext.putNodeForScroll(key: Any, value: GXNode) {
64-
scrollNodeCache?.put(key, value)
65-
Log.runE("GXTemplateContextExt") { "putNodeForScroll key=$key value=$value" }
66-
}

0 commit comments

Comments
 (0)