react-native-everything-responsive 0.0.0-stage → 1.0.0

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.
Files changed (100) hide show
  1. package/CHANGELOG.md +16 -0
  2. package/LICENSE +21 -0
  3. package/README.md +459 -2
  4. package/docs/API.md +311 -0
  5. package/lib/core/breakpoints.d.ts +28 -0
  6. package/lib/core/breakpoints.d.ts.map +1 -0
  7. package/lib/core/breakpoints.js +108 -0
  8. package/lib/core/breakpoints.js.map +1 -0
  9. package/lib/core/config.d.ts +24 -0
  10. package/lib/core/config.d.ts.map +1 -0
  11. package/lib/core/config.js +112 -0
  12. package/lib/core/config.js.map +1 -0
  13. package/lib/core/device.d.ts +31 -0
  14. package/lib/core/device.d.ts.map +1 -0
  15. package/lib/core/device.js +35 -0
  16. package/lib/core/device.js.map +1 -0
  17. package/lib/core/grid.d.ts +30 -0
  18. package/lib/core/grid.d.ts.map +1 -0
  19. package/lib/core/grid.js +37 -0
  20. package/lib/core/grid.js.map +1 -0
  21. package/lib/core/info.d.ts +26 -0
  22. package/lib/core/info.d.ts.map +1 -0
  23. package/lib/core/info.js +41 -0
  24. package/lib/core/info.js.map +1 -0
  25. package/lib/core/layout.d.ts +4 -0
  26. package/lib/core/layout.d.ts.map +1 -0
  27. package/lib/core/layout.js +31 -0
  28. package/lib/core/layout.js.map +1 -0
  29. package/lib/core/scaling.d.ts +28 -0
  30. package/lib/core/scaling.d.ts.map +1 -0
  31. package/lib/core/scaling.js +47 -0
  32. package/lib/core/scaling.js.map +1 -0
  33. package/lib/core/types.d.ts +153 -0
  34. package/lib/core/types.d.ts.map +1 -0
  35. package/lib/core/types.js +8 -0
  36. package/lib/core/types.js.map +1 -0
  37. package/lib/index.d.ts +26 -0
  38. package/lib/index.d.ts.map +1 -0
  39. package/lib/index.js +54 -0
  40. package/lib/index.js.map +1 -0
  41. package/lib/native/ResponsiveGrid.d.ts +61 -0
  42. package/lib/native/ResponsiveGrid.d.ts.map +1 -0
  43. package/lib/native/ResponsiveGrid.js +110 -0
  44. package/lib/native/ResponsiveGrid.js.map +1 -0
  45. package/lib/native/ResponsiveProvider.d.ts +19 -0
  46. package/lib/native/ResponsiveProvider.d.ts.map +1 -0
  47. package/lib/native/ResponsiveProvider.js +26 -0
  48. package/lib/native/ResponsiveProvider.js.map +1 -0
  49. package/lib/native/ResponsiveView.d.ts +30 -0
  50. package/lib/native/ResponsiveView.d.ts.map +1 -0
  51. package/lib/native/ResponsiveView.js +51 -0
  52. package/lib/native/ResponsiveView.js.map +1 -0
  53. package/lib/native/Visibility.d.ts +45 -0
  54. package/lib/native/Visibility.d.ts.map +1 -0
  55. package/lib/native/Visibility.js +53 -0
  56. package/lib/native/Visibility.js.map +1 -0
  57. package/lib/native/context.d.ts +6 -0
  58. package/lib/native/context.d.ts.map +1 -0
  59. package/lib/native/context.js +12 -0
  60. package/lib/native/context.js.map +1 -0
  61. package/lib/native/createStyles.d.ts +46 -0
  62. package/lib/native/createStyles.d.ts.map +1 -0
  63. package/lib/native/createStyles.js +68 -0
  64. package/lib/native/createStyles.js.map +1 -0
  65. package/lib/native/hooks.d.ts +33 -0
  66. package/lib/native/hooks.d.ts.map +1 -0
  67. package/lib/native/hooks.js +68 -0
  68. package/lib/native/hooks.js.map +1 -0
  69. package/lib/native/platform.d.ts +10 -0
  70. package/lib/native/platform.d.ts.map +1 -0
  71. package/lib/native/platform.js +50 -0
  72. package/lib/native/platform.js.map +1 -0
  73. package/lib/native/snapshot.d.ts +8 -0
  74. package/lib/native/snapshot.d.ts.map +1 -0
  75. package/lib/native/snapshot.js +29 -0
  76. package/lib/native/snapshot.js.map +1 -0
  77. package/lib/native/store.d.ts +14 -0
  78. package/lib/native/store.d.ts.map +1 -0
  79. package/lib/native/store.js +51 -0
  80. package/lib/native/store.js.map +1 -0
  81. package/package.json +50 -4
  82. package/src/core/breakpoints.ts +101 -0
  83. package/src/core/config.ts +130 -0
  84. package/src/core/device.ts +46 -0
  85. package/src/core/grid.ts +54 -0
  86. package/src/core/info.ts +64 -0
  87. package/src/core/layout.ts +44 -0
  88. package/src/core/scaling.ts +62 -0
  89. package/src/core/types.ts +178 -0
  90. package/src/index.ts +59 -0
  91. package/src/native/ResponsiveGrid.tsx +159 -0
  92. package/src/native/ResponsiveProvider.tsx +30 -0
  93. package/src/native/ResponsiveView.tsx +98 -0
  94. package/src/native/Visibility.tsx +82 -0
  95. package/src/native/context.ts +11 -0
  96. package/src/native/createStyles.ts +94 -0
  97. package/src/native/hooks.ts +102 -0
  98. package/src/native/platform.ts +54 -0
  99. package/src/native/snapshot.ts +27 -0
  100. package/src/native/store.ts +58 -0
