Skip to content
Open
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
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"changes": {
"packages/react/package.json": "Patch"
},
"note": "`@devup-ui/react/native` also tells which breakpoint of devup.json the window is at (`useBreakpoint`, `getBreakpoint`) and whether it is in landscape, for responsive values on React Native (part of #411). One `Dimensions` listener is shared by every component, and a component renders again only when the window crosses into another breakpoint or turns, not on every pixel. The runtime is about 630 bytes minified and gzipped.",
"date": "2026-11-21T00:00:00.000Z"
}
8 changes: 8 additions & 0 deletions .changepacks/changepack_log_react_native_css.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"changes": {
"bindings/devup-ui-binding/package.json": "Patch",
"bindings/devup-ui-wasm/package.json": "Patch"
},
"note": "`codeExtractNative` compiles `css()` for React Native (part of #411): a call compiles to the style it describes, the value React Native's `style` takes, and `className` on a Devup UI element passes it on before the element's style props. `css()` takes objects of style props with responsive values, theme tokens and blocks, conditions choosing between objects, what another `css()` gives, and CSS text whose interpolations are whole values. A `css()` whose styles differ by theme, breakpoint or orientation must be called in a function component or a hook. A `style` prop holding Devup UI elements or `css()` calls now compiles them too. Web output is unchanged.",
"date": "2026-11-21T00:00:00.000Z"
}
8 changes: 8 additions & 0 deletions .changepacks/changepack_log_react_native_pressed.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"changes": {
"bindings/devup-ui-binding/package.json": "Patch",
"bindings/devup-ui-wasm/package.json": "Patch"
},
"note": "`codeExtractNative` compiles press styles for React Native (part of #411): `_active` and its React Native name `_pressed` make the element a `Pressable` (a `Box`, `Flex`, `Center` or `VStack` becomes one, a `Button` already is) whose `style` is a function of whether it is pressed, `({ pressed }) => [styles.a, pressed && styles.b]`. Press styles combine with responsive values, themes, platforms, orientations and conditions, and work with `runtime: false` as they need no runtime. They are build errors on a `Text`, an `Image` or an `Input`, and with `as`. Web output is unchanged.",
"date": "2026-11-21T00:00:00.000Z"
}
8 changes: 8 additions & 0 deletions .changepacks/changepack_log_react_native_responsive.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"changes": {
"bindings/devup-ui-binding/package.json": "Patch",
"bindings/devup-ui-wasm/package.json": "Patch"
},
"note": "`codeExtractNative` compiles responsive values for React Native (part of #411): responsive arrays (`p={[1, null, 3]}`, `null` keeping the value before as on the web), `length`, `shadow` and `typography` tokens with a value at each breakpoint, responsive values inside `_ios`, `_theme*` and conditions, and `_portrait`/`_landscape`. The breakpoints of devup.json are measured against the window width. The build precomputes one style object for each run of breakpoints that share their styles, only for the styles that differ, and picks one by the breakpoint `useBreakpoint()` of `@devup-ui/react/native` gives (by breakpoint and theme where both differ). A value read at runtime in an array applies from its breakpoint on. With `runtime: false` these are build errors. Web output is unchanged.",
"date": "2026-11-21T00:00:00.000Z"
}
3 changes: 3 additions & 0 deletions .github/workflows/publish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,9 @@ on:
- main
- feat/napi-binding
- feat/react-native-metro
- feat/react-native-themes
- feat/react-native-responsive
- feat/react-native-pressed

# Pull requests and every job below run read-only. Only the `release` and
# `deploy-pages` jobs get write permissions, and they run on pushes to main
Expand Down
46 changes: 32 additions & 14 deletions apps/expo/check-bundle.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,19 @@
// placeholders of @devup-ui/react or any module of that package but its React
// Native runtime (`@devup-ui/react/native`), and the styles of src/App.tsx
// must be there as React Native style objects. src/App.tsx reads the theme,
// so it uses the runtime; src/Badge.tsx is styled the same in every theme, so
// it must not.
// the breakpoint and the orientation, so it calls each of those hooks of the
// runtime; src/Badge.tsx is styled the same in every theme and at every
// width, so it must not use the runtime. Its buttons take press styles, which
// React Native's `Pressable` applies through a function for `style`.
import { readdirSync, readFileSync } from 'node:fs'
import { join } from 'node:path'

