Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
46 changes: 39 additions & 7 deletions resources/android/NativeLayoutDrawerHost.kt
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
package com.nativephp.plugins.native_ui.ui

import androidx.compose.foundation.layout.Box
import androidx.compose.foundation.layout.BoxWithConstraints
import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.fillMaxHeight
import androidx.compose.foundation.layout.fillMaxSize
import androidx.compose.foundation.layout.fillMaxWidth
import androidx.compose.foundation.layout.heightIn
import androidx.compose.foundation.layout.padding
import androidx.compose.foundation.layout.statusBarsPadding
import androidx.compose.foundation.layout.width
Expand All @@ -26,6 +29,7 @@ import androidx.compose.ui.Modifier
import androidx.compose.ui.unit.dp
import com.nativephp.mobile.ui.nativerender.NativeUINode
import com.nativephp.mobile.ui.nativerender.RenderNode
import com.nativephp.mobile.ui.nativerender.SizeMode
import kotlinx.coroutines.launch

/**
Expand Down Expand Up @@ -103,13 +107,41 @@ fun NativeLayoutDrawerHost(

@Composable
private fun DrawerChildren(drawerNode: NativeUINode) {
Column(
modifier = Modifier
.fillMaxHeight()
.verticalScroll(rememberScrollState())
) {
drawerNode.children.forEach { child ->
RenderNode(child)
// A `fill` / `h-full` DIRECT child is at least as tall as the drawer, so
// `justify-between` can pin a footer to the bottom. The scroll measures
// its children with an unbounded height, so `fillMaxHeight()` alone has
// nothing to fill and the child hugs its content. The drawer's height is
// handed over as a MINIMUM, the same rule as ScrollViewRenderer: content
// taller than the drawer still grows and scrolls.
BoxWithConstraints(Modifier.fillMaxHeight()) {
val viewport = maxHeight.takeIf { it.value.isFinite() && it.value > 0f }
Column(
modifier = Modifier
.fillMaxHeight()
.verticalScroll(rememberScrollState())
) {
drawerNode.children.forEach { child ->
val layout = child.layout
if (viewport != null && layout?.heightMode == SizeMode.FILL) {
// Width is reproduced because the modifier replaces
// NodeView's own sizing, as in ScrollViewRenderer.
var childMod: Modifier = Modifier.heightIn(min = viewport)
when (layout.widthMode) {
SizeMode.FILL -> childMod = childMod.fillMaxWidth()
SizeMode.FIXED -> if (layout.width > 0f) {
childMod = childMod.width(layout.width.dp)
}
SizeMode.PERCENT -> if (layout.width > 0f) {
childMod = childMod.fillMaxWidth(
(layout.width / 100f).coerceIn(0f, 1f)
)
}
}
RenderNode(child, childMod)
} else {
RenderNode(child)
}
}
}
}
}
32 changes: 22 additions & 10 deletions resources/ios/NativeUIDrawerHost.swift
Original file line number Diff line number Diff line change
Expand Up @@ -255,18 +255,30 @@ struct NativeDrawerHost<Content: View>: View {

@ViewBuilder
private func drawerView(_ drawerNode: NativeUINode, width: CGFloat) -> some View {
ScrollView {
VStack(alignment: .leading, spacing: 0) {
ForEach(drawerNode.children) { child in
NodeView(node: child).equatable()
// Nothing inside the ScrollView knows how tall the panel is, so an
// `h-full` child (a `justify-between` column pinning a footer) would
// hug its content. The panel's height, less the top inset, goes to
// those direct children as a minimum, as in the scroll-view renderer:
// taller content still grows and scrolls.
GeometryReader { geometry in
ScrollView {
VStack(alignment: .leading, spacing: 0) {
ForEach(drawerNode.children) { child in
NodeView(node: child).equatable()
.modifier(MinViewportHeightModifier(
minHeight: child.layout?.heightMode == SizeMode.fill
? geometry.size.height - windowSafeAreaTop
: nil
))
}
}
// The panel ignores the safe area so its background reaches the top
// of the screen; without this inset the CONTENT does too, and the
// first row slides under the status bar. An app that pins
// UIUserInterfaceStyle sees this at every launch, not just on a
// notched device in landscape.
.padding(.top, windowSafeAreaTop)
}
// The panel ignores the safe area so its background reaches the top
// of the screen; without this inset the CONTENT does too, and the
// first row slides under the status bar. An app that pins
// UIUserInterfaceStyle sees this at every launch, not just on a
// notched device in landscape.
.padding(.top, windowSafeAreaTop)
}
.frame(width: width)
.frame(maxHeight: .infinity)
Expand Down
2 changes: 1 addition & 1 deletion resources/ios/NativeUIScrollViewRenderer.swift
Original file line number Diff line number Diff line change
Expand Up @@ -469,7 +469,7 @@ private struct BottomProbe: Equatable {

/// Applies a minimum height only when there is one, so children that didn't
/// ask for viewport height keep the exact modifier chain they always had.
private struct MinViewportHeightModifier: ViewModifier {
struct MinViewportHeightModifier: ViewModifier {
let minHeight: CGFloat?

@ViewBuilder
Expand Down
12 changes: 10 additions & 2 deletions tests/android/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,9 @@

This standalone Robolectric/Compose module compiles the production filled and
outlined editors, their shared dispatcher, the production Button renderer and
the production gesture area, list, virtual list, pager and bottom sheet renderers
and the background layer host.
the production gesture area, list, virtual list, pager and bottom sheet renderers,
the background layer host and the layout drawer host.

It records the bridge event boundary; it does not load PHP/JNI, render icons or
menus, or prove device IME behaviour. The Mobile policy and node models are read
from an explicit checkout, not substituted by test implementations.
Expand Down Expand Up @@ -55,10 +56,17 @@ composition: when its detents change in the same render, and when a finger
grabs it while it slides away. `RenderNode` here draws each child as
`NodeView` does.

`DrawerFillHeightTest` opens a modal drawer from its menu button and checks
an `h-full` child reaches the bottom of the drawer, a sibling without it
keeps its own height, and a child taller than the drawer still scrolls.
`NodeView` here wraps its box in the modifier the drawer passes, so these
check the sizes the drawer hands out, not `justify-between` itself.

`BackgroundLayerStyleTest` puts a column with a background colour, a gradient
and a dark-mode background at the top of a background layer and checks the
pixels drawn, then checks a top element's padding and safe-area insets leave
its background showing around its content. The renderers here draw only the
modifier they are given; core's `nodeStyle` and `nodeLayout` are compiled from
the Mobile checkout.

These are JVM checks; SwiftUI and native device behaviour need separate testing.
3 changes: 2 additions & 1 deletion tests/android/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ plugins {
}
val stageSources = tasks.register<Sync>("stageSources") {
from(layout.projectDirectory.dir("../../resources/android")) {
include("FilledTextInputRenderer.kt", "OutlinedTextInputRenderer.kt", "BareTextInputRenderer.kt", "TextInputShared.kt", "NativeUIFontResolver.kt", "NativeUITheme.kt", "ButtonRenderer.kt", "GestureAreaRenderer.kt", "ListRenderer.kt", "VirtualListRenderer.kt", "PagerRenderer.kt", "BottomSheetRenderer.kt", "NativeUIBackgroundLayerHost.kt")
include("FilledTextInputRenderer.kt", "OutlinedTextInputRenderer.kt", "BareTextInputRenderer.kt", "TextInputShared.kt", "NativeUIFontResolver.kt", "NativeUITheme.kt", "ButtonRenderer.kt", "GestureAreaRenderer.kt", "ListRenderer.kt", "VirtualListRenderer.kt", "PagerRenderer.kt", "BottomSheetRenderer.kt", "NativeLayoutDrawerHost.kt", "NativeUIBackgroundLayerHost.kt")
}
from(providers.gradleProperty("mobileRoot").map { "$it/resources/androidstudio/app/src/main/java/com/nativephp/mobile/ui/nativerender" }) {
include("KeyboardFocusPolicy.kt", "NativeUINode.kt", "SharedValueStore.kt", "NativeCompositionLocals.kt", "NativeRendererRegistry.kt", "NodeModifiers.kt", "NodeBorder.kt", "NodeAccessibility.kt", "ComposeFlexLayout.kt")
Expand All @@ -30,6 +30,7 @@ dependencies {
implementation(platform("androidx.compose:compose-bom:2025.12.00"))
implementation("androidx.compose.foundation:foundation")
implementation("androidx.compose.material3:material3")
implementation("androidx.compose.material:material-icons-core")
implementation("androidx.compose.ui:ui")
implementation("io.coil-kt.coil3:coil-compose:3.1.0")
testImplementation("junit:junit:4.13.2")
Expand Down
4 changes: 2 additions & 2 deletions tests/android/src/main/kotlin/NodeView.kt
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,11 @@ import androidx.compose.ui.unit.dp
/**
* Draws a container's children for the gesture area tests: a 300x120 box
* tagged `node-<id>`, made clickable the way core makes a `pressable` when
* the node has a press handler.
* the node has a press handler. A parent's modifier wraps the box.
*/
@Composable
fun NodeView(node: NativeUINode, overrideModifier: Modifier? = null) {
var modifier = Modifier.size(300.dp, 120.dp).testTag("node-${node.id}")
var modifier = (overrideModifier ?: Modifier).size(300.dp, 120.dp).testTag("node-${node.id}")
if (node.onPress != 0) {
modifier = modifier.clickable { NativeUIBridge.sendPressEvent(node.onPress, node.id) }
}
Expand Down
67 changes: 67 additions & 0 deletions tests/android/src/test/kotlin/DrawerFillHeightTest.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
package com.nativephp.plugins.native_ui.ui

import androidx.compose.foundation.layout.Box
import androidx.compose.foundation.layout.height
import androidx.compose.ui.Modifier
import androidx.compose.ui.semantics.SemanticsProperties
import androidx.compose.ui.test.*
import androidx.compose.ui.test.junit4.createComposeRule
import androidx.compose.ui.unit.Dp
import androidx.compose.ui.unit.dp
import androidx.compose.ui.unit.height
import com.nativephp.mobile.ui.nativerender.*
import org.junit.Assert.assertEquals
import org.junit.Rule
import org.junit.Test
import org.junit.runner.RunWith
import org.robolectric.RobolectricTestRunner
import org.robolectric.annotation.Config

@RunWith(RobolectricTestRunner::class)
@Config(sdk = [35])
class DrawerFillHeightTest {
@get:Rule val compose = createComposeRule()

@Test fun anHFullRootReachesTheBottomOfTheDrawer() {
open(fill(2))
val root = compose.onNodeWithTag("node-2").getUnclippedBoundsInRoot()
assertNear(viewport().top, root.top)
assertNear(viewport().bottom, root.bottom)
}

@Test fun aSiblingThatDoesNotFillKeepsItsOwnHeight() {
open(fill(2), plain(3))
assertNear(viewport().height, compose.onNodeWithTag("node-2").getUnclippedBoundsInRoot().height)
compose.onNodeWithTag("node-3").assertHeightIsEqualTo(120.dp)
}

@Test fun aRootTallerThanTheDrawerStillGrowsAndScrolls() {
open(fill(2), height = 100.dp)
compose.onNodeWithTag("node-2").assertHeightIsEqualTo(120.dp)
compose.onNode(drawerScroll).performTouchInput { swipeUp() }
assertNear(viewport().bottom, compose.onNodeWithTag("node-2").getUnclippedBoundsInRoot().bottom)
}

private val drawerScroll = SemanticsMatcher.keyIsDefined(SemanticsProperties.VerticalScrollAxisRange)

/** The drawer's scrolling column: the height an `h-full` child should reach. */
private fun viewport() = compose.onNode(drawerScroll).getUnclippedBoundsInRoot()

private fun open(vararg children: NativeUINode, height: Dp? = null) {
compose.setContent {
Box(if (height != null) Modifier.height(height) else Modifier) {
NativeLayoutDrawerHost(NativeUINode(1, "native_drawer", null, null, GenericProps(), 0, 0, children.toList())) {}
}
}
compose.onNodeWithContentDescription("Open menu").performClick()
compose.waitForIdle()
}

private fun assertNear(expected: Dp, actual: Dp) = assertEquals(expected.value, actual.value, 0.5f)

/** `w-full h-full`, like a drawer root column with `justify-between`. */
private fun fill(id: Int) = NativeUINode(
id, "column", NodeLayout.EMPTY.copy(widthMode = SizeMode.FILL, heightMode = SizeMode.FILL), null, GenericProps(), 0, 0, emptyList())

private fun plain(id: Int) = NativeUINode(id, "column", null, null, GenericProps(), 0, 0, emptyList())
}
Loading