Skip to content

Commit 314f2f2

Browse files
committed
Fix a bug that the FAB gets scrolled up with the content in TopAppBarScaffold, and replace *ScrollPlatformModifiers with imitateAndroidxLayout*ScrollPlatformModifiers BTW
1 parent ad04477 commit 314f2f2

File tree

7 files changed

+27
-18
lines changed

7 files changed

+27
-18
lines changed

compose-multiplatform-common/src/commonMain/kotlin/com/huanshankeji/compose/foundation/ext/MatchPositionRelativeParentJsOnly.kt

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,11 @@ package com.huanshankeji.compose.foundation.ext
22

33
import com.huanshankeji.compose.ui.Modifier
44

5+
/*
6+
const val MATCH_POSITION_RELATIVE_PARENT_DEPRECATED_MESSAGE =
7+
"This function's functionality is replaced by `imitateAndroidxLayout`."
8+
*/
9+
10+
11+
//@Deprecated(MATCH_POSITION_RELATIVE_PARENT_DEPRECATED_MESSAGE)
512
expect fun Modifier.matchPositionRelativeParentJsDom(): Modifier

compose-multiplatform-common/src/jsMain/kotlin/com/huanshankeji/compose/foundation/Scroll.js.kt

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import com.huanshankeji.compose.foundation.layout.ext.KobwebBox
1010
import com.huanshankeji.compose.ui.Alignment
1111
import com.huanshankeji.compose.ui.Modifier
1212
import com.huanshankeji.compose.ui.PlatformModifier
13+
import com.huanshankeji.kobweb.compose.ui.modifiers.imitateAndroidxLayout
1314
import com.varabyte.kobweb.compose.ui.styleModifier
1415

1516
fun PlatformModifier.verticalScroll() =
@@ -18,8 +19,8 @@ fun PlatformModifier.verticalScroll() =
1819
fun PlatformModifier.horizontalScroll() =
1920
styleModifier { horizontalScroll() }
2021

21-
val verticalScrollPlatformModifier = PlatformModifier.verticalScroll()
22-
val horizontalScrollPlatformModifier = PlatformModifier.horizontalScroll()
22+
val imitateAndroidxLayoutVerticalScrollPlatformModifier = PlatformModifier.imitateAndroidxLayout().verticalScroll()
23+
val imitateAndroidxLayoutHorizontalScrollPlatformModifier = PlatformModifier.imitateAndroidxLayout().horizontalScroll()
2324

2425

2526
@Composable

compose-multiplatform-common/src/jsMain/kotlin/com/huanshankeji/compose/foundation/lazy/LazyDsl.js.kt

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
package com.huanshankeji.compose.foundation.lazy
22

