@rootnative/core 0.0.0-alpha.17 → 0.0.0-alpha.19

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -175,6 +175,14 @@ Returns a value based on the current breakpoint with cascade fallback.
175
175
  const columns = useBreakpointValue({ compact: 1, medium: 2, expanded: 4 })
176
176
  ```
177
177
 
178
+ ### useWindowDimensions()
179
+
180
+ Returns the window size, the same as the `react-native` hook, but safe in a static web export. Use it when a layout needs the raw width or height.
181
+
182
+ ```tsx
183
+ const { width } = useWindowDimensions()
184
+ ```
185
+
178
186
  ## Exports
179
187
 
180
188
  - `ThemeProvider` — Theme context provider (works with any design system, defaults to MD3)
@@ -186,6 +194,7 @@ const columns = useBreakpointValue({ compact: 1, medium: 2, expanded: 4 })
186
194
  - `material` — MD3 preset object (`lightTheme`, `darkTheme`, `defaultTopAppBarTokens`)
187
195
  - `useBreakpoint` / `breakpoints` — Current window size class
188
196
  - `useBreakpointValue` — Responsive values
197
+ - `useWindowDimensions` — Window size that is safe to hydrate from a static export
189
198
  - `lightTheme` / `darkTheme` — Built-in MD3 themes
190
199
  - `defaultTopAppBarTokens` — MD3 top app bar defaults
191
200
  - `motionTransitions` — The named-transition registry mounted by `ThemeProvider`
package/dist/index.d.mts CHANGED
@@ -3,6 +3,7 @@ export { C as Colors, E as Elevation, b as ElevationLevel, F as FontWeight, c as
3
3
  import { TransitionConfig, NamedTransitions } from '@rootnative/inertia';
4
4
  import * as react_jsx_runtime from 'react/jsx-runtime';
5
5
  import * as React from 'react';
6
+ import { ScaledSize } from 'react-native';
6
7
 
7
8
  declare const lightTheme: Theme;
8
9
 
@@ -320,7 +321,9 @@ declare const breakpoints: {
320
321
  * So this hook reports `compact` for as long as the client is hydrating,
321
322
  * matching the markup exactly, and switches to the measured breakpoint on the
322
323
  * re-render React schedules once hydration finishes. The correction is an
323
- * ordinary update, which *does* patch the DOM.
324
+ * ordinary update, which *does* patch the DOM. The guard lives in this
325
+ * package's `useWindowDimensions`, which this hook reads. Use that hook, not
326
+ * the `react-native` one, when a layout needs the raw width.
324
327
  *
325
328
  * **It costs nothing where there is no hydration.** On native, and on a
326
329
  * single-page web build, `getServerSnapshot` is never called, so the measured
@@ -347,6 +350,34 @@ type BreakpointValues<T> = Partial<Record<Breakpoint, T>> & Record<'compact', T>
347
350
  */
348
351
  declare function useBreakpointValue<T>(values: BreakpointValues<T>): T;
349
352
 
353
+ /**
354
+ * Returns the window size, the same as `useWindowDimensions` from
355
+ * `react-native`, but safe to use in a static web export.
356
+ *
357
+ * **Use this instead of the `react-native` hook for any value that reaches a
358
+ * style or the tree.** A static export (`web.output: 'static'`) renders on a
359
+ * server with no DOM, where react-native-web measures a 0 by 0 window. The
360
+ * client measures the real window on its first render, so the `react-native`
361
+ * hook disagrees with the markup it hydrates, and React 19 keeps the server's
362
+ * style with no error. A carousel slot sized from the width, or a hero height
363
+ * set as a fraction of it, then keeps the layout of a 0 wide window until the
364
+ * reader resizes the window.
365
+ *
366
+ * This hook returns the server's 0 by 0 window while the client hydrates, and
367
+ * the measured window on the re-render React schedules after hydration. That
368
+ * re-render is an ordinary update, which does patch the DOM. On native, and on
369
+ * a single-page web build, nothing hydrates, so the measured window comes back
370
+ * from the first render with no extra pass.
371
+ *
372
+ * `useBreakpoint` reads this hook, so a breakpoint and a raw width cannot
373
+ * disagree during hydration.
374
+ *
375
+ * @example
376
+ * const { width } = useWindowDimensions()
377
+ * const heroHeight = width * 0.56
378
+ */
379
+ declare function useWindowDimensions(): ScaledSize;
380
+
350
381
  /**
351
382
  * Material Design 3 preset — groups all MD3-specific theme values.
352
383
  *
@@ -363,4 +394,4 @@ declare const material: {
363
394
  readonly defaultTopAppBarTokens: TopAppBarTokens;
364
395
  };
365
396
 
366
- export { BaseTheme, type Breakpoint, type BreakpointValues, type ColorScheme, type IconRenderProps, type IconResolver, type IconSource, Motion, Shape, THEME_MODE_STORAGE_KEY, Theme, type ThemeMode, type ThemeModeContextValue, type ThemeModeStorage, type ThemePair, ThemeProvider, type ThemeProviderProps, TopAppBarTokens, applyRoundness, breakpoints, darkTheme, defaultTopAppBarTokens, defineTheme, lightTheme, material, motionTransitions, useBreakpoint, useBreakpointValue, useIconResolver, useTheme, useThemeMode };
397
+ export { BaseTheme, type Breakpoint, type BreakpointValues, type ColorScheme, type IconRenderProps, type IconResolver, type IconSource, Motion, Shape, THEME_MODE_STORAGE_KEY, Theme, type ThemeMode, type ThemeModeContextValue, type ThemeModeStorage, type ThemePair, ThemeProvider, type ThemeProviderProps, TopAppBarTokens, applyRoundness, breakpoints, darkTheme, defaultTopAppBarTokens, defineTheme, lightTheme, material, motionTransitions, useBreakpoint, useBreakpointValue, useIconResolver, useTheme, useThemeMode, useWindowDimensions };
package/dist/index.mjs CHANGED
@@ -341,9 +341,30 @@ function useIconResolver() {
341
341
  return useContext3(IconResolverContext);
342
342
  }
343
343
 
344
- // src/responsive/useBreakpoint.ts
344
+ // src/responsive/useWindowDimensions.ts
345
345
  import { useSyncExternalStore } from "react";
346
- import { useWindowDimensions } from "react-native";
346
+ import { useWindowDimensions as useMeasuredWindowDimensions } from "react-native";
347
+ var subscribeToNothing = () => () => {
348
+ };
349
+ var notHydrating = () => false;
350
+ var isHydratingOnServer = () => true;
351
+ var SERVER_WINDOW = Object.freeze({
352
+ width: 0,
353
+ height: 0,
354
+ scale: 1,
355
+ fontScale: 1
356
+ });
357
+ function useWindowDimensions() {
358
+ const measured = useMeasuredWindowDimensions();
359
+ const hydrating = useSyncExternalStore(
360
+ subscribeToNothing,
361
+ notHydrating,
362
+ isHydratingOnServer
363
+ );
364
+ return hydrating ? SERVER_WINDOW : measured;
365
+ }
366
+
367
+ // src/responsive/useBreakpoint.ts
347
368
  var breakpoints = {
348
369
  compact: 0,
349
370
  medium: 600,
@@ -358,18 +379,9 @@ function getBreakpoint(width) {
358
379
  if (width >= breakpoints.medium) return "medium";
359
380
  return "compact";
360
381
  }
361
- var subscribeToNothing = () => () => {
362
- };
363
- var notHydrating = () => false;
364
- var isHydratingOnServer = () => true;
365
382
  function useBreakpoint() {
366
383
  const { width } = useWindowDimensions();
367
- const hydrating = useSyncExternalStore(
368
- subscribeToNothing,
369
- notHydrating,
370
- isHydratingOnServer
371
- );
372
- return getBreakpoint(hydrating ? 0 : width);
384
+ return getBreakpoint(width);
373
385
  }
374
386
 
375
387
  // src/responsive/useBreakpointValue.ts
@@ -411,5 +423,6 @@ export {
411
423
  useBreakpointValue,
412
424
  useIconResolver,
413
425
  useTheme,
414
- useThemeMode
426
+ useThemeMode,
427
+ useWindowDimensions
415
428
  };
package/llms.txt CHANGED
@@ -1,6 +1,6 @@
1
1
  # @rootnative/core — Theme System for React Native
2
2
 
3
- > Version: 0.0.0-alpha.17
3
+ > Version: 0.0.0-alpha.19
4
4
  > Peer deps: react >=19.2.3 <20.0.0, react-native >=0.83.0 <0.87.0, @rootnative/inertia >=0.0.11 <0.1.0 (required — every animation runs on it)
5
5
  > createMaterialTheme needs no extra install — its color engine (@material/material-color-utilities) is bundled behind the create-theme subpath
6
6
 
@@ -323,13 +323,26 @@ const columns = useBreakpointValue({ compact: 1, medium: 2, expanded: 4 })
323
323
 
324
324
  Type: `useBreakpointValue<T>(values: Partial<Record<Breakpoint, T>> & Record<'compact', T>): T`
325
325
 
326
+ ### useWindowDimensions()
327
+
328
+ Returns the window size, the same as `useWindowDimensions` from `react-native`, but hydration-safe. Use it instead of the `react-native` hook when a layout needs a number rather than a size class: a hero height, a carousel slot, a column count.
329
+
330
+ ```tsx
331
+ import { useWindowDimensions } from '@rootnative/core'
332
+
333
+ const { width } = useWindowDimensions()
334
+ const heroHeight = width * 0.56
335
+ ```
336
+
337
+ Type: `useWindowDimensions(): ScaledSize`
338
+
326
339
  ### Breakpoints and static export (web)
327
340
 
328
- Both hooks are hydration-safe, so **no `useHydrated` gate is needed at the call site**.
341
+ The three hooks are hydration-safe, so **no `useHydrated` gate is needed at the call site**. The `useWindowDimensions` hook from `react-native` is **not**: on a static export it keeps the layout of a 0 wide window until the reader resizes the window.
329
342
 
330
343
  A static export (`web.output: 'static'`) renders on a server with no DOM, where react-native-web's `Dimensions` is fixed at `width: 0` — so every breakpoint resolves to `compact` and that is what ships in the HTML. React 19 does **not** repair a `className`/`style` mismatch during hydration: it adopts the server DOM, keeps it, and fires no recoverable error, so a tablet would silently keep the phone layout.
331
344
 
332
- `useBreakpoint` therefore reports `compact` for as long as the client is hydrating, matching that markup, and switches to the measured breakpoint on the re-render React schedules once hydration finishes. On native and on a single-page web build there is no hydration, so the measured value is returned from the first render at no cost.
345
+ `useWindowDimensions` therefore reports the server's 0 by 0 window for as long as the client is hydrating, matching that markup, and switches to the measured window on the re-render React schedules once hydration finishes. `useBreakpoint` reads it, so it reports `compact` for the same span, and a breakpoint and a raw width cannot disagree. On native and on a single-page web build there is no hydration, so the measured value is returned from the first render at no cost.
333
346
 
334
347
  The practical consequence: a breakpoint-dependent layout **starts compact and widens a frame later** on a static export. That is unavoidable — the server cannot know the viewport — so design the compact variant to be the honest first paint. `Grid` inherits all of this, which matters because it resolves a `columns` map internally and leaves a consumer nowhere to put a gate of their own.
335
348
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@rootnative/core",
3
- "version": "0.0.0-alpha.17",
3
+ "version": "0.0.0-alpha.19",
4
4
  "description": "Design-system agnostic theme engine for RootNative UI — a React Native component library. Ships with Material Design 3 out of the box.",
5
5
  "private": false,
6
6
  "sideEffects": false,