Skip to content

Commit b4485f1

Browse files
committed
added documentation for prop
1 parent 1fa751c commit b4485f1

File tree

3 files changed

+26
-11
lines changed

3 files changed

+26
-11
lines changed

README.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -383,6 +383,13 @@ A lower value results in more frequent updates, offering smoother visual updates
383383
<td><code>false</code></td>
384384
<td> Defines the base unit height for items within the grid. This value serves as a foundational measure to determine the actual height of each grid item. The item's final height is calculated by multiplying this base unit height (<code>itemUnitHeight</code>) by the item's heightRatio, allowing for proportional scaling of items based on their content or design requirements. While <code>widthRatio</code> affects the item's width in relation to the column width, <code>itemUnitHeight</code> and <code>heightRatio</code> together define the item's vertical dimension, enabling dynamic grid layouts that adapt seamlessly to varying content sizes.</td>
385385
</tr>
386+
<tr>
387+
<td><code>direction</code></td>
388+
<td><code>string</code></td>
389+
<td><code>ltr</code></td>
390+
<td><code>false</code></td>
391+
<td> Determines the direction for arranging grid items in the layout: left-to-right (ltr) or right-to-left (rtl). </td>
392+
</tr>
386393
<tr>
387394
<td><code>virtualization</code></td>
388395
<td><code>Boolean</code></td>

src/responsive-grid/index.tsx

Lines changed: 15 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,6 @@ export const ResponsiveGrid: React.FC<ResponsiveGridProps> = ({
2828
FooterComponent = null,
2929
direction = 'ltr',
3030
}) => {
31-
const start = direction === 'ltr' ? 'left' : 'right';
3231
const [visibleItems, setVisibleItems] = useState<TileItem[]>([]);
3332

3433
const [containerSize, setContainerSize] = useState({ width: 0, height: 0 });
@@ -122,6 +121,20 @@ export const ResponsiveGrid: React.FC<ResponsiveGridProps> = ({
122121
onEndReachedCalled.current = false;
123122
}, [gridItems, containerSize, virtualization]);
124123

124+
const getItemPositionStyle = (item: TileItem) => {
125+
const baseStyle = {
126+
position: 'absolute' as const,
127+
top: item.top,
128+
width: item.width,
129+
height: item.height,
130+
};
131+
132+
return {
133+
...baseStyle,
134+
...(direction === 'rtl' ? { right: item.left } : { left: item.left }),
135+
};
136+
};
137+
125138
return (
126139
<View
127140
style={[{ flexGrow: 1 }, style]}
@@ -156,16 +169,7 @@ export const ResponsiveGrid: React.FC<ResponsiveGridProps> = ({
156169
{renderedItems.map((item, index) => (
157170
<View
158171
key={keyExtractor(item, index)}
159-
style={[
160-
{
161-
position: 'absolute',
162-
top: item.top,
163-
[start]: item.left,
164-
width: item.width,
165-
height: item.height,
166-
},
167-
itemContainerStyle,
168-
]}
172+
style={[getItemPositionStyle(item), itemContainerStyle]}
169173
>
170174
{renderItem({ item, index })}
171175
</View>

src/responsive-grid/types.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,10 @@ export interface ResponsiveGridProps {
6969
| null
7070
| undefined;
7171

72+
/**
73+
* Determines the direction for arranging grid items in the layout: left-to-right (ltr) or right-to-left (rtl).
74+
* @default ltr
75+
*/
7276
direction?: 'rtl' | 'ltr';
7377
}
7478

0 commit comments

Comments
 (0)