33
import androidx.compose.runtime.Composable
4-
import com.huanshankeji.compose.foundation.horizontalScrollPlatformModifier
4+
import com.huanshankeji.compose.foundation.imitateAndroidxLayoutHorizontalScrollPlatformModifier
5+
import com.huanshankeji.compose.foundation.imitateAndroidxLayoutVerticalScrollPlatformModifier
56
import com.huanshankeji.compose.foundation.layout.*
6-
import com.huanshankeji.compose.foundation.verticalScrollPlatformModifier
77
import com.huanshankeji.compose.runtime.DeferredComposableRunner
88
import com.huanshankeji.compose.ui.Alignment
99
import com.huanshankeji.compose.ui.Modifier
@@ -63,7 +63,7 @@ actual fun LazyRow(
6363
content: LazyListScope.() -> Unit
6464
) =
6565
Row(
66-
commonLazyModifier(horizontalScrollPlatformModifier, contentPadding, modifier),
66+
commonLazyModifier(imitateAndroidxLayoutHorizontalScrollPlatformModifier, contentPadding, modifier),
6767
horizontalArrangement,
6868
verticalAlignment
6969
) {
@@ -80,7 +80,7 @@ actual fun LazyColumn(
8080
content: LazyListScope.() -> Unit
8181
) =
8282
Column(
83-
commonLazyModifier(verticalScrollPlatformModifier, contentPadding, modifier),
83+
commonLazyModifier(imitateAndroidxLayoutVerticalScrollPlatformModifier, contentPadding, modifier),
8484
verticalArrangement,
8585
horizontalAlignment
8686
) {

compose-multiplatform-material2/src/jsMain/kotlin/com/huanshankeji/compose/material2/ext/TopAppBarScaffold.js.kt

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -5,15 +5,13 @@ import com.huanshankeji.compose.contentDescription
55
import com.huanshankeji.compose.foundation.ext.matchPositionRelativeParent
66
import com.huanshankeji.compose.foundation.layout.Column
77
import com.huanshankeji.compose.foundation.layout.PaddingValues
8+
import com.huanshankeji.compose.foundation.layout.ext.fillMaxWidthStretch
89
import com.huanshankeji.compose.foundation.layout.fillMaxSize
9-
import com.huanshankeji.compose.foundation.layout.fillMaxWidth
1010
import com.huanshankeji.compose.material.icons.Icon
1111
import com.huanshankeji.compose.material2.icons.mdcIconWithStyle
1212
import com.huanshankeji.compose.ui.Modifier
1313
import com.huanshankeji.compose.ui.toAttrs
14-
import com.varabyte.kobweb.compose.css.Overflow
1514
import com.varabyte.kobweb.compose.css.TextAlign
16-
import com.varabyte.kobweb.compose.css.overflow
1715
import com.varabyte.kobweb.compose.css.textAlign
1816
import dev.petuska.kmdc.top.app.bar.*
1917
import org.jetbrains.compose.web.css.*
@@ -121,26 +119,27 @@ actual fun TopAppBarScaffold(
121119
topAppBarModifier,
122120
navigationIcon,
123121
actions,
124-
Modifier.weight(1f).fillMaxWidth()
122+
Modifier.weight(1f).fillMaxWidthStretch()
125123
) {
124+
// The content gets hidden behind the top app bar if this div is not added.
126125
Div({
127126
style {
128127
height(100.percent)
129-
position(Position.Relative)
128+
position(Position.Relative) // same issue as above if not added
130129
}
131130
}) {
132131
Div({
133132
style {
134133
matchPositionRelativeParent()
135-
overflow(Overflow.Auto)
134+
//overflow(Overflow.Auto) // This seems not needed. TODO remove if confirmed to be not needed
136135
}
137136
}) {
138137
// see `ScaffoldLayoutWithMeasureFix`
139138
val innerPadding = PaddingValues()
140139
content(innerPadding)
141-
142-
floatingActionButton?.let { fabWithPosition(it) }
143140
}
141+
142+
floatingActionButton?.let { fabWithPosition(it) }
144143
}
145144
}
146145

compose-multiplatform-material2/src/jsMain/kotlin/com/huanshankeji/compose/material2/lazy/ext/LazyDsl.js.kt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
package com.huanshankeji.compose.material2.lazy.ext
22

33
import androidx.compose.runtime.Composable
4-
import com.huanshankeji.compose.foundation.verticalScrollPlatformModifier
4+
import com.huanshankeji.compose.foundation.imitateAndroidxLayoutVerticalScrollPlatformModifier
55
import com.huanshankeji.compose.runtime.DeferredComposableRunner
66
import com.huanshankeji.compose.ui.Modifier
77
import com.varabyte.kobweb.compose.ui.toAttrs
@@ -78,6 +78,6 @@ actual class HeaderScope(val headingElementScope: ElementScope<HTMLHeadingElemen
7878

7979
@Composable
8080
actual fun List(modifier: Modifier, content: ListScope.() -> Unit) =
81-
MDCList(attrs = verticalScrollPlatformModifier.then(modifier.platformModifier).toAttrs()) {
81+
MDCList(attrs = imitateAndroidxLayoutVerticalScrollPlatformModifier.then(modifier.platformModifier).toAttrs()) {
8282
ListScope(this).ComposableRun(content)
8383
}

compose-multiplatform-material3/src/jsMain/kotlin/com/huanshankeji/compose/material3/lazy/ext/List.js.kt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
package com.huanshankeji.compose.material3.lazy.ext
22

33
import androidx.compose.runtime.Composable
4-
import com.huanshankeji.compose.foundation.verticalScrollPlatformModifier
4+
import com.huanshankeji.compose.foundation.imitateAndroidxLayoutVerticalScrollPlatformModifier
55
import com.huanshankeji.compose.html.material3.MdList
66
import com.huanshankeji.compose.html.material3.MdListItemScope
77
import com.huanshankeji.compose.html.material3.MdListItemType
@@ -95,6 +95,6 @@ actual fun List(
9595
modifier: Modifier,
9696
content: ListScope.() -> Unit
9797
) =
98-
MdList(verticalScrollPlatformModifier.then(modifier.platformModifier).toAttrs()) {
98+
MdList(imitateAndroidxLayoutVerticalScrollPlatformModifier.then(modifier.platformModifier).toAttrs()) {
9999
ListScope(this).ComposableRun(content)
100100
}

demo/src/commonMain/kotlin/com/huanshankeji/compose/material/demo/Material2.kt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,8 @@ fun Material2(/*modifier: Modifier = Modifier*/) {
3939
MaterialIconActionButton({}, icon = Icons.Default.Done, contentDescription = "done")
4040
}, snackbarHost = {
4141
SnackbarHost(snackbarHostState)
42+
}, floatingActionButton = {
43+
Text("FAB") // The Material 2 FAB is not added so this is a placeholder.
4244
}) {
4345
VerticalScrollBox {
4446
Card(contentPaddingModifier) {

0 commit comments

Comments
 (0)