const PLACEHOLDER = 'Cannot run on the runtime'
/** Names of the runtime that only code using it holds, as minified code keeps them */
const RUNTIME_NAMES = /\b(?:defineThemes|useThemeIndex)\b/g
const RUNTIME_NAMES =
/\b(?:defineThemes|useThemeIndex|useBreakpoint|useLandscape)\b/g
/** The hooks src/App.tsx must call */
const APP_HOOKS = ['useThemeIndex', 'useBreakpoint', 'useLandscape']
/** Modules of @devup-ui/react, by the path Metro resolves */
const REACT_PACKAGE = /(^|[\\/])(@devup-ui[\\/]react|packages[\\/]react)[\\/]/
/** The React Native runtime among them */
Expand Down Expand Up @@ -89,17 +94,19 @@ function mapSources(map) {
: map.sources
}

/** The sources of the code that names the runtime */
/** Each name of the runtime, with the sources of the code that names it */
function runtimeUsers(code, locate) {
const users = new Set()
const users = new Map()
code.split('\n').forEach((line, index) => {
for (const match of line.matchAll(RUNTIME_NAMES)) {
users.add(locate(index, match.index))
const source = locate(index, match.index)
if (source === null || NATIVE_RUNTIME.test(source)) continue
const sources = users.get(match[0]) ?? new Set()
sources.add(source)
users.set(match[0], sources)
}
})
return [...users].filter(
(source) => source !== null && !NATIVE_RUNTIME.test(source),
)
return users
}

