@flipova/foundation 2.3.0 → 2.4.0-beta.1

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 (98) hide show
  1. package/README.md +157 -156
  2. package/components/ui/accordion/ANIMATION_CUSTOMIZATION.md +16 -7
  3. package/components/ui/accordion/AccordionAnimatedHeight.tsx +3 -15
  4. package/components/ui/accordion/AccordionAnimatedIcon.tsx +2 -9
  5. package/components/ui/accordion/AnimatedHeight.tsx +3 -15
  6. package/components/ui/accordion/AnimatedIcon.tsx +2 -9
  7. package/components/ui/accordion/MIGRATION_SUMMARY.md +22 -11
  8. package/components/ui/accordion/USAGE_EXAMPLE.tsx +10 -25
  9. package/components/ui/accordion/index.tsx +71 -139
  10. package/components/ui/actionsheet/index.tsx +63 -105
  11. package/components/ui/alert/index.tsx +20 -50
  12. package/components/ui/alert-dialog/index.tsx +23 -48
  13. package/components/ui/avatar/index.tsx +32 -68
  14. package/components/ui/badge/index.tsx +18 -49
  15. package/components/ui/bottomsheet/index.tsx +20 -52
  16. package/components/ui/box/index.tsx +4 -9
  17. package/components/ui/box/index.web.tsx +3 -9
  18. package/components/ui/button/index.tsx +73 -109
  19. package/components/ui/calendar/creator.tsx +69 -30
  20. package/components/ui/calendar/index.tsx +81 -159
  21. package/components/ui/calendar/styles.tsx +10 -10
  22. package/components/ui/card/index.tsx +8 -9
  23. package/components/ui/card/index.web.tsx +4 -10
  24. package/components/ui/center/index.tsx +6 -11
  25. package/components/ui/center/index.web.tsx +3 -9
  26. package/components/ui/checkbox/index.tsx +46 -107
  27. package/components/ui/date-time-picker/creator.tsx +14 -1
  28. package/components/ui/date-time-picker/index.tsx +107 -156
  29. package/components/ui/date-time-picker/index.web.tsx +11 -33
  30. package/components/ui/date-time-picker/styles.tsx +5 -5
  31. package/components/ui/divider/index.tsx +5 -6
  32. package/components/ui/drawer/index.tsx +108 -128
  33. package/components/ui/fab/index.tsx +25 -68
  34. package/components/ui/flat-list/index.tsx +11 -8
  35. package/components/ui/form-control/index.tsx +49 -90
  36. package/components/ui/gluestack-ui-provider/index.tsx +4 -18
  37. package/components/ui/gluestack-ui-provider/index.web.tsx +10 -11
  38. package/components/ui/gluestack-ui-provider/script.ts +1 -3
  39. package/components/ui/gluestack-ui-provider/theme-context.ts +2 -2
  40. package/components/ui/gluestack-ui-provider/useGluestackColors.ts +2 -6
  41. package/components/ui/grid/index.tsx +128 -165
  42. package/components/ui/grid/index.web.tsx +17 -19
  43. package/components/ui/grid/styles.tsx +1 -3
  44. package/components/ui/heading/index.tsx +146 -169
  45. package/components/ui/heading/index.web.tsx +7 -28
  46. package/components/ui/heading/styles.tsx +5 -5
  47. package/components/ui/hstack/index.tsx +16 -15
  48. package/components/ui/hstack/index.web.tsx +17 -17
  49. package/components/ui/hstack/styles.tsx +5 -5
  50. package/components/ui/icon/index.tsx +95 -486
  51. package/components/ui/icon/index.web.tsx +79 -439
  52. package/components/ui/image/index.tsx +13 -18
  53. package/components/ui/image-viewer/index.tsx +149 -221
  54. package/components/ui/image-viewer/index.web.tsx +88 -113
  55. package/components/ui/input/index.tsx +20 -33
  56. package/components/ui/link/index.tsx +16 -22
  57. package/components/ui/liquid-glass/index.tsx +19 -25
  58. package/components/ui/menu/index.tsx +44 -66
  59. package/components/ui/modal/index.tsx +70 -91
  60. package/components/ui/popover/index.tsx +102 -121
  61. package/components/ui/portal/index.tsx +5 -6
  62. package/components/ui/pressable/index.tsx +5 -9
  63. package/components/ui/progress/index.tsx +4 -11
  64. package/components/ui/radio/index.tsx +47 -83
  65. package/components/ui/select/index.tsx +38 -59
  66. package/components/ui/select/select-actionsheet.tsx +61 -108
  67. package/components/ui/skeleton/index.tsx +22 -43
  68. package/components/ui/skeleton/index.web.tsx +63 -75
  69. package/components/ui/slider/index.tsx +36 -56
  70. package/components/ui/spinner/index.tsx +1 -10
  71. package/components/ui/switch/index.tsx +6 -13
  72. package/components/ui/table/index.tsx +39 -102
  73. package/components/ui/table/index.web.tsx +41 -79
  74. package/components/ui/tabs/TabsAnimatedIndicator.tsx +10 -38
  75. package/components/ui/tabs/creator.tsx +32 -24
  76. package/components/ui/tabs/index.tsx +253 -309
  77. package/components/ui/text/index.tsx +23 -37
  78. package/components/ui/text/index.web.tsx +33 -35
  79. package/components/ui/text/styles.tsx +5 -5
  80. package/components/ui/textarea/index.tsx +24 -38
  81. package/components/ui/toast/index.tsx +47 -52
  82. package/components/ui/tooltip/index.tsx +12 -28
  83. package/components/ui/vstack/index.tsx +17 -17
  84. package/components/ui/vstack/index.web.tsx +17 -17
  85. package/components/ui/vstack/styles.tsx +5 -5
  86. package/design/tools/design.js +15 -12
  87. package/design/tools/npm.js +4 -3
  88. package/dist/{chunk-B277QSR5.mjs → chunk-2R66P5X5.mjs} +1816 -3124
  89. package/dist/chunk-2R66P5X5.mjs.map +1 -0
  90. package/dist/{chunk-GD37RFBR.js → chunk-LCTFQJZM.js} +1816 -3124
  91. package/dist/chunk-LCTFQJZM.js.map +1 -0
  92. package/dist/index.js +294 -294
  93. package/dist/index.mjs +1 -1
  94. package/dist/ui/index.js +294 -294
  95. package/dist/ui/index.mjs +1 -1
  96. package/package.json +12 -7
  97. package/dist/chunk-B277QSR5.mjs.map +0 -1
  98. package/dist/chunk-GD37RFBR.js.map +0 -1