@@ -0,0 +1,61 @@
1
+ import React from 'react';
2
+ import type { ReactNode } from 'react';
3
+ import type { LayoutChangeEvent, StyleProp, ViewProps, ViewStyle } from 'react-native';
4
+ import type { GridLayout } from '../core/grid';
5
+ import type { ResponsiveValue } from '../core/types';
6
+ import type { SourceOptions } from './hooks';
7
+ export interface GridOptions extends SourceOptions {
8
+ /** Fixed number of columns. Default `{ xs: 1, sm: 2, md: 3, lg: 4 }`. */
9
+ columns?: ResponsiveValue<number>;
10
+ /**
11
+ * Auto-fit mode (like CSS `repeat(auto-fill, minmax(X, 1fr))`): fit as many columns
12
+ * as possible with each item at least this wide. Overrides `columns`.
13
+ */
14
+ minItemWidth?: ResponsiveValue<number>;
15
+ /** Maximum columns in auto-fit mode. */
16
+ maxColumns?: ResponsiveValue<number>;
17
+ /** Gap between rows and columns. Default 0. */
18
+ gap?: ResponsiveValue<number>;
19
+ /** Gap between rows. Overrides `gap`. */
20
+ rowGap?: ResponsiveValue<number>;
21
+ /** Gap between columns. Overrides `gap`. */
22
+ columnGap?: ResponsiveValue<number>;
23
+ }
24
+ export interface ResponsiveGridProps extends ViewProps, GridOptions {
25
+ /** Extra style for every cell wrapper. */
26
+ itemStyle?: StyleProp<ViewStyle>;
27
+ children?: ReactNode;
28
+ }
29
+ export interface GridLayoutResult extends GridLayout {
30
+ rowGap: number;
31
+ columnGap: number;
32
+ /** Attach to the grid's outer View (or FlatList) so its width is measured. */
33
+ onLayout: (event: LayoutChangeEvent) => void;
34
+ }
35
+ /**
36
+ * Grid maths as a hook, for use with `FlatList`/`SectionList` virtualised grids.
37
+ *
38
+ * React Native does not allow changing `numColumns` on a mounted FlatList, so pass
39
+ * `key={columns}` to remount it when the column count changes.
40
+ *
41
+ * @example
42
+ * const grid = useGridLayout({ minItemWidth: 160, gap: 12 });
43
+ * <FlatList key={grid.columns} numColumns={grid.columns} onLayout={grid.onLayout}
44
+ * columnWrapperStyle={grid.columns > 1 ? { gap: grid.columnGap } : undefined}
45
+ * renderItem={({ item }) => <Card style={{ width: grid.itemWidth }} />} />
46
+ */
47
+ export declare function useGridLayout(options?: GridOptions): GridLayoutResult;
48
+ /**
49
+ * A responsive grid for a small or medium number of children (for long lists use
50
+ * `useGridLayout` with a FlatList). Supports fixed and auto-fit columns, independent
51
+ * row/column gaps, RTL layouts, and pixel-exact widths so rows never wrap unexpectedly.
52
+ *
53
+ * @example
54
+ * <ResponsiveGrid columns={{ xs: 1, md: 2, xl: 4 }} gap={16}>
55
+ * {products.map((p) => <ProductCard key={p.id} product={p} />)}
56
+ * </ResponsiveGrid>
57
+ *
58
+ * <ResponsiveGrid minItemWidth={180} gap={12}>...</ResponsiveGrid>
59
+ */
60
+ export declare function ResponsiveGrid({ columns, minItemWidth, maxColumns, gap, rowGap, columnGap, source, itemStyle, style, onLayout, children, ...viewProps }: ResponsiveGridProps): React.JSX.Element;
61
+ //# sourceMappingURL=ResponsiveGrid.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"ResponsiveGrid.d.ts","sourceRoot":"","sources":["../../src/native/ResponsiveGrid.tsx"],"names":[],"mappings":"AAAA,OAAO,KAA+D,MAAM,OAAO,CAAC;AACpF,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,OAAO,CAAC;AAEvC,OAAO,KAAK,EAAE,iBAAiB,EAAE,SAAS,EAAE,SAA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,SAAS,EACT,KAAK,EACL,QAAQ,EACR,QAAQ,EACR,GAAG,SAAS,EACb,EAAE,mBAAmB,GAAG,KAAK,CAAC,GAAG,CAAC,OAAO,CAsCzC"}
@@ -0,0 +1,110 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
15
+ }) : function(o, v) {
16
+ o["default"] = v;
17
+ });
18
+ var __importStar = (this && this.__importStar) || function (mod) {
19
+ if (mod && mod.__esModule) return mod;
20
+ var result = {};
21
+ if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
22
+ __setModuleDefault(result, mod);
23
+ return result;
24
+ };
25
+ Object.defineProperty(exports, "__esModule", { value: true });
26
+ exports.useGridLayout = useGridLayout;
27
+ exports.ResponsiveGrid = ResponsiveGrid;
28
+ const jsx_runtime_1 = require("react/jsx-runtime");
29
+ const react_1 = __importStar(require("react"));
30
+ const react_native_1 = require("react-native");
31
+ const breakpoints_1 = require("../core/breakpoints");
32
+ const grid_1 = require("../core/grid");
33
+ const context_1 = require("./context");
34
+ const hooks_1 = require("./hooks");
35
+ const store_1 = require("./store");
36
+ const DEFAULT_COLUMNS = { xs: 1, sm: 2, md: 3, lg: 4 };
37
+ /**
38
+ * Grid maths as a hook, for use with `FlatList`/`SectionList` virtualised grids.
39
+ *
40
+ * React Native does not allow changing `numColumns` on a mounted FlatList, so pass
41
+ * `key={columns}` to remount it when the column count changes.
42
+ *
43
+ * @example
44
+ * const grid = useGridLayout({ minItemWidth: 160, gap: 12 });
45
+ * <FlatList key={grid.columns} numColumns={grid.columns} onLayout={grid.onLayout}
46
+ * columnWrapperStyle={grid.columns > 1 ? { gap: grid.columnGap } : undefined}
47
+ * renderItem={({ item }) => <Card style={{ width: grid.itemWidth }} />} />
48
+ */
49
+ function useGridLayout(options = {}) {
50
+ var _a, _b, _c, _d, _e;
51
+ const breakpoint = (0, hooks_1.useBreakpoint)({ source: options.source });
52
+ const container = (0, react_1.useContext)(context_1.ContainerContext);
53
+ const [measuredWidth, setMeasuredWidth] = (0, react_1.useState)(null);
54
+ const onLayout = (0, react_1.useCallback)((event) => {
55
+ const width = event.nativeEvent.layout.width;
56
+ setMeasuredWidth((previous) => (previous !== null && Math.abs(previous - width) < 0.5 ? previous : width));
57
+ }, []);
58
+ const pick = (value) => value === undefined ? undefined : (0, breakpoints_1.resolveResponsiveValue)(value, breakpoint);
59
+ const gap = (_a = pick(options.gap)) !== null && _a !== void 0 ? _a : 0;
60
+ const rowGap = (_b = pick(options.rowGap)) !== null && _b !== void 0 ? _b : gap;
61
+ const columnGap = (_c = pick(options.columnGap)) !== null && _c !== void 0 ? _c : gap;
62
+ const columns = pick((_d = options.columns) !== null && _d !== void 0 ? _d : DEFAULT_COLUMNS);
63
+ const minItemWidth = pick(options.minItemWidth);
64
+ const maxColumns = pick(options.maxColumns);
65
+ const width = (_e = measuredWidth !== null && measuredWidth !== void 0 ? measuredWidth : container === null || container === void 0 ? void 0 : container.width) !== null && _e !== void 0 ? _e : (0, store_1.getSnapshot)().window.width;
66
+ const layout = (0, react_1.useMemo)(() => (0, grid_1.computeGridLayout)({
67
+ containerWidth: width,
68
+ columns,
69
+ minItemWidth,
70
+ maxColumns,
71
+ columnGap,
72
+ pixelRatio: react_native_1.PixelRatio.get(),
73
+ }), [width, columns, minItemWidth, maxColumns, columnGap]);
74
+ return { ...layout, rowGap, columnGap, onLayout };
75
+ }
76
+ /**
77
+ * A responsive grid for a small or medium number of children (for long lists use
78
+ * `useGridLayout` with a FlatList). Supports fixed and auto-fit columns, independent
79
+ * row/column gaps, RTL layouts, and pixel-exact widths so rows never wrap unexpectedly.
80
+ *
81
+ * @example
82
+ * <ResponsiveGrid columns={{ xs: 1, md: 2, xl: 4 }} gap={16}>
83
+ * {products.map((p) => <ProductCard key={p.id} product={p} />)}
84
+ * </ResponsiveGrid>
85
+ *
86
+ * <ResponsiveGrid minItemWidth={180} gap={12}>...</ResponsiveGrid>
87
+ */
88
+ function ResponsiveGrid({ columns, minItemWidth, maxColumns, gap, rowGap, columnGap, source, itemStyle, style, onLayout, children, ...viewProps }) {
89
+ const grid = useGridLayout({ columns, minItemWidth, maxColumns, gap, rowGap, columnGap, source });
90
+ const gridOnLayout = grid.onLayout;
91
+ const handleLayout = (0, react_1.useCallback)((event) => {
92
+ gridOnLayout(event);
93
+ onLayout === null || onLayout === void 0 ? void 0 : onLayout(event);
94
+ }, [gridOnLayout, onLayout]);
95
+ const items = react_1.Children.toArray(children);
96
+ return ((0, jsx_runtime_1.jsx)(react_native_1.View, { ...viewProps, style: [{ flexDirection: 'row', flexWrap: 'wrap' }, style], onLayout: handleLayout, children: items.map((child, index) => {
97
+ const column = index % grid.columns;
98
+ const row = Math.floor(index / grid.columns);
99
+ const key = react_1.default.isValidElement(child) && child.key != null ? child.key : index;
100
+ return ((0, jsx_runtime_1.jsx)(react_native_1.View, { style: [
101
+ {
102
+ width: grid.itemWidth,
103
+ marginStart: column === 0 ? 0 : grid.columnGap,
104
+ marginTop: row === 0 ? 0 : grid.rowGap,
105
+ },
106
+ itemStyle,
107
+ ], children: child }, key));
108
+ }) }));
109
+ }
110
+ //# sourceMappingURL=ResponsiveGrid.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"ResponsiveGrid.js","sourceRoot":"","sources":["../../src/native/ResponsiveGrid.tsx"],"names":[],"mappings":";;;;;;;;;;;;;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AAI,CAAC,MAAM;qBACvC;oBACD,SAAS;iBACV,YAEA,KAAK,IAVD,GAAG,CAWH,CACR,CAAC;QACJ,CAAC,CAAC,GACG,CACR,CAAC;AACJ,CAAC"}
@@ -0,0 +1,19 @@
1
+ import React from 'react';
2
+ import type { ReactNode } from 'react';
3
+ import type { ResponsiveConfigInput } from '../core/types';
4
+ export interface ResponsiveProviderProps {
5
+ /** Partial configuration merged over the parent provider's (or the defaults). */
6
+ config?: ResponsiveConfigInput;
7
+ children?: ReactNode;
8
+ }
9
+ /**
10
+ * Optional. Use it only to customise breakpoints or scaling; every hook and component
11
+ * works without it. Providers can be nested: inner ones inherit from outer ones.
12
+ *
13
+ * @example
14
+ * <ResponsiveProvider config={{ breakpoints: { md: 640 }, maxScale: 1.25 }}>
15
+ * <App />
16
+ * </ResponsiveProvider>
17
+ */
18
+ export declare function ResponsiveProvider({ config, children }: ResponsiveProviderProps): React.JSX.Element;
19
+ //# sourceMappingURL=ResponsiveProvider.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"ResponsiveProvider.d.ts","sourceRoot":"","sources":["../../src/native/ResponsiveProvider.tsx"],"names":[],"mappings":"AAAA,OAAO,KAA8B,MAAM,OAAO,CAAC;AACnD,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,OAAO,CAAC;AAEvC,OAAO,KAAK,EAAE,qBAAqB,EAAE,MAAM,eAAe,CAAC;AAG3D,MAAM,WAAW,uBAAuB;IACtC,iFAAiF;IACjF,MAAM,CAAC,EAAE,qBAAqB,CAAC;IAC/B,QAAQ,CAAC,EAAE,SAAS,CAAC;CACtB;AAED;;;;;;;;GAQG;AACH,wBAAgB,kBAAkB,CAAC,EAAE,MAAM,EAAE,QAAQ,EAAE,EAAE,uBAAuB,GAAG,KAAK,CAAC,GAAG,CAAC,OAAO,CAQnG"}
@@ -0,0 +1,26 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.ResponsiveProvider = ResponsiveProvider;
4
+ const jsx_runtime_1 = require("react/jsx-runtime");
5
+ const react_1 = require("react");
6
+ const config_1 = require("../core/config");
7
+ const context_1 = require("./context");
8
+ /**
9
+ * Optional. Use it only to customise breakpoints or scaling; every hook and component
10
+ * works without it. Providers can be nested: inner ones inherit from outer ones.
11
+ *
12
+ * @example
13
+ * <ResponsiveProvider config={{ breakpoints: { md: 640 }, maxScale: 1.25 }}>
14
+ * <App />
15
+ * </ResponsiveProvider>
16
+ */
17
+ function ResponsiveProvider({ config, children }) {
18
+ const parent = (0, react_1.useContext)(context_1.ConfigContext);
19
+ // Config is plain data, so a serialised key lets callers pass inline objects
20
+ // without re-rendering the whole tree on every parent render.
21
+ const key = config ? JSON.stringify(config) : '';
22
+ // eslint-disable-next-line react-hooks/exhaustive-deps
23
+ const value = (0, react_1.useMemo)(() => (0, config_1.createConfig)(config, parent), [parent, key]);
24
+ return (0, jsx_runtime_1.jsx)(context_1.ConfigContext.Provider, { value: value, children: children });
25
+ }
26
+ //# sourceMappingURL=ResponsiveProvider.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"ResponsiveProvider.js","sourceRoot":"","sources":["../../src/native/ResponsiveProvider.tsx"],"names":[],"mappings":";;AAqBA,gDAQC;;AA7BD,iCAAmD;AAEnD,2CAA8C;AAE9C,uCAA0C;AAQ1C;;;;;;;;GAQG;AACH,SAAgB,kBAAkB,CAAC,EAAE,MAAM,EAAE,QAAQ,EAA2B;IAC9E,MAAM,MAAM,GAAG,IAAA,kBAAU,EAAC,uBAAa,CAAC,CAAC;IACzC,6EAA6E;IAC7E,8DAA8D;IAC9D,MAAM,GAAG,GAAG,MAAM,CAAC,CAAC,CAAC,IAAI,CAAC,SAAS,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,EAAE,CAAC;IACjD,uDAAuD;IACvD,MAAM,KAAK,GAAG,IAAA,eAAO,EAAC,GAAG,EAAE,CAAC,IAAA,qBAAY,EAAC,MAAM,EAAE,MAAM,CAAC,EAAE,CAAC,MAAM,EAAE,GAAG,CAAC,CAAC,CAAC;IACzE,OAAO,uBAAC,uBAAa,CAAC,QAAQ,IAAC,KAAK,EAAE,KAAK,YAAG,QAAQ,GAA0B,CAAC;AACnF,CAAC"}
@@ -0,0 +1,30 @@
1
+ import React from 'react';
2
+ import type { ViewProps } from 'react-native';
3
+ import type { BreakpointKey } from '../core/types';
4
+ export interface ResponsiveViewProps extends ViewProps {
5
+ /** Custom breakpoints for this container only (merged over the global ones). */
6
+ breakpoints?: Partial<Record<BreakpointKey, number>>;
7
+ /**
8
+ * Width to assume before the first layout pass. Default: the parent container's width,
9
+ * or the window width. Set it when you know the container is narrow (e.g. a sidebar)
10
+ * to avoid a one-frame flash of the wide layout.
11
+ */
12
+ initialWidth?: number;
13
+ /** Height to assume before the first layout pass. */
14
+ initialHeight?: number;
15
+ /** Render children only after the container has been measured. Default false. */
16
+ waitForLayout?: boolean;
17
+ }
18
+ /**
19
+ * A `View` that turns itself into a **container query** boundary.
20
+ *
21
+ * Every hook, `createStyles`, `<Show>`, `<Hide>` and `<ResponsiveGrid>` inside it measures
22
+ * this view instead of the window (unless they ask for `source: 'window'`). The same card
23
+ * component can then lay out as "wide" in a main column and "narrow" in a sidebar,
24
+ * which window-based media queries cannot do.
25
+ *
26
+ * Prefer width-based logic inside containers: when children change the container's
27
+ * height based on the container's height, layouts can oscillate.
28
+ */
29
+ export declare function ResponsiveView({ breakpoints, initialWidth, initialHeight, waitForLayout, onLayout, children, ...viewProps }: ResponsiveViewProps): React.JSX.Element;
30
+ //# sourceMappingURL=ResponsiveView.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"ResponsiveView.d.ts","sourceRoot":"","sources":["../../src/native/ResponsiveView.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAqD,MAAM,OAAO,CAAC;AAE1E,OAAO,KAAK,EAAqB,SAAS,EAAE,MAAM,cAAc,CAAC;AAGjE,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,eAAe,CAAC;AAKnD,MAAM,WAAW,mBAAoB,SAAQ,SAAS;IACpD,gFAAgF;IAChF,WAAW,CAAC,EAAE,OAAO,CAAC,MAAM,CAAC,aAAa,EAAE,MAAM,CAAC,CAAC,CAAC;IACrD;;;;OAIG;IACH,YAAY,CAAC,EAAE,MAAM,CAAC;IACtB,qDAAqD;IACrD,aAAa,CAAC,EAAE,MAAM,CAAC;IACvB,iFAAiF;IACjF,aAAa,CAAC,EAAE,OAAO,CAAC;CACzB;AAQD;;;;;;;;;;GAUG;AACH,wBAAgB,cAAc,CAAC,EAC7B,WAAW,EACX,YAAY,EACZ,aAAa,EACb,aAAqB,EACrB,QAAQ,EACR,QAAQ,EACR,GAAG,SAAS,EACb,EAAE,mBAAmB,GAAG,KAAK,CAAC,GAAG,CAAC,OAAO,CA+CzC"}
@@ -0,0 +1,51 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.ResponsiveView = ResponsiveView;
4
+ const jsx_runtime_1 = require("react/jsx-runtime");
5
+ const react_1 = require("react");
6
+ const react_native_1 = require("react-native");
7
+ const config_1 = require("../core/config");
8
+ const layout_1 = require("../core/layout");
9
+ const context_1 = require("./context");
10
+ const platform_1 = require("./platform");
11
+ const store_1 = require("./store");
12
+ /**
13
+ * A `View` that turns itself into a **container query** boundary.
14
+ *
15
+ * Every hook, `createStyles`, `<Show>`, `<Hide>` and `<ResponsiveGrid>` inside it measures
16
+ * this view instead of the window (unless they ask for `source: 'window'`). The same card
17
+ * component can then lay out as "wide" in a main column and "narrow" in a sidebar,
18
+ * which window-based media queries cannot do.
19
+ *
20
+ * Prefer width-based logic inside containers: when children change the container's
21
+ * height based on the container's height, layouts can oscillate.
22
+ */
23
+ function ResponsiveView({ breakpoints, initialWidth, initialHeight, waitForLayout = false, onLayout, children, ...viewProps }) {
24
+ const config = (0, react_1.useContext)(context_1.ConfigContext);
25
+ const parent = (0, react_1.useContext)(context_1.ContainerContext);
26
+ const [size, setSize] = (0, react_1.useState)(() => {
27
+ var _a, _b;
28
+ const { window } = (0, store_1.getSnapshot)();
29
+ return {
30
+ width: (_a = initialWidth !== null && initialWidth !== void 0 ? initialWidth : parent === null || parent === void 0 ? void 0 : parent.width) !== null && _a !== void 0 ? _a : window.width,
31
+ height: (_b = initialHeight !== null && initialHeight !== void 0 ? initialHeight : parent === null || parent === void 0 ? void 0 : parent.height) !== null && _b !== void 0 ? _b : window.height,
32
+ measured: false,
33
+ };
34
+ });
35
+ const breakpointsKey = breakpoints ? JSON.stringify(breakpoints) : '';
36
+ const table = (0, react_1.useMemo)(() => (0, config_1.mergeBreakpoints)(config.breakpoints, breakpoints),
37
+ // eslint-disable-next-line react-hooks/exhaustive-deps
38
+ [config.breakpoints, breakpointsKey]);
39
+ const handleLayout = (0, react_1.useCallback)((event) => {
40
+ const { width, height } = event.nativeEvent.layout;
41
+ setSize((previous) => previous.measured &&
42
+ Math.abs(previous.width - width) < 0.5 &&
43
+ Math.abs(previous.height - height) < 0.5
44
+ ? previous
45
+ : { width, height, measured: true });
46
+ onLayout === null || onLayout === void 0 ? void 0 : onLayout(event);
47
+ }, [onLayout]);
48
+ const layout = (0, react_1.useMemo)(() => (0, layout_1.createLayoutInfo)('container', size.width, size.height, table, platform_1.roundToPixel), [size.width, size.height, table]);
49
+ return ((0, jsx_runtime_1.jsx)(react_native_1.View, { ...viewProps, onLayout: handleLayout, children: (0, jsx_runtime_1.jsx)(context_1.ContainerContext.Provider, { value: layout, children: waitForLayout && !size.measured ? null : children }) }));
50
+ }
51
+ //# sourceMappingURL=ResponsiveView.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"ResponsiveView.js","sourceRoot":"","sources":["../../src/native/ResponsiveView.tsx"],"names":[],"mappings":";;AA0CA,wCAuDC;;AAjGD,iCAA0E;AAC1E,+CAAoC;AAEpC,2CAAkD;AAClD,2CAAkD;AAElD,uCAA4D;AAC5D,yCAA0C;AAC1C,mCAAsC;AAuBtC;;;;;;;;;;GAUG;AACH,SAAgB,cAA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Q,CAAC,QAAQ;YACjB,IAAI,CAAC,GAAG,CAAC,QAAQ,CAAC,KAAK,GAAG,KAAK,CAAC,GAAG,GAAG;YACtC,IAAI,CAAC,GAAG,CAAC,QAAQ,CAAC,MAAM,GAAG,MAAM,CAAC,GAAG,GAAG;YACtC,CAAC,CAAC,QAAQ;YACV,CAAC,CAAC,EAAE,KAAK,EAAE,MAAM,EAAE,QAAQ,EAAE,IAAI,EAAE,CACtC,CAAC;QACF,QAAQ,aAAR,QAAQ,uBAAR,QAAQ,CAAG,KAAK,CAAC,CAAC;IACpB,CAAC,EACD,CAAC,QAAQ,CAAC,CACX,CAAC;IAEF,MAAM,MAAM,GAAG,IAAA,eAAO,EACpB,GAAG,EAAE,CAAC,IAAA,yBAAgB,EAAC,WAAW,EAAE,IAAI,CAAC,KAAK,EAAE,IAAI,CAAC,MAAM,EAAE,KAAK,EAAE,uBAAY,CAAC,EACjF,CAAC,IAAI,CAAC,KAAK,EAAE,IAAI,CAAC,MAAM,EAAE,KAAK,CAAC,CACjC,CAAC;IAEF,OAAO,CACL,uBAAC,mBAAI,OAAK,SAAS,EAAE,QAAQ,EAAE,YAAY,YACzC,uBAAC,0BAAgB,CAAC,QAAQ,IAAC,KAAK,EAAE,MAAM,YACrC,aAAa,IAAI,CAAC,IAAI,CAAC,QAAQ,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,QAAQ,GACxB,GACvB,CACR,CAAC;AACJ,CAAC"}
@@ -0,0 +1,45 @@
1
+ import React from 'react';
2
+ import type { ReactNode } from 'react';
3
+ import type { BreakpointKey, DeviceType, Orientation, ResponsiveInfo } from '../core/types';
4
+ import type { SourceOptions } from './hooks';
5
+ export interface VisibilityConditions extends SourceOptions {
6
+ /** Match at this breakpoint and larger. */
7
+ from?: BreakpointKey;
8
+ /** Match strictly below this breakpoint. */
9
+ below?: BreakpointKey;
10
+ /** Match only at these breakpoints. */
11
+ only?: BreakpointKey | readonly BreakpointKey[];
12
+ /** Match only on these device types (hardware). */
13
+ device?: DeviceType | readonly DeviceType[];
14
+ /** Match only in this orientation (of the measured area). */
15
+ orientation?: Orientation;
16
+ /** Custom predicate, for anything the props above cannot express. */
17
+ when?: (r: ResponsiveInfo) => boolean;
18
+ }
19
+ export interface VisibilityProps extends VisibilityConditions {
20
+ children?: ReactNode;
21
+ /** Rendered instead of `children` when hidden. */
22
+ fallback?: ReactNode;
23
+ /**
24
+ * `'unmount'` (default) removes hidden children from the tree.
25
+ * `'hide'` keeps them mounted (state, video playback and scroll position are preserved)
26
+ * inside a wrapper View with `display: 'none'`.
27
+ */
28
+ mode?: 'unmount' | 'hide';
29
+ }
30
+ /** True when every given condition matches. Conditions that are not given are ignored. */
31
+ export declare function matchesConditions(r: ResponsiveInfo, c: VisibilityConditions): boolean;
32
+ /** Hook form of `<Show>`: true when all conditions match. */
33
+ export declare function useMatches(conditions: VisibilityConditions): boolean;
34
+ /**
35
+ * Renders children only when **all** given conditions match.
36
+ *
37
+ * @example
38
+ * <Show from="md">Sidebar</Show>
39
+ * <Show below="md" fallback={<FullMenu />}><HamburgerMenu /></Show>
40
+ * <Show device="tablet" orientation="landscape">Two-pane layout</Show>
41
+ */
42
+ export declare function Show(props: VisibilityProps): React.JSX.Element;
43
+ /** The opposite of `<Show>`: hides children when **all** given conditions match. */
44
+ export declare function Hide(props: VisibilityProps): React.JSX.Element;
45
+ //# sourceMappingURL=Visibility.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"Visibility.d.ts","sourceRoot":"","sources":["../../src/native/Visibility.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,MAAM,OAAO,CAAC;AAC1B,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,OAAO,CAAC;AAEvC,OAAO,KAAK,EAAE,aAAa,EAAE,UAAU,EAAE,WAAW,EAAE,cAAc,EAAE,MAAM,eAAe,CAAC;AAE5F,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,SAAS,CAAC;AAE7C,MAAM,WAAW,oBAAqB,SAAQ,aAAa;IACzD,2CAA2C;IAC3C,IAAI,CAAC,EAAE,aAAa,CAAC;IACrB,4CAA4C;IAC5C,KAAK,CAAC,EAAE,aAAa,CAAC;IACtB,uCAAuC;IACvC,IAAI,CAAC,EAAE,aAAa,GAAG,SAAS,aAAa,EAAE,CAAC;IAChD,mDAAmD;IACnD,MAAM,CAAC,EAAE,UAAU,GAAG,SAAS,UAAU,EAAE,CAAC;IAC5C,6DAA6D;IAC7D,WAAW,CAAC,EAAE,WAAW,CAAC;IAC1B,qEAAqE;IACrE,IAAI,CAAC,EAAE,CAAC,CAAC,EAAE,cAAc,KAAK,OAAO,CAAC;CACvC;AAED,MAAM,WAAW,eAAgB,SAAQ,oBAAoB;IAC3D,QAAQ,CAAC,EAAE,SAAS,CAAC;IACrB,kDAAkD;IAClD,QAAQ,CAAC,EAAE,SAAS,CAAC;IACrB;;;;OAIG;IACH,IAAI,CAAC,EAAE,SAAS,GAAG,MAAM,CAAC;CAC3B;AAKD,0FAA0F;AAC1F,wBAAgB,iBAAiB,CAAC,CAAC,EAAE,cAAc,EAAE,CAAC,EAAE,oBAAoB,GAAG,OAAO,CAQrF;AAED,6DAA6D;AAC7D,wBAAgB,UAAU,CAAC,UAAU,EAAE,oBAAoB,GAAG,OAAO,CAGpE;AAcD;;;;;;;GAOG;AACH,wBAAgB,IAAI,CAAC,KAAK,EAAE,eAAe,GAAG,KAAK,CAAC,GAAG,CAAC,OAAO,CAE9D;AAED,oFAAoF;AACpF,wBAAgB,IAAI,CAAC,KAAK,EAAE,eAAe,GAAG,KAAK,CAAC,GAAG,CAAC,OAAO,CAE9D"}
@@ -0,0 +1,53 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.matchesConditions = matchesConditions;
4
+ exports.useMatches = useMatches;
5
+ exports.Show = Show;
6
+ exports.Hide = Hide;
7
+ const jsx_runtime_1 = require("react/jsx-runtime");
8
+ const react_native_1 = require("react-native");
9
+ const hooks_1 = require("./hooks");
10
+ const asArray = (value) => Array.isArray(value) ? value : [value];
11
+ /** True when every given condition matches. Conditions that are not given are ignored. */
12
+ function matchesConditions(r, c) {
13
+ if (c.from !== undefined && !r.from(c.from))
14
+ return false;
15
+ if (c.below !== undefined && !r.below(c.below))
16
+ return false;
17
+ if (c.only !== undefined && !r.only(...asArray(c.only)))
18
+ return false;
19
+ if (c.device !== undefined && !asArray(c.device).includes(r.deviceType))
20
+ return false;
21
+ if (c.orientation !== undefined && r.orientation !== c.orientation)
22
+ return false;
23
+ if (c.when !== undefined && !c.when(r))
24
+ return false;
25
+ return true;
26
+ }
27
+ /** Hook form of `<Show>`: true when all conditions match. */
28
+ function useMatches(conditions) {
29
+ const r = (0, hooks_1.useResponsive)({ source: conditions.source });
30
+ return matchesConditions(r, conditions);
31
+ }
32
+ function render(visible, { children, fallback, mode = 'unmount' }) {
33
+ if (mode === 'hide') {
34
+ return ((0, jsx_runtime_1.jsxs)(jsx_runtime_1.Fragment, { children: [(0, jsx_runtime_1.jsx)(react_native_1.View, { style: { display: visible ? 'flex' : 'none' }, children: children }), !visible && fallback] }));
35
+ }
36
+ return (0, jsx_runtime_1.jsx)(jsx_runtime_1.Fragment, { children: visible ? children : fallback !== null && fallback !== void 0 ? fallback : null });
37
+ }
38
+ /**
39
+ * Renders children only when **all** given conditions match.
40
+ *
41
+ * @example
42
+ * <Show from="md">Sidebar</Show>
43
+ * <Show below="md" fallback={<FullMenu />}><HamburgerMenu /></Show>
44
+ * <Show device="tablet" orientation="landscape">Two-pane layout</Show>
45
+ */
46
+ function Show(props) {
47
+ return render(useMatches(props), props);
48
+ }
49
+ /** The opposite of `<Show>`: hides children when **all** given conditions match. */
50
+ function Hide(props) {
51
+ return render(!useMatches(props), props);
52
+ }
53
+ //# sourceMappingURL=Visibility.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"Visibility.js","sourceRoot":"","sources":["../../src/native/Visibility.tsx"],"names":[],"mappings":";;AAsCA,8CAQC;AAGD,gCA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U,CAAC,MAAM,EAAE,CAAC,CAAC;IACvD,OAAO,iBAAiB,CAAC,CAAC,EAAE,UAAU,CAAC,CAAC;AAC1C,CAAC;AAED,SAAS,MAAM,CAAC,OAAgB,EAAE,EAAE,QAAQ,EAAE,QAAQ,EAAE,IAAI,GAAG,SAAS,EAAmB;IACzF,IAAI,IAAI,KAAK,MAAM,EAAE,CAAC;QACpB,OAAO,CACL,6DACE,uBAAC,mBAAI,IAAC,KAAK,EAAE,EAAE,OAAO,EAAE,OAAO,CAAC,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,MAAM,EAAE,YAAG,QAAQ,GAAQ,EACrE,CAAC,OAAO,IAAI,QAAQ,IACpB,CACJ,CAAC;IACJ,CAAC;IACD,OAAO,2DAAG,OAAO,CAAC,CAAC,CAAC,QAAQ,CAAC,CAAC,CAAC,QAAQ,aAAR,QAAQ,cAAR,QAAQ,GAAI,IAAI,GAAI,CAAC;AACtD,CAAC;AAED;;;;;;;GAOG;AACH,SAAgB,IAAI,CAAC,KAAsB;IACzC,OAAO,MAAM,CAAC,UAAU,CAAC,KAAK,CAAC,EAAE,KAAK,CAAC,CAAC;AAC1C,CAAC;AAED,oFAAoF;AACpF,SAAgB,IAAI,CAAC,KAAsB;IACzC,OAAO,MAAM,CAAC,CAAC,UAAU,CAAC,KAAK,CAAC,EAAE,KAAK,CAAC,CAAC;AAC3C,CAAC"}
@@ -0,0 +1,6 @@
1
+ import type { LayoutInfo, ResponsiveConfig } from '../core/types';
2
+ /** Resolved configuration. Works without a provider (uses defaults). */
3
+ export declare const ConfigContext: import("react").Context<ResponsiveConfig>;
4
+ /** Layout of the nearest `<ResponsiveView>`, or null outside any container. */
5
+ export declare const ContainerContext: import("react").Context<LayoutInfo | null>;
6
+ //# sourceMappingURL=context.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"context.d.ts","sourceRoot":"","sources":["../../src/native/context.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,UAAU,EAAE,gBAAgB,EAAE,MAAM,eAAe,CAAC;AAElE,wEAAwE;AACxE,eAAO,MAAM,aAAa,2CAAkD,CAAC;AAG7E,+EAA+E;AAC/E,eAAO,MAAM,gBAAgB,4CAAyC,CAAC"}
@@ -0,0 +1,12 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.ContainerContext = exports.ConfigContext = void 0;
4
+ const react_1 = require("react");
5
+ const config_1 = require("../core/config");
6
+ /** Resolved configuration. Works without a provider (uses defaults). */
7
+ exports.ConfigContext = (0, react_1.createContext)(config_1.DEFAULT_CONFIG);
8
+ exports.ConfigContext.displayName = 'ResponsiveConfig';
9
+ /** Layout of the nearest `<ResponsiveView>`, or null outside any container. */
10
+ exports.ContainerContext = (0, react_1.createContext)(null);
11
+ exports.ContainerContext.displayName = 'ResponsiveContainer';
12
+ //# sourceMappingURL=context.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"context.js","sourceRoot":"","sources":["../../src/native/context.ts"],"names":[],"mappings":";;;AAAA,iCAAsC;AACtC,2CAAgD;AAGhD,wEAAwE;AAC3D,QAAA,aAAa,GAAG,IAAA,qBAAa,EAAmB,uBAAc,CAAC,CAAC;AAC7E,qBAAa,CAAC,WAAW,GAAG,kBAAkB,CAAC;AAE/C,+EAA+E;AAClE,QAAA,gBAAgB,GAAG,IAAA,qBAAa,EAAoB,IAAI,CAAC,CAAC;AACvE,wBAAgB,CAAC,WAAW,GAAG,qBAAqB,CAAC"}
@@ -0,0 +1,46 @@
1
+ import type { DependencyList } from 'react';
2
+ import type { ImageStyle, TextStyle, ViewStyle } from 'react-native';
3
+ import type { BreakpointKey, ResolvedStyles, ResponsiveInfo, ResponsiveValue } from '../core/types';
4
+ import type { SourceOptions } from './hooks';
5
+ /** A style object where every property may be a responsive value. */
6
+ export type ResponsiveStyle<S> = {
7
+ [K in keyof S]?: ResponsiveValue<S[K]>;
8
+ };
9
+ export type AnyResponsiveStyle = ResponsiveStyle<ViewStyle> | ResponsiveStyle<TextStyle> | ResponsiveStyle<ImageStyle>;
10
+ /** Named responsive styles, the input to `createStyles`. */
11
+ export type ResponsiveNamedStyles<T> = {
12
+ [P in keyof T]: AnyResponsiveStyle;
13
+ };
14
+ type StyleFactory<T> = (r: ResponsiveInfo) => T & ResponsiveNamedStyles<T>;
15
+ /** Resolves every responsive value in a named style sheet for one breakpoint. */
16
+ export declare function resolveStyles<T>(sheet: T, breakpoint: BreakpointKey): ResolvedStyles<T>;
17
+ /**
18
+ * Defines responsive styles once, outside the component, and returns a hook.
19
+ *
20
+ * - Any style property can be a responsive object: `padding: { xs: 12, md: 24 }`.
21
+ * - Pass a function to also use scaling and device info: `(r) => ({ ... r.s(16) ... })`.
22
+ * - Results are memoised. A static object re-computes only when the breakpoint changes.
23
+ *
24
+ * @example
25
+ * const useStyles = createStyles((r) => ({
26
+ * root: { padding: r.s(16), flexDirection: { xs: 'column', md: 'row' } },
27
+ * title: { fontSize: r.fs(20), fontWeight: '700' },
28
+ * }));
29
+ *
30
+ * function Card() {
31
+ * const styles = useStyles();
32
+ * return <View style={styles.root}><Text style={styles.title}>Hi</Text></View>;
33
+ * }
34
+ */
35
+ export declare function createStyles<T extends ResponsiveNamedStyles<T>>(stylesOrFactory: StyleFactory<T> | (T & ResponsiveNamedStyles<T>), options?: SourceOptions): () => ResolvedStyles<T>;
36
+ /**
37
+ * Inline variant of `createStyles` for styles that depend on props or state.
38
+ *
39
+ * @example
40
+ * const styles = useResponsiveStyles((r) => ({
41
+ * box: { width: r.select({ xs: '100%', md: size }) },
42
+ * }), [size]);
43
+ */
44
+ export declare function useResponsiveStyles<T extends ResponsiveNamedStyles<T>>(factory: StyleFactory<T>, deps: DependencyList, options?: SourceOptions): ResolvedStyles<T>;
45
+ export {};
46
+ //# sourceMappingURL=createStyles.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"createStyles.d.ts","sourceRoot":"","sources":["../../src/native/createStyles.ts"],"names":[],"mappings":"AACA,OAAO,KAA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AAS,qBAAqB,CAAC,CAAC,CAAC,EACpE,OAAO,EAAE,YAAY,CAAC,CAAC,CAAC,EACxB,IAAI,EAAE,cAAc,EACpB,OAAO,CAAC,EAAE,aAAa,GACtB,cAAc,CAAC,CAAC,CAAC,CAInB"}
@@ -0,0 +1,68 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.resolveStyles = resolveStyles;
4
+ exports.createStyles = createStyles;
5
+ exports.useResponsiveStyles = useResponsiveStyles;
6
+ const react_1 = require("react");
7
+ const breakpoints_1 = require("../core/breakpoints");
8
+ const hooks_1 = require("./hooks");
9
+ /** Resolves every responsive value in a named style sheet for one breakpoint. */
10
+ function resolveStyles(sheet, breakpoint) {
11
+ const out = {};
12
+ for (const name of Object.keys(sheet)) {
13
+ out[name] = (0, breakpoints_1.resolveDeep)(sheet[name], breakpoint);
14
+ }
15
+ return out;
16
+ }
17
+ /**
18
+ * Defines responsive styles once, outside the component, and returns a hook.
19
+ *
20
+ * - Any style property can be a responsive object: `padding: { xs: 12, md: 24 }`.
21
+ * - Pass a function to also use scaling and device info: `(r) => ({ ... r.s(16) ... })`.
22
+ * - Results are memoised. A static object re-computes only when the breakpoint changes.
23
+ *
24
+ * @example
25
+ * const useStyles = createStyles((r) => ({
26
+ * root: { padding: r.s(16), flexDirection: { xs: 'column', md: 'row' } },
27
+ * title: { fontSize: r.fs(20), fontWeight: '700' },
28
+ * }));
29
+ *
30
+ * function Card() {
31
+ * const styles = useStyles();
32
+ * return <View style={styles.root}><Text style={styles.title}>Hi</Text></View>;
33
+ * }
34
+ */
35
+ function createStyles(stylesOrFactory, options) {
36
+ if (typeof stylesOrFactory === 'function') {
37
+ const factory = stylesOrFactory;
38
+ return function useResponsiveStyleSheet() {
39
+ const r = (0, hooks_1.useResponsive)(options);
40
+ return (0, react_1.useMemo)(() => resolveStyles(factory(r), r.breakpoint), [r]);
41
+ };
42
+ }
43
+ const sheet = stylesOrFactory;
44
+ const cache = new Map();
45
+ return function useStaticResponsiveStyleSheet() {
46
+ const breakpoint = (0, hooks_1.useBreakpoint)(options);
47
+ let resolved = cache.get(breakpoint);
48
+ if (!resolved) {
49
+ resolved = resolveStyles(sheet, breakpoint);
50
+ cache.set(breakpoint, resolved);
51
+ }
52
+ return resolved;
53
+ };
54
+ }
55
+ /**
56
+ * Inline variant of `createStyles` for styles that depend on props or state.
57
+ *
58
+ * @example
59
+ * const styles = useResponsiveStyles((r) => ({
60
+ * box: { width: r.select({ xs: '100%', md: size }) },
61
+ * }), [size]);
62
+ */
63
+ function useResponsiveStyles(factory, deps, options) {
64
+ const r = (0, hooks_1.useResponsive)(options);
65
+ // eslint-disable-next-line react-hooks/exhaustive-deps
66
+ return (0, react_1.useMemo)(() => resolveStyles(factory(r), r.breakpoint), [r, ...deps]);
67
+ }
68
+ //# sourceMappingURL=createStyles.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"createStyles.js","sourceRoot":"","sources":["../../src/native/createStyles.ts"],"names":[],"mappings":";;AA2BA,sCAMC;AAoBD,oCAsBC;AAUD,kDAQC;AA7FD,iCAAgC;AAGhC,qDAAkD;AAOlD,mCAAuD;AAgBvD,iFAAiF;AACjF,SAAgB,aAAa,CAAI,KAAQ,EAAE,UAAyB;IAClE,MAAM,GAAG,GAA4B,EAAE,CAAC;IACxC,KAAK,MAAM,IAAI,IAAI,MAAM,CAAC,IAAI,CAAC,KAAe,CAAC,EAAE,CAAC;QAChD,GAAG,CAAC,IAAI,CAAC,GAAG,IAAA,yBAAW,EAAE,KAAiC,CAAC,IAAI,CAAC,EAAE,UAAU,CAAC,CAAC;IAChF,CAAC;IACD,OAAO,GAAwB,CAAC;AAClC,CAAC;AAED;;;;;;;;;;;;;;;;;GAiBG;AACH,SAAgB,YAAY,CAC1B,eAAiE,EACjE,OAAuB;IAEvB,IAAI,OAAO,eAAe,KAAK,UAAU,EAAE,CAAC;QAC1C,MAAM,OAAO,GAAG,eAAe,CAAC;QAChC,OAAO,SAAS,uBA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