for (const platform of ['ios', 'android']) {
Expand All @@ -111,7 +118,12 @@ for (const platform of ['ios', 'android']) {
if (code.includes(PLACEHOLDER)) {
failures.push(`${platform}/${file}: holds "${PLACEHOLDER}"`)
}
for (const style of ['backgroundColor:"#5a44ff"', 'StyleSheet']) {
for (const style of [
'backgroundColor:"#5a44ff"',
'backgroundColor:"#4330d9"',
'StyleSheet',
'style:({pressed:',
]) {
if (!code.replaceAll(' ', '').includes(style)) {
failures.push(`${platform}/${file}: lacks ${style}`)
}
Expand All @@ -129,16 +141,22 @@ for (const platform of ['ios', 'android']) {
failures.push(`${platform}/${file}: lacks @devup-ui/react/native`)
}
const users = runtimeUsers(code, sourceLocator(map))
if (!users.some((source) => /src[\\/]App\.tsx$/.test(source))) {
failures.push(`${platform}/${file}: src/App.tsx does not use the runtime`)
for (const hook of APP_HOOKS) {
const callers = [...(users.get(hook) ?? [])]
if (!callers.some((source) => /src[\\/]App\.tsx$/.test(source))) {
failures.push(`${platform}/${file}: src/App.tsx does not call ${hook}`)
}
}
for (const source of users.filter((source) =>
const all = [
...new Set([...users.values()].flatMap((sources) => [...sources])),
]
for (const source of all.filter((source) =>
/src[\\/]Badge\.tsx$/.test(source),
)) {
failures.push(`${platform}/${file}: ${source} uses the runtime`)
}
console.info(
`${platform}/${file}: ${sources.length} modules, runtime used by ${users.join(', ')}`,
`${platform}/${file}: ${sources.length} modules, runtime used by ${all.join(', ')}`,
)
}
}
Expand Down
17 changes: 11 additions & 6 deletions apps/expo/devup.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,8 @@
},
"length": {
"default": {
"radius": ["12px"]
"radius": ["12px"],
"gutter": ["16px", null, "32px"]
}
},
"shadow": {
Expand All @@ -29,11 +30,15 @@
}
},
"typography": {
"title": {
"fontSize": "24px",
"fontWeight": 700,
"lineHeight": 1.3
}
"title": [
{
"fontSize": "24px",
"fontWeight": 700,
"lineHeight": 1.3
},
null,
{ "fontSize": "32px" }
]
}
}
}
62 changes: 39 additions & 23 deletions apps/expo/src/App.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import {
Box,
Button,
css,
Flex,
Image,
Input,
Expand All @@ -12,6 +13,9 @@ import { useState } from 'react'

import { Badge } from './Badge'

/** The shape both buttons share */
const button = css({ borderRadius: '8px', px: 5, py: 3 })

export function App() {
const [name, setName] = useState('')
const [count, setCount] = useState(0)
Expand All @@ -24,7 +28,8 @@ export function App() {
flexDirection="column"
gap={4}
justifyContent="center"
p={6}
px="$gutter"
py={[6, null, 10]}
>
<Image
borderRadius="16px"
Expand All @@ -36,7 +41,14 @@ export function App() {
Devup UI on React Native
</Text>
<Badge label={`${theme ?? 'light'} theme`} />
<Box bg="$card" borderRadius="$radius" boxShadow="$raised" p={4} w="100%">
<Box
bg="$card"
borderRadius="$radius"
boxShadow="$raised"
maxW={[null, null, '480px']}
p={[4, null, 6]}
w="100%"
>
<Text color="$muted" fontSize="14px" mb={2}>
Your name
</Text>
Expand All @@ -53,28 +65,32 @@ export function App() {
{name ? `Hello, ${name}` : 'Type your name'}
</Text>
</Box>
<Button
bg="#5a44ff"
borderRadius="8px"
onPress={() => setCount(count + 1)}
px={5}
py={3}
>
<Text color="#fff" fontWeight="600">
Pressed {count} times
</Text>
</Button>
<Button
border="1px solid $border"
borderRadius="8px"
onPress={() => setTheme(theme === 'dark' ? 'light' : 'dark')}
px={5}
py={3}
<Flex
_landscape={{ flexDirection: 'row' }}
flexDirection="column"
gap={3}
>
<Text color="$text">
Switch to {theme === 'dark' ? 'light' : 'dark'}
</Text>
</Button>
<Button
_active={{ bg: '#4330d9' }}
bg="#5a44ff"
className={button}
onPress={() => setCount(count + 1)}
>
<Text color="#fff" fontWeight="600">
Pressed {count} times
</Text>
</Button>
<Button
_active={{ opacity: 0.6 }}
border="1px solid $border"
className={button}
onPress={() => setTheme(theme === 'dark' ? 'light' : 'dark')}
>
<Text color="$text">
Switch to {theme === 'dark' ? 'light' : 'dark'}
</Text>
</Button>
</Flex>
</Flex>
)
}
1 change: 1 addition & 0 deletions libs/binding/src/native_theme.rs
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ pub fn native_theme(theme: &Theme) -> NativeTheme {
.iter()
.map(|(name, typography)| (name.clone(), typography_levels(typography)))
.collect(),
breakpoints: theme.breakpoints.clone(),
}
}

Expand Down
9 changes: 9 additions & 0 deletions libs/binding/tests/native.rs
Original file line number Diff line number Diff line change
Expand Up @@ -159,3 +159,12 @@ fn native_extraction_resolves_the_registered_theme() -> Result<(), String> {
assert!(code.contains("backgroundColor: \"#fff\""), "{code}");
Ok(())
}

#[test]
fn native_theme_keeps_the_breakpoints() {
// The web's breakpoints by default, and those devup.json sets
let default = devup_ui_binding_core::native_theme(&theme("{}"));
let custom = devup_ui_binding_core::native_theme(&theme(r#"{ "breakpoints": [0, 600] }"#));
assert_eq!(default.breakpoints, [0, 480, 768, 992, 1280, 1600]);
assert_eq!(custom.breakpoints, [0, 600]);
}
Loading
Loading