@@ -10,13 +10,7 @@ import {
10
10
  } from './useGluestackColors';
11
11
  import { ThemeContext, MountedThemeContext, resolveThemeId } from './theme-context';
12
12
 
13
- export {
14
- ThemeContext,
15
- MountedThemeContext,
16
- useMountedColors,
17
- useMountedTheme,
18
- resolveThemeId,
19
- } from './theme-context';
13
+ export { ThemeContext, MountedThemeContext, useMountedColors, useMountedTheme, resolveThemeId } from './theme-context';
20
14
 
21
15
  export type ModeType = 'light' | 'dark' | 'system';
22
16
 
@@ -67,11 +61,7 @@ export function createGluestackUIProvider(theme: GluestackTheme) {
67
61
  const variantMap = theme.variants;
68
62
  const themeIds = Object.keys(vars);
69
63
 
70
- return function ThemedProvider({
71
- mode = 'light',
72
- variant,
73
- ...props
74
- }: GluestackUIProviderProps) {
64
+ return function ThemedProvider({ mode = 'light', variant, ...props }: GluestackUIProviderProps) {
75
65
  const { colorScheme, setColorScheme } = useColorScheme();
76
66
 
77
67
  useEffect(() => {
@@ -82,13 +72,9 @@ export function createGluestackUIProvider(theme: GluestackTheme) {
82
72
  // Nativewind only reports light/dark, so `system` resolves through it while a
83
73
  // named mode is taken as-is; either way the VARIANT picks the pair. Falling
84
74
  // back to the mode keeps a theme set without variants working untouched.
85
- const resolvedMode =
86
- mode === 'system' ? colorScheme ?? 'light' : mode;
75
+ const resolvedMode = mode === 'system' ? (colorScheme ?? 'light') : mode;
87
76
  const themeId = resolveThemeId(variantMap, variant, resolvedMode);
88
- const mountedTheme = React.useMemo(
89
- () => ({ themeId, themeIds }),
90
- [themeId, themeIds]
91
- );
77
+ const mountedTheme = React.useMemo(() => ({ themeId, themeIds }), [themeId, themeIds]);
92
78
 
93
79
  return (
94
80
  <View
@@ -20,8 +20,7 @@ const createStyle = (styleTagId: string) => {
20
20
  return style;
21
21
  };
22
22
 
23
- export const useSafeLayoutEffect =
24
- typeof window !== 'undefined' ? useLayoutEffect : useEffect;
23
+ export const useSafeLayoutEffect = typeof window !== 'undefined' ? useLayoutEffect : useEffect;
25
24
 
26
25
  export function GluestackUIProvider({
27
26
  mode = 'light',
@@ -41,15 +40,12 @@ export function GluestackUIProvider({
41
40
  let cssVariablesWithMode = ``;
42
41
  let variantCss = ``;
43
42
  themeIds.forEach((configKey) => {
44
- const cssVariables = Object.keys(
45
- config[configKey as keyof typeof config]
46
- ).reduce((acc: string, curr: string) => {
43
+ const cssVariables = Object.keys(config[configKey as keyof typeof config]).reduce((acc: string, curr: string) => {
47
44
  acc += `${curr}:${config[configKey as keyof typeof config][curr]}; `;
48
45
  return acc;
49
46
  }, '');
50
47
  if (isDefaultId(configKey)) {
51
- cssVariablesWithMode +=
52
- configKey === 'dark' ? `\n .dark {\n ` : `\n:root {\n`;
48
+ cssVariablesWithMode += configKey === 'dark' ? `\n .dark {\n ` : `\n:root {\n`;
53
49
  cssVariablesWithMode += `${cssVariables} \n}`;
54
50
  } else {
55
51
  variantCss += `\n[data-theme='${configKey}'] {\n${cssVariables} \n}`;
@@ -59,10 +55,13 @@ export function GluestackUIProvider({
59
55
 
60
56
  setFlushStyles(cssVariablesWithMode);
61
57
 
62
- const handleMediaQuery = React.useCallback((e: MediaQueryListEvent) => {
63
- const resolved = e.matches ? 'dark' : 'light';
64
- script(resolved, resolveThemeId(variants, variant, resolved), resolved);
65
- }, [variant]);
58
+ const handleMediaQuery = React.useCallback(
59
+ (e: MediaQueryListEvent) => {
60
+ const resolved = e.matches ? 'dark' : 'light';
61
+ script(resolved, resolveThemeId(variants, variant, resolved), resolved);
62
+ },
63
+ [variant],
64
+ );
66
65
 
67
66
  // The script keeps the light/dark class AND the variant class/attribute in step.
68
67
  const activeMode = mode === 'system' ? 'light' : mode;
@@ -2,9 +2,7 @@ export const script = (mode: string, themeId: string, modeClass: string) => {
2
2
  const documentElement = document.documentElement;
3
3
 
4
4
  function getSystemColorMode() {
5
- return window.matchMedia('(prefers-color-scheme: dark)').matches
6
- ? 'dark'
7
- : 'light';
5
+ return window.matchMedia('(prefers-color-scheme: dark)').matches ? 'dark' : 'light';
8
6
  }
9
7
 
10
8
  try {
@@ -44,8 +44,8 @@ export const useMountedTheme = (): MountedTheme | null => useContext(MountedThem
44
44
  export function resolveThemeId(
45
45
  variants: Record<string, Record<string, string>> | undefined,
46
46
  variant: string | undefined,
47
- mode: string
47
+ mode: string,
48
48
  ): string {
49
49
  const mapped = variant ? variants?.[variant]?.[mode] : undefined;
50
50
  return mapped ?? mode;
51
- }
51
+ }
@@ -24,8 +24,7 @@ function rgbToHex(rgbString: string): string {
24
24
  return isNaN(num) ? 0 : num;
25
25
  });
26
26
 
27
- const toHex = (n: number) =>
28
- Math.max(0, Math.min(255, n)).toString(16).padStart(2, '0');
27
+ const toHex = (n: number) => Math.max(0, Math.min(255, n)).toString(16).padStart(2, '0');
29
28
  return `#${toHex(r)}${toHex(g)}${toHex(b)}`;
30
29
  }
31
30
 
@@ -52,10 +51,7 @@ export function useGluestackColors(): Record<string, string> {
52
51
  // the active id is only known at runtime.
53
52
  const palettes = theme as Record<string, Record<string, string>>;
54
53
  const palette =
55
- palettes[mounted?.themeId ?? ''] ??
56
- palettes[colorScheme || 'light'] ??
57
- palettes[mounted?.themeIds[0] ?? ''] ??
58
- {};
54
+ palettes[mounted?.themeId ?? ''] ?? palettes[colorScheme || 'light'] ?? palettes[mounted?.themeIds[0] ?? ''] ?? {};
59
55
 
60
56
  // Dynamically convert all CSS variables to camelCase hex colors
61
57
  const result: Record<string, string> = {};
@@ -1,18 +1,9 @@
1
- import React, {
2
- useState,
3
- createContext,
4
- useContext,
5
- useMemo,
6
- forwardRef,
7
- } from 'react';
1
+ import React, { useState, createContext, useContext, useMemo, forwardRef } from 'react';
8
2
  import type { VariantProps } from '@gluestack-ui/utils/nativewind-utils';
9
3
  import { View, Dimensions, Platform, ViewProps } from 'react-native';
10
4
  import { gridStyle, gridItemStyle } from './styles';
11
5
  import { cssInterop } from 'nativewind';
12
- import {
13
- useBreakpointValue,
14
- getBreakPointValue,
15
- } from '@gluestack-ui/utils/hooks';
6
+ import { useBreakpointValue, getBreakPointValue } from '@gluestack-ui/utils/hooks';
16
7
  const { width: DEVICE_WIDTH } = Dimensions.get('window');
17
8
  const GridContext = createContext<any>({});
18
9
  function arrangeChildrenIntoRows({
@@ -40,9 +31,7 @@ function arrangeChildrenIntoRows({
40
31
  // if current row is not full, add colSpan to current row
41
32
  currentRowTotalColSpan += colSpan;
42
33
  }
43
- rowItemsCount[currentRow] = rowItemsCount[currentRow]
44
- ? [...rowItemsCount[currentRow], i]
45
- : [i];
34
+ rowItemsCount[currentRow] = rowItemsCount[currentRow] ? [...rowItemsCount[currentRow], i] : [i];
46
35
  }
47
36
  return rowItemsCount;
48
37
  }
@@ -64,11 +53,7 @@ function generateResponsiveNumColumns({ gridClass }: { gridClass: string }) {
64
53
  });
65
54
  return result;
66
55
  }
67
- function generateResponsiveColSpans({
68
- gridItemClassName,
69
- }: {
70
- gridItemClassName: string;
71
- }) {
56
+ function generateResponsiveColSpans({ gridItemClassName }: { gridItemClassName: string }) {
72
57
  const gridClassNamePattern = /\b(?:\w+:)?col-span-?\d+\b/g;
73
58
  const colSpan: any = gridItemClassName?.match(gridClassNamePattern);
74
59
  if (!colSpan) {
@@ -104,83 +89,79 @@ type IGridProps = ViewProps &
104
89
  className: string;
105
90
  };
106
91
  };
107
- const Grid = forwardRef<React.ComponentRef<typeof View>, IGridProps>(
108
- function Grid({ className, _extra, children, ...props }, ref) {
109
- const [calculatedWidth, setCalculatedWidth] = useState<number | null>(null);
110
- const gridClass = _extra?.className;
111
- const obj = generateResponsiveNumColumns({ gridClass });
112
- const responsiveNumColumns: any = useBreakpointValue(obj);
113
- const itemsPerRow = useMemo(() => {
114
- // get the colSpan of each child
115
- const colSpanArr = React.Children.map(children, (child: any) => {
116
- const gridItemClassName = child?.props?._extra?.className;
117
- const colSpan2 = getBreakPointValue(
118
- generateResponsiveColSpans({ gridItemClassName }),
119
- DEVICE_WIDTH
120
- );
121
- const colSpan = colSpan2 ? colSpan2 : 1;
122
- if (colSpan > responsiveNumColumns) {
123
- return responsiveNumColumns;
124
- }
125
- return colSpan;
126
- });
127
- const childrenArray = React.Children.toArray(children);
128
- const rowItemsCount = arrangeChildrenIntoRows({
129
- childrenArray,
130
- colSpanArr,
131
- numColumns: responsiveNumColumns,
132
- });
133
- return rowItemsCount;
134
- }, [responsiveNumColumns, children]);
135
- const childrenWithProps = React.Children.map(children, (child, index) => {
136
- if (React.isValidElement(child)) {
137
- return React.cloneElement(child, { key: index, index: index } as any);
92
+ const Grid = forwardRef<React.ComponentRef<typeof View>, IGridProps>(function Grid(
93
+ { className, _extra, children, ...props },
94
+ ref,
95
+ ) {
96
+ const [calculatedWidth, setCalculatedWidth] = useState<number | null>(null);
97
+ const gridClass = _extra?.className;
98
+ const obj = generateResponsiveNumColumns({ gridClass });
99
+ const responsiveNumColumns: any = useBreakpointValue(obj);
100
+ const itemsPerRow = useMemo(() => {
101
+ // get the colSpan of each child
102
+ const colSpanArr = React.Children.map(children, (child: any) => {
103
+ const gridItemClassName = child?.props?._extra?.className;
104
+ const colSpan2 = getBreakPointValue(generateResponsiveColSpans({ gridItemClassName }), DEVICE_WIDTH);
105
+ const colSpan = colSpan2 ? colSpan2 : 1;
106
+ if (colSpan > responsiveNumColumns) {
107
+ return responsiveNumColumns;
138
108
  }
139
- return child;
109
+ return colSpan;
140
110
  });
141
- const gridClassMerged = `${Platform.select({
142
- web: gridClass ?? '',
143
- })}`;
144
- const contextValue = useMemo(() => {
145
- return {
146
- calculatedWidth,
147
- numColumns: responsiveNumColumns,
148
- itemsPerRow,
149
- flexDirection: props?.flexDirection || 'row',
150
- gap: props?.gap || 0,
151
- columnGap: props?.columnGap || 0,
152
- };
153
- }, [calculatedWidth, itemsPerRow, responsiveNumColumns, props]);
154
- const borderLeftWidth = props?.borderLeftWidth || props?.borderWidth || 0;
155
- const borderRightWidth = props?.borderRightWidth || props?.borderWidth || 0;
156
- const borderWidthToSubtract = borderLeftWidth + borderRightWidth;
157
- return (
158
- <GridContext.Provider value={contextValue}>
159
- <View
160
- ref={ref}
161
- className={gridStyle({
162
- class: className + ' ' + gridClassMerged,
163
- })}
164
- onLayout={(event) => {
165
- const paddingLeftToSubtract =
166
- props?.paddingStart || props?.paddingLeft || props?.padding || 0;
167
- const paddingRightToSubtract =
168
- props?.paddingEnd || props?.paddingRight || props?.padding || 0;
169
- const gridWidth =
170
- Math.floor(event.nativeEvent.layout.width) -
171
- paddingLeftToSubtract -
172
- paddingRightToSubtract -
173
- borderWidthToSubtract;
174
- setCalculatedWidth(gridWidth);
175
- }}
176
- {...props}
177
- >
178
- {calculatedWidth && childrenWithProps}
179
- </View>
180
- </GridContext.Provider>
181
- );
182
- }
183
- );
111
+ const childrenArray = React.Children.toArray(children);
112
+ const rowItemsCount = arrangeChildrenIntoRows({
113
+ childrenArray,
114
+ colSpanArr,
115
+ numColumns: responsiveNumColumns,
116
+ });
117
+ return rowItemsCount;
118
+ }, [responsiveNumColumns, children]);
119
+ const childrenWithProps = React.Children.map(children, (child, index) => {
120
+ if (React.isValidElement(child)) {
121
+ return React.cloneElement(child, { key: index, index: index } as any);
122
+ }
123
+ return child;
124
+ });
125
+ const gridClassMerged = `${Platform.select({
126
+ web: gridClass ?? '',
127
+ })}`;
128
+ const contextValue = useMemo(() => {
129
+ return {
130
+ calculatedWidth,
131
+ numColumns: responsiveNumColumns,
132
+ itemsPerRow,
133
+ flexDirection: props?.flexDirection || 'row',
134
+ gap: props?.gap || 0,
135
+ columnGap: props?.columnGap || 0,
136
+ };
137
+ }, [calculatedWidth, itemsPerRow, responsiveNumColumns, props]);
138
+ const borderLeftWidth = props?.borderLeftWidth || props?.borderWidth || 0;
139
+ const borderRightWidth = props?.borderRightWidth || props?.borderWidth || 0;
140
+ const borderWidthToSubtract = borderLeftWidth + borderRightWidth;
141
+ return (
142
+ <GridContext.Provider value={contextValue}>
143
+ <View
144
+ ref={ref}
145
+ className={gridStyle({
146
+ class: className + ' ' + gridClassMerged,
147
+ })}
148
+ onLayout={(event) => {
149
+ const paddingLeftToSubtract = props?.paddingStart || props?.paddingLeft || props?.padding || 0;
150
+ const paddingRightToSubtract = props?.paddingEnd || props?.paddingRight || props?.padding || 0;
151
+ const gridWidth =
152
+ Math.floor(event.nativeEvent.layout.width) -
153
+ paddingLeftToSubtract -
154
+ paddingRightToSubtract -
155
+ borderWidthToSubtract;
156
+ setCalculatedWidth(gridWidth);
157
+ }}
158
+ {...props}
159
+ >
160
+ {calculatedWidth && childrenWithProps}
161
+ </View>
162
+ </GridContext.Provider>
163
+ );
164
+ });
184
165
  cssInterop(Grid, {
185
166
  className: {
186
167
  target: 'style',
@@ -207,77 +188,59 @@ type IGridItemProps = ViewProps &
207
188
  className: string;
208
189
  };
209
190
  };
210
- const GridItem = forwardRef<React.ComponentRef<typeof View>, IGridItemProps>(
211
- function GridItem({ className, _extra, ...props }, ref) {
212
- const {
213
- calculatedWidth,
214
- numColumns,
215
- itemsPerRow,
216
- flexDirection,
217
- gap,
218
- columnGap,
219
- } = useContext(GridContext);
220
- const gridItemClass = _extra?.className;
221
- const responsiveColSpan = (useBreakpointValue(
222
- generateResponsiveColSpans({ gridItemClassName: gridItemClass })
223
- ) ?? 1) as number;
224
- const flexBasisValue = useMemo(() => {
225
- if (!calculatedWidth || !numColumns || responsiveColSpan <= 0) {
226
- return 'auto';
227
- }
228
- if (flexDirection?.includes('column')) {
229
- return 'auto';
230
- }
231
- // Find which row this item is in
232
- const row = Object.keys(itemsPerRow).find((key) => {
233
- return itemsPerRow[key].includes(props?.index);
234
- });
235
- if (!row) {
236
- return 'auto';
237
- }
238
- const rowColsCount = itemsPerRow[row]?.length || 1;
239
- const space = columnGap || gap || 0;
240
- // Calculate available width accounting for gaps
241
- const totalGapWidth = space * (rowColsCount - 1);
242
- const availableWidth = calculatedWidth - totalGapWidth;
243
- // Calculate the width for this item based on its column span
244
- const itemWidth = (availableWidth * responsiveColSpan) / numColumns;
245
- // Return the width directly instead of percentage for better native compatibility
246
- return Math.max(0, Math.floor(itemWidth));
247
- }, [
248
- calculatedWidth,
249
- responsiveColSpan,
250
- numColumns,
251
- columnGap,
252
- gap,
253
- flexDirection,
254
- itemsPerRow,
255
- props?.index,
256
- ]);
257
- return (
258
- <View
259
- ref={ref}
260
- // @ts-expect-error : internal implementation for r-19/react-native-web
261
- gridItemClass={gridItemClass}
262
- className={gridItemStyle({
263
- class: className,
264
- })}
265
- {...props}
266
- style={[
267
- {
268
- width:
269
- typeof flexBasisValue === 'number' ? flexBasisValue : undefined,
270
- flexBasis:
271
- typeof flexBasisValue === 'string' ? flexBasisValue : undefined,
272
- flexShrink: 0,
273
- flexGrow: 0,
274
- },
275
- props.style,
276
- ]}
277
- />
278
- );
279
- }
280
- );
191
+ const GridItem = forwardRef<React.ComponentRef<typeof View>, IGridItemProps>(function GridItem(
192
+ { className, _extra, ...props },
193
+ ref,
194
+ ) {
195
+ const { calculatedWidth, numColumns, itemsPerRow, flexDirection, gap, columnGap } = useContext(GridContext);
196
+ const gridItemClass = _extra?.className;
197
+ const responsiveColSpan = (useBreakpointValue(generateResponsiveColSpans({ gridItemClassName: gridItemClass })) ??
198
+ 1) as number;
199
+ const flexBasisValue = useMemo(() => {
200
+ if (!calculatedWidth || !numColumns || responsiveColSpan <= 0) {
201
+ return 'auto';
202
+ }
203
+ if (flexDirection?.includes('column')) {
204
+ return 'auto';
205
+ }
206
+ // Find which row this item is in
207
+ const row = Object.keys(itemsPerRow).find((key) => {
208
+ return itemsPerRow[key].includes(props?.index);
209
+ });
210
+ if (!row) {
211
+ return 'auto';
212
+ }
213
+ const rowColsCount = itemsPerRow[row]?.length || 1;
214
+ const space = columnGap || gap || 0;
215
+ // Calculate available width accounting for gaps
216
+ const totalGapWidth = space * (rowColsCount - 1);
217
+ const availableWidth = calculatedWidth - totalGapWidth;
218
+ // Calculate the width for this item based on its column span
219
+ const itemWidth = (availableWidth * responsiveColSpan) / numColumns;
220
+ // Return the width directly instead of percentage for better native compatibility
221
+ return Math.max(0, Math.floor(itemWidth));
222
+ }, [calculatedWidth, responsiveColSpan, numColumns, columnGap, gap, flexDirection, itemsPerRow, props?.index]);
223
+ return (
224
+ <View
225
+ ref={ref}
226
+ // @ts-expect-error : internal implementation for r-19/react-native-web
227
+ gridItemClass={gridItemClass}
228
+ className={gridItemStyle({
229
+ class: className,
230
+ })}
231
+ {...props}
232
+ style={[
233
+ {
234
+ width: typeof flexBasisValue === 'number' ? flexBasisValue : undefined,
235
+ flexBasis: typeof flexBasisValue === 'string' ? flexBasisValue : undefined,
236
+ flexShrink: 0,
237
+ flexGrow: 0,
238
+ },
239
+ props.style,
240
+ ]}
241
+ />
242
+ );
243
+ });
281
244
  Grid.displayName = 'Grid';
282
245
  GridItem.displayName = 'GridItem';
283
246
  export { Grid, GridItem };
@@ -19,10 +19,7 @@ type IGridProps = React.ComponentPropsWithoutRef<'div'> &
19
19
  };
20
20
  };
21
21
 
22
- const Grid = React.forwardRef<HTMLDivElement, IGridProps>(function Grid(
23
- { className, _extra, ...props },
24
- ref
25
- ) {
22
+ const Grid = React.forwardRef<HTMLDivElement, IGridProps>(function Grid({ className, _extra, ...props }, ref) {
26
23
  const gridClass = _extra?.className;
27
24
  const finalGridClass = gridClass ?? '';
28
25
  return (
@@ -43,22 +40,23 @@ type IGridItemProps = React.ComponentPropsWithoutRef<'div'> &
43
40
  className: string;
44
41
  };
45
42
  };
46
- const GridItem = React.forwardRef<HTMLDivElement, IGridItemProps>(
47
- function GridItem({ className, _extra, ...props }, ref) {
48
- const gridItemClass = _extra?.className;
43
+ const GridItem = React.forwardRef<HTMLDivElement, IGridItemProps>(function GridItem(
44
+ { className, _extra, ...props },
45
+ ref,
46
+ ) {
47
+ const gridItemClass = _extra?.className;
49
48
 
50
- const finalGridItemClass = gridItemClass ?? '';
51
- return (
52
- <div
53
- ref={ref}
54
- className={gridItemStyle({
55
- class: className + ' ' + finalGridItemClass,
56
- })}
57
- {...props}
58
- />
59
- );
60
- }
61
- );
49
+ const finalGridItemClass = gridItemClass ?? '';
50
+ return (
51
+ <div
52
+ ref={ref}
53
+ className={gridItemStyle({
54
+ class: className + ' ' + finalGridItemClass,
55
+ })}
56
+ {...props}
57
+ />
58
+ );
59
+ });
62
60
 
63
61
  Grid.displayName = 'Grid';
64
62
  GridItem.displayName = 'GridItem';
@@ -1,9 +1,7 @@
1
1
  import { tva } from '@gluestack-ui/utils/nativewind-utils';
2
2
  import { isWeb } from '@gluestack-ui/utils/nativewind-utils';
3
3
 
4
- const gridBaseStyle = isWeb
5
- ? 'grid grid-cols-12'
6
- : 'box-border flex-row flex-wrap justify-start';
4
+ const gridBaseStyle = isWeb ? 'grid grid-cols-12' : 'box-border flex-row flex-wrap justify-start';
7
5
  const gridItemBaseStyle = isWeb ? 'w-auto col-span-1' : '';
8
6
 
9
7
  export const gridStyle = tva({