Skip to content
Closed
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
4 changes: 2 additions & 2 deletions resources/android/ActivityIndicatorRenderer.kt
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package com.nativephp.plugins.native_ui.ui

import androidx.compose.foundation.isSystemInDarkTheme
import androidx.compose.foundation.layout.size
import androidx.compose.material3.CircularProgressIndicator
import androidx.compose.runtime.Composable
Expand All @@ -11,6 +10,7 @@ import androidx.compose.ui.semantics.contentDescription
import androidx.compose.ui.semantics.liveRegion
import androidx.compose.ui.semantics.semantics
import androidx.compose.ui.unit.dp
import com.nativephp.mobile.ui.NativeAppearanceState
import com.nativephp.mobile.ui.nativerender.NativeUINode
import com.nativephp.plugins.native_ui.NativeUITheme

Expand All @@ -24,7 +24,7 @@ object ActivityIndicatorRenderer {
val size = p.getString("size", "md")
val a11yLabel = p.getString("a11y_label")

val theme = if (isSystemInDarkTheme()) NativeUITheme.dark else NativeUITheme.light
val theme = if (NativeAppearanceState.isDark()) NativeUITheme.dark else NativeUITheme.light

// Optional override — primitives like spinners sometimes need to
// match their container. When unset, fall through to theme.primary.
Expand Down
4 changes: 2 additions & 2 deletions resources/android/BadgeRenderer.kt
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package com.nativephp.plugins.native_ui.ui

import androidx.compose.foundation.background
import androidx.compose.foundation.isSystemInDarkTheme
import androidx.compose.foundation.layout.Box
import androidx.compose.foundation.layout.defaultMinSize
import androidx.compose.foundation.layout.padding
Expand All @@ -17,6 +16,7 @@ import androidx.compose.ui.semantics.semantics
import androidx.compose.ui.text.font.FontWeight
import androidx.compose.ui.unit.dp
import androidx.compose.ui.unit.sp
import com.nativephp.mobile.ui.NativeAppearanceState
import com.nativephp.mobile.ui.nativerender.NativeUINode
import com.nativephp.plugins.native_ui.NativeUITheme

Expand All @@ -32,7 +32,7 @@ object BadgeRenderer {
val variant = p.getString("variant", "destructive")
val a11yLabel = p.getString("a11y_label")

val theme = if (isSystemInDarkTheme()) NativeUITheme.dark else NativeUITheme.light
val theme = if (NativeAppearanceState.isDark()) NativeUITheme.dark else NativeUITheme.light

val (bg, fg) = when (variant) {
"primary" -> theme.primary to theme.onPrimary
Expand Down
4 changes: 2 additions & 2 deletions resources/android/BareTextInputRenderer.kt
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package com.nativephp.plugins.native_ui.ui

import androidx.compose.foundation.isSystemInDarkTheme
import androidx.compose.foundation.layout.fillMaxWidth
import androidx.compose.foundation.text.BasicTextField
import androidx.compose.foundation.text.KeyboardActions
Expand All @@ -21,6 +20,7 @@ import androidx.compose.ui.platform.LocalContext
import androidx.compose.ui.text.TextRange
import androidx.compose.ui.text.input.TextFieldValue
import androidx.compose.ui.unit.sp
import com.nativephp.mobile.ui.NativeAppearanceState
import com.nativephp.mobile.ui.nativerender.NativeUINode
import com.nativephp.mobile.ui.nativerender.argbToComposeColor
import com.nativephp.plugins.native_ui.NativeUITheme
Expand All @@ -45,7 +45,7 @@ object BareTextInputRenderer {
@Composable
fun Render(node: NativeUINode, modifier: Modifier) {
val props = parseTextInputProps(node)
val isDark = isSystemInDarkTheme()
val isDark = NativeAppearanceState.isDark()
val theme = if (isDark) NativeUITheme.dark else NativeUITheme.light
val customFontFamily = (if (props.fontName.isNotEmpty()) NativeUIFontResolver.resolve(LocalContext.current, props.fontName) else null)
?: nuiThemeDefaultFontFamily(LocalContext.current)
Expand Down
4 changes: 2 additions & 2 deletions resources/android/BottomSheetRenderer.kt
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package com.nativephp.plugins.native_ui.ui

import androidx.compose.foundation.isSystemInDarkTheme
import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.fillMaxHeight
import androidx.compose.material3.BottomSheetDefaults
Expand All @@ -13,6 +12,7 @@ import androidx.compose.runtime.Composable
import androidx.compose.ui.Modifier
import androidx.compose.ui.semantics.contentDescription
import androidx.compose.ui.semantics.semantics
import com.nativephp.mobile.ui.NativeAppearanceState
import com.nativephp.mobile.ui.nativerender.NativeUIBridge
import com.nativephp.mobile.ui.nativerender.NativeUINode
import com.nativephp.mobile.ui.nativerender.RenderNode
Expand Down Expand Up @@ -51,7 +51,7 @@ object BottomSheetRenderer {

if (!visible) return

val theme = if (isSystemInDarkTheme()) NativeUITheme.dark else NativeUITheme.light
val theme = if (NativeAppearanceState.isDark()) NativeUITheme.dark else NativeUITheme.light

val skipPartial = !hasPartialDetent(detentsStr)
val sheetState = rememberModalBottomSheetState(
Expand Down
4 changes: 2 additions & 2 deletions resources/android/ButtonGroupRenderer.kt
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package com.nativephp.plugins.native_ui.ui

import androidx.compose.foundation.isSystemInDarkTheme
import androidx.compose.material3.SegmentedButton
import androidx.compose.material3.SegmentedButtonDefaults
import androidx.compose.material3.SingleChoiceSegmentedButtonRow
Expand All @@ -14,6 +13,7 @@ import androidx.compose.runtime.setValue
import androidx.compose.ui.Modifier
import androidx.compose.ui.semantics.contentDescription
import androidx.compose.ui.semantics.semantics
import com.nativephp.mobile.ui.NativeAppearanceState
import com.nativephp.mobile.ui.nativerender.NativeUIBridge
import com.nativephp.mobile.ui.nativerender.NativeUINode
import com.nativephp.plugins.native_ui.NativeUITheme
Expand All @@ -34,7 +34,7 @@ object ButtonGroupRenderer {

if (options.isEmpty()) return

val theme = if (isSystemInDarkTheme()) NativeUITheme.dark else NativeUITheme.light
val theme = if (NativeAppearanceState.isDark()) NativeUITheme.dark else NativeUITheme.light

var selectedIndex by remember(node.id) { mutableStateOf(serverValue) }
var lastSentValue by remember(node.id) { mutableStateOf(serverValue) }
Expand Down
4 changes: 2 additions & 2 deletions resources/android/ButtonRenderer.kt
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,10 @@ import androidx.compose.ui.text.font.FontFamily
import androidx.compose.ui.unit.Dp
import androidx.compose.ui.unit.TextUnit
import androidx.compose.ui.unit.dp
import com.nativephp.mobile.ui.NativeAppearanceState
import com.nativephp.mobile.ui.MaterialIcon
import com.nativephp.mobile.ui.nativerender.NativeUIBridge
import com.nativephp.mobile.ui.nativerender.NativeUINode
import androidx.compose.foundation.isSystemInDarkTheme
import com.nativephp.plugins.native_ui.NativeUITheme
import com.nativephp.plugins.native_ui.NativeUITokens

Expand Down Expand Up @@ -70,7 +70,7 @@ object ButtonRenderer {
// rather than a CompositionLocal because nothing in the render tree
// currently provides one — the store is backed by `mutableStateOf`, so
// Compose recomposes automatically when PHP pushes a theme update.
val theme = if (isSystemInDarkTheme()) NativeUITheme.dark else NativeUITheme.light
val theme = if (NativeAppearanceState.isDark()) NativeUITheme.dark else NativeUITheme.light
val metrics = sizeMetrics(size, theme)
// Leading — button labels are single-line, so this is usually a no-op.
val lineHeight = nuiLineHeightUnit(p.getFloat("line_height_px", 0f), p.getFloat("line_height", 0f), metrics.textSize.value)
Expand Down
4 changes: 2 additions & 2 deletions resources/android/CheckboxRenderer.kt
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package com.nativephp.plugins.native_ui.ui

import androidx.compose.foundation.isSystemInDarkTheme
import androidx.compose.foundation.layout.Arrangement
import androidx.compose.foundation.layout.Row
import androidx.compose.foundation.selection.toggleable
Expand All @@ -17,6 +16,7 @@ import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.semantics.Role
import androidx.compose.ui.unit.dp
import com.nativephp.mobile.ui.NativeAppearanceState
import com.nativephp.mobile.ui.nativerender.NativeUIBridge
import com.nativephp.mobile.ui.nativerender.NativeUINode
import com.nativephp.plugins.native_ui.NativeUITheme
Expand All @@ -38,7 +38,7 @@ object CheckboxRenderer {
val a11yLabel = p.getString("a11y_label")
val a11yHint = p.getString("a11y_hint")

val theme = if (isSystemInDarkTheme()) NativeUITheme.dark else NativeUITheme.light
val theme = if (NativeAppearanceState.isDark()) NativeUITheme.dark else NativeUITheme.light

var checked by remember(node.id) { mutableStateOf(serverValue) }
var lastSentValue by remember(node.id) { mutableStateOf(serverValue) }
Expand Down
4 changes: 2 additions & 2 deletions resources/android/ChipRenderer.kt
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package com.nativephp.plugins.native_ui.ui

import androidx.compose.foundation.isSystemInDarkTheme
import androidx.compose.material3.ExperimentalMaterial3Api
import androidx.compose.material3.FilterChip
import androidx.compose.material3.FilterChipDefaults
Expand All @@ -13,6 +12,7 @@ import androidx.compose.runtime.remember
import androidx.compose.runtime.setValue
import androidx.compose.ui.Modifier
import androidx.compose.ui.unit.dp
import com.nativephp.mobile.ui.NativeAppearanceState
import com.nativephp.mobile.ui.MaterialIcon
import com.nativephp.mobile.ui.nativerender.NativeUIBridge
import com.nativephp.mobile.ui.nativerender.NativeUINode
Expand All @@ -35,7 +35,7 @@ object ChipRenderer {
val a11yLabel = p.getString("a11y_label")
val a11yHint = p.getString("a11y_hint")

val theme = if (isSystemInDarkTheme()) NativeUITheme.dark else NativeUITheme.light
val theme = if (NativeAppearanceState.isDark()) NativeUITheme.dark else NativeUITheme.light

var isSelected by remember(node.id) { mutableStateOf(serverValue) }
var lastSentValue by remember(node.id) { mutableStateOf(serverValue) }
Expand Down
4 changes: 2 additions & 2 deletions resources/android/DatePickerRenderer.kt
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package com.nativephp.plugins.native_ui.ui

import androidx.compose.foundation.clickable
import androidx.compose.foundation.isSystemInDarkTheme
import androidx.compose.foundation.layout.Box
import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.fillMaxWidth
Expand All @@ -28,6 +27,7 @@ import androidx.compose.runtime.setValue
import androidx.compose.ui.Modifier
import androidx.compose.ui.text.TextStyle
import androidx.compose.ui.unit.dp
import com.nativephp.mobile.ui.NativeAppearanceState
import com.nativephp.mobile.ui.MaterialIcon
import com.nativephp.mobile.ui.nativerender.NativeUIBridge
import com.nativephp.mobile.ui.nativerender.NativeUINode
Expand Down Expand Up @@ -88,7 +88,7 @@ object DatePickerRenderer {
val a11yLabel = p.getString("a11y_label")
val a11yHint = p.getString("a11y_hint")

val theme = if (isSystemInDarkTheme()) NativeUITheme.dark else NativeUITheme.light
val theme = if (NativeAppearanceState.isDark()) NativeUITheme.dark else NativeUITheme.light
val zone = resolveZone(p.getString("timezone"))
val locale = resolveLocale(p.getString("locale"))
val is24 = resolve24Hour(hourFormat, locale)
Expand Down
4 changes: 2 additions & 2 deletions resources/android/FilledTextInputRenderer.kt
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ package com.nativephp.plugins.native_ui.ui
import androidx.compose.foundation.interaction.FocusInteraction
import androidx.compose.foundation.interaction.Interaction
import androidx.compose.foundation.interaction.MutableInteractionSource
import androidx.compose.foundation.isSystemInDarkTheme
import androidx.compose.foundation.layout.fillMaxWidth
import androidx.compose.foundation.layout.size
import androidx.compose.foundation.text.KeyboardActions
Expand All @@ -25,6 +24,7 @@ import androidx.compose.ui.text.TextStyle
import androidx.compose.ui.text.font.FontFamily
import androidx.compose.ui.text.input.TextFieldValue
import androidx.compose.ui.unit.dp
import com.nativephp.mobile.ui.NativeAppearanceState
import com.nativephp.mobile.ui.nativerender.NativeUINode
import com.nativephp.plugins.native_ui.NativeUITheme

Expand All @@ -42,7 +42,7 @@ object FilledTextInputRenderer {
@Composable
fun Render(node: NativeUINode, modifier: Modifier) {
val props = parseTextInputProps(node)
val theme = if (isSystemInDarkTheme()) NativeUITheme.dark else NativeUITheme.light
val theme = if (NativeAppearanceState.isDark()) NativeUITheme.dark else NativeUITheme.light
val scope = rememberCoroutineScope()

// Local state owns text + caret (TextFieldValue). Initial caret sits at
Expand Down
4 changes: 2 additions & 2 deletions resources/android/IconRenderer.kt
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
package com.nativephp.plugins.native_ui.ui

import androidx.compose.foundation.clickable
import androidx.compose.foundation.isSystemInDarkTheme
import androidx.compose.material3.minimumInteractiveComponentSize
import androidx.compose.runtime.Composable
import androidx.compose.ui.Modifier
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.semantics.Role
import androidx.compose.ui.unit.dp
import com.nativephp.mobile.ui.NativeAppearanceState
import com.nativephp.mobile.ui.nativerender.NativeUIBridge
import com.nativephp.mobile.ui.nativerender.NativeUINode

Expand All @@ -19,7 +19,7 @@ object IconRenderer {
val a11yLabel = p.getString("a11y_label")
val lightArgb = p.getColor("color", 0xFF000000.toInt())
val darkArgb = p.getColor("dark_color", 0)
val isDark = isSystemInDarkTheme()
val isDark = NativeAppearanceState.isDark()
val effectiveArgb = if (isDark && darkArgb != 0) darkArgb else lightArgb

com.nativephp.mobile.ui.MaterialIcon(
Expand Down
4 changes: 2 additions & 2 deletions resources/android/ModalRenderer.kt
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ package com.nativephp.plugins.native_ui.ui
import androidx.compose.foundation.background
import androidx.compose.foundation.clickable
import androidx.compose.foundation.interaction.MutableInteractionSource
import androidx.compose.foundation.isSystemInDarkTheme
import androidx.compose.foundation.layout.Arrangement
import androidx.compose.foundation.layout.Box
import androidx.compose.foundation.layout.Column
Expand All @@ -27,6 +26,7 @@ import androidx.compose.ui.semantics.semantics
import androidx.compose.ui.unit.dp
import androidx.compose.ui.window.Dialog
import androidx.compose.ui.window.DialogProperties
import com.nativephp.mobile.ui.NativeAppearanceState
import com.nativephp.mobile.ui.nativerender.NativeElementBridge
import com.nativephp.mobile.ui.nativerender.NativeUINode
import com.nativephp.mobile.ui.nativerender.NodeView
Expand All @@ -49,7 +49,7 @@ object ModalRenderer {
val a11yLabel = node.props.getString("a11y_label")
val nodeId = node.id

val theme = if (isSystemInDarkTheme()) NativeUITheme.dark else NativeUITheme.light
val theme = if (NativeAppearanceState.isDark()) NativeUITheme.dark else NativeUITheme.light

var showModal by remember { mutableStateOf(false) }
LaunchedEffect(visible) { showModal = visible }
Expand Down
4 changes: 2 additions & 2 deletions resources/android/NavRenderers.kt
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import android.content.Intent
import android.net.Uri
import androidx.compose.foundation.background
import androidx.compose.foundation.clickable
import androidx.compose.foundation.isSystemInDarkTheme
import com.nativephp.mobile.ui.NativeAppearanceState
import androidx.compose.foundation.layout.Box
import androidx.compose.foundation.layout.defaultMinSize
import androidx.compose.foundation.layout.offset
Expand Down Expand Up @@ -54,7 +54,7 @@ object TopBarRenderer {

// Honor explicit text_color / background_color from NavBar builder;
// fall back to system dark-theme heuristic only when nothing is set.
val isDark = isSystemInDarkTheme()
val isDark = NativeAppearanceState.isDark()
val textArgb = props.getColor("text_color", 0)
val textColor = if (textArgb != 0) Color(textArgb) else if (isDark) Color.White else Color.Black
val bgArgb = props.getColor("background_color", 0)
Expand Down
4 changes: 2 additions & 2 deletions resources/android/OutlinedTextInputRenderer.kt
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ package com.nativephp.plugins.native_ui.ui
import androidx.compose.foundation.interaction.FocusInteraction
import androidx.compose.foundation.interaction.Interaction
import androidx.compose.foundation.interaction.MutableInteractionSource
import androidx.compose.foundation.isSystemInDarkTheme
import androidx.compose.foundation.layout.fillMaxWidth
import androidx.compose.foundation.layout.size
import androidx.compose.foundation.text.KeyboardActions
Expand All @@ -25,6 +24,7 @@ import androidx.compose.ui.text.TextStyle
import androidx.compose.ui.text.font.FontFamily
import androidx.compose.ui.text.input.TextFieldValue
import androidx.compose.ui.unit.dp
import com.nativephp.mobile.ui.NativeAppearanceState
import com.nativephp.mobile.ui.nativerender.NativeUINode
import com.nativephp.plugins.native_ui.NativeUITheme

Expand All @@ -41,7 +41,7 @@ object OutlinedTextInputRenderer {
@Composable
fun Render(node: NativeUINode, modifier: Modifier) {
val props = parseTextInputProps(node)
val theme = if (isSystemInDarkTheme()) NativeUITheme.dark else NativeUITheme.light
val theme = if (NativeAppearanceState.isDark()) NativeUITheme.dark else NativeUITheme.light
val scope = rememberCoroutineScope()

// Echo-prevention sync (plan K). Local state owns what the user is
Expand Down
4 changes: 2 additions & 2 deletions resources/android/ProgressBarRenderer.kt
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
package com.nativephp.plugins.native_ui.ui

import androidx.compose.foundation.isSystemInDarkTheme
import androidx.compose.material3.LinearProgressIndicator
import androidx.compose.runtime.Composable
import androidx.compose.ui.Modifier
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.semantics.contentDescription
import androidx.compose.ui.semantics.semantics
import com.nativephp.mobile.ui.NativeAppearanceState
import com.nativephp.mobile.ui.nativerender.NativeUINode
import com.nativephp.plugins.native_ui.NativeUITheme

Expand All @@ -21,7 +21,7 @@ object ProgressBarRenderer {
val indeterminate = p.getBool("indeterminate")
val a11yLabel = p.getString("a11y_label")

val theme = if (isSystemInDarkTheme()) NativeUITheme.dark else NativeUITheme.light
val theme = if (NativeAppearanceState.isDark()) NativeUITheme.dark else NativeUITheme.light

val overrideArgb = p.getColor("color", 0)
val trackOverride = p.getColor("track_color", 0)
Expand Down
4 changes: 2 additions & 2 deletions resources/android/RadioGroupRenderer.kt
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package com.nativephp.plugins.native_ui.ui

import androidx.compose.foundation.isSystemInDarkTheme
import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.Spacer
import androidx.compose.foundation.layout.height
Expand All @@ -13,6 +12,7 @@ import androidx.compose.runtime.remember
import androidx.compose.runtime.setValue
import androidx.compose.ui.Modifier
import androidx.compose.ui.unit.dp
import com.nativephp.mobile.ui.NativeAppearanceState
import com.nativephp.mobile.ui.nativerender.NativeUIBridge
import com.nativephp.mobile.ui.nativerender.NativeUINode
import com.nativephp.mobile.ui.nativerender.RenderNode
Expand All @@ -35,7 +35,7 @@ object RadioGroupRenderer {
val a11yLabel = p.getString("a11y_label")
val a11yHint = p.getString("a11y_hint")

val theme = if (isSystemInDarkTheme()) NativeUITheme.dark else NativeUITheme.light
val theme = if (NativeAppearanceState.isDark()) NativeUITheme.dark else NativeUITheme.light

var selectedValue by remember(node.id) { mutableStateOf(serverValue) }
var lastSentValue by remember(node.id) { mutableStateOf(serverValue) }
Expand Down
Loading