Skip to content

Commit 2223e8e

Browse files
authored
Popup: Fixes TextPopupElement composable shifting in size when coming back into visibility (#461)
1 parent 9c5080f commit 2223e8e

File tree

2 files changed

+24
-11
lines changed

2 files changed

+24
-11
lines changed

toolkit/popup/src/main/java/com/arcgismaps/toolkit/popup/Popup.kt

+18-10
Original file line numberDiff line numberDiff line change
@@ -150,35 +150,43 @@ private fun PopupBody(popupState: PopupState, onFileClicked: (ViewableFile?) ->
150150
) {
151151
states.forEach { entry ->
152152
val element = entry.popupElement
153-
item {
154-
when (element) {
155-
is TextPopupElement -> {
153+
when (element) {
154+
is TextPopupElement -> {
155+
// a contentType is needed to reuse the TextPopupElement composable inside a LazyColumn
156+
item(contentType = TextPopupElement::class.java) {
156157
TextPopupElement(
157158
entry.state as TextElementState
158159
)
159160
}
161+
}
160162

161-
is AttachmentsPopupElement -> {
163+
is AttachmentsPopupElement -> {
164+
item(contentType = AttachmentsPopupElement::class.java) {
162165
AttachmentsPopupElement(
163166
state = entry.state as AttachmentsElementState,
164-
onFileClicked)
167+
onFileClicked
168+
)
165169
}
170+
}
166171

167-
is FieldsPopupElement -> {
172+
is FieldsPopupElement -> {
173+
item(contentType = FieldsPopupElement::class.java) {
168174
FieldsPopupElement(
169175
entry.state as FieldsElementState,
170176
)
171177
}
178+
}
172179

173-
is MediaPopupElement -> {
180+
is MediaPopupElement -> {
181+
item(contentType = MediaPopupElement::class.java) {
174182
MediaPopupElement(
175183
entry.state as MediaElementState
176184
)
177185
}
186+
}
178187

179-
else -> {
180-
// other popup elements are not created
181-
}
188+
else -> {
189+
// other popup elements are not created
182190
}
183191
}
184192
}

toolkit/popup/src/main/java/com/arcgismaps/toolkit/popup/internal/element/textelement/TextPopupElement.kt

+6-1
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,12 @@ private fun HTML(content: String) {
8181
val completeHtml = "$header$headStyle<html>${content.trim()}</html>"
8282
loadDataWithBaseURL(null, completeHtml, "text/html", "UTF-8", null)
8383
}
84-
})
84+
},
85+
// By default, AndroidViews aren't reused in a lazy list. This means that the `HTML` composable instance will
86+
// get discarded and recreated every time. By defining an `onReset` lambda, we can ensure tha the AndroidView will
87+
// be reused when the composition hierarchy changes.
88+
onReset = {}
89+
)
8590
}
8691

8792
/**

0 commit comments

Comments
 (0)