Skip to content

Commit 3fe5d76

Browse files
committed
fix(details): improve markdown rendering and height calculation stability
This commit fixes issues where UI sections might not correctly recalculate their expandable heights when content changes and improves markdown link resolution. - **fix(details)**: Updated `WhatsNew` and `About` sections to re-calculate `contentHeightPx` when the source content or collapsed height constraints change by adding appropriate keys to `remember`. - **fix(details)**: Optimized `About` section by removing redundant `remember` for `needsExpansion` and switching to `mutableFloatStateOf` in `WhatsNew` for better performance. - **fix(data)**: Enhanced markdown preprocessing to resolve relative or shorthand URLs within markdown link syntax.
1 parent 40a4e8a commit 3fe5d76

3 files changed

Lines changed: 9 additions & 8 deletions

File tree

feature/details/data/src/commonMain/kotlin/zed/rainxch/details/data/utils/preprocessMarkdown.kt

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -329,10 +329,11 @@ fun preprocessMarkdown(markdown: String, baseUrl: String): String {
329329
) { match ->
330330
val url = match.groupValues[2]
331331
val text = match.groupValues[3].trim()
332+
val resolvedUrl = resolveUrl(url)
332333
if (text.isEmpty()) {
333-
"[$url]($url)"
334+
"[$resolvedUrl]($resolvedUrl)"
334335
} else {
335-
"[$text]($url)"
336+
"[$text]($resolvedUrl)"
336337
}
337338
}
338339

feature/details/presentation/src/commonMain/kotlin/zed/rainxch/details/presentation/components/sections/About.kt

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -117,11 +117,8 @@ fun ExpandableMarkdownContent(
117117
val flavour = remember { GFMFlavourDescriptor() }
118118

119119
val collapsedHeightPx = with(density) { collapsedHeight.toPx() }
120-
var contentHeightPx by remember { mutableStateOf(0f) }
121-
val needsExpansion = remember(contentHeightPx) {
122-
contentHeightPx > collapsedHeightPx
123-
&& collapsedHeightPx > 0f
124-
}
120+
var contentHeightPx by remember(content, collapsedHeightPx) { mutableStateOf(0f) }
121+
val needsExpansion = contentHeightPx > collapsedHeightPx && collapsedHeightPx > 0f
125122

126123
Column(
127124
modifier = modifier.animateContentSize()

feature/details/presentation/src/commonMain/kotlin/zed/rainxch/details/presentation/components/sections/WhatsNew.kt

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ import androidx.compose.material3.MaterialTheme
1919
import androidx.compose.material3.Text
2020
import androidx.compose.material3.TextButton
2121
import androidx.compose.runtime.getValue
22+
import androidx.compose.runtime.mutableFloatStateOf
2223
import androidx.compose.runtime.mutableStateOf
2324
import androidx.compose.runtime.remember
2425
import androidx.compose.runtime.setValue
@@ -107,7 +108,9 @@ fun LazyListScope.whatsNew(
107108
val cardColor = MaterialTheme.colorScheme.surfaceContainerLow
108109

109110
val collapsedHeightPx = with(density) { collapsedHeight.toPx() }
110-
var contentHeightPx by remember { mutableStateOf(0f) }
111+
var contentHeightPx by remember(release.description, collapsedHeightPx) {
112+
mutableFloatStateOf(0f)
113+
}
111114
val needsExpansion = remember(contentHeightPx, collapsedHeightPx) {
112115
contentHeightPx > collapsedHeightPx && collapsedHeightPx > 0f
113116
}

0 commit comments

Comments
 (0)