Skip to content

Commit 0757a6f

Browse files
authored
Added bounces prop & fixed issue with ResponsiveGrid component horizontal padding (#76)
* added bounce prop & fixed ResponsiveGrid padding bug * fix lint issues * fix CL failing
1 parent d8b91cc commit 0757a6f

File tree

9 files changed

+3403
-3632
lines changed

9 files changed

+3403
-3632
lines changed

.github/actions/setup/action.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,5 +23,5 @@ runs:
2323
2424
- name: Install dependencies
2525
if: steps.yarn-cache.outputs.cache-hit != 'true'
26-
run: yarn install --immutable
26+
run: yarn install
2727
shell: bash

.github/workflows/ci.yml

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,6 @@ jobs:
1717
- name: Setup
1818
uses: ./.github/actions/setup
1919

20-
- name: Install dependencies
21-
run: yarn install
22-
2320
- name: Lint files
2421
run: yarn lint
2522

@@ -35,9 +32,6 @@ jobs:
3532
- name: Setup
3633
uses: ./.github/actions/setup
3734

38-
- name: Install dependencies
39-
run: yarn install
40-
4135
- name: Run unit tests
4236
run: yarn test --maxWorkers=2 --coverage
4337

@@ -50,9 +44,6 @@ jobs:
5044
- name: Setup
5145
uses: ./.github/actions/setup
5246

53-
- name: Install dependencies
54-
run: yarn install
55-
5647
- name: Build package
5748
run: yarn prepare
5849

@@ -65,8 +56,5 @@ jobs:
6556
- name: Setup
6657
uses: ./.github/actions/setup
6758

68-
- name: Install dependencies
69-
run: yarn install
70-
7159
- name: Build example for Web
7260
run: yarn example expo export:web

README.md

Lines changed: 106 additions & 61 deletions
Original file line numberDiff line numberDiff line change
@@ -4,14 +4,12 @@
44
[![npm package](https://img.shields.io/npm/v/react-native-flexible-grid.svg?style=flat-square)](https://www.npmjs.org/package/react-native-flexible-grid)
55
[![npm downloads](https://img.shields.io/npm/dt/react-native-flexible-grid.svg)]()
66

7-
87
`React Native Flexible Grid` is an advanced grid layout system inspired by CSS Grid, designed to facilitate responsive, customizable, and dynamic grid layouts in React Native applications. It supports both responsive and fixed layouts, enabling the creation of intricate designs with minimal effort.
98

109
<p align="center">
1110
<img src="https://raw.githubusercontent.com/iNerdStack/react-native-flexible-grid/main/example/assets/images/grid-layout.jpeg" width="500" height="500" alt="React Native Flexible Grid" >
1211
</p>
1312

14-
1513
## 🌟 Features
1614

1715
- **Responsive Design**: Adapts fluidly to both screen and container sizes, ensuring your content looks perfect on any device. This guarantees that your grid will seamlessly accommodate different resolutions and orientations, making it ideal for responsive mobile applications.
@@ -37,7 +35,6 @@
3735
</tr>
3836
</table>
3937

40-
4138
<table>
4239
<tr>
4340
<td><img src="https://raw.githubusercontent.com/iNerdStack/react-native-flexible-grid/main/example/assets/gifs/gridboard-overflow-example.gif" alt="Grid Board Example" width="403px" height="100%" /></td>
@@ -47,50 +44,67 @@
4744
</tr>
4845
</table>
4946

50-
51-
5247
## 📦 Installation
5348

5449
```sh
5550
npm install react-native-flexible-grid
5651
```
52+
5753
or
54+
5855
```sh
5956
yarn add react-native-flexible-grid
6057
```
6158

6259
## 💡 Usage
6360

6461
### 1. Flex Grid
65-
`FlexGrid` is designed for creating highly flexible and dynamic grid layouts, capable of two-way scrolling to accommodate content that extends beyond both the viewport's width and height. By leveraging `maxColumnRatioUnits`, `itemSizeUnit`, and smooth scrolling mechanics, `FlexGrid` facilitates precise control over the grid's arrangement, dimensions, and scrolling behavior. This makes it exceptionally suited for applications requiring a versatile grid system that can display content in both horizontally and vertically overflowed layouts with ease.
66-
6762

63+
`FlexGrid` is designed for creating highly flexible and dynamic grid layouts, capable of two-way scrolling to accommodate content that extends beyond both the viewport's width and height. By leveraging `maxColumnRatioUnits`, `itemSizeUnit`, and smooth scrolling mechanics, `FlexGrid` facilitates precise control over the grid's arrangement, dimensions, and scrolling behavior. This makes it exceptionally suited for applications requiring a versatile grid system that can display content in both horizontally and vertically overflowed layouts with ease.
6864

6965
#### Use Cases:
66+
7067
- **Interactive Galleries**: Optimal for galleries where users can explore content through both horizontal and vertical navigation.
7168
- **Board Layout**: Ideal for creating grid board with documents or media or files in a grid that exceeds the viewport, allowing for comprehensive exploration.
7269
- **Complex Layouts**: Perfect for applications demanding intricate grid arrangements that go beyond simple lists, including dashboards or design portfolios.
7370

74-
7571
```jsx
7672
import { FlexGrid } from 'react-native-flexible-grid';
7773

7874
export default function App() {
7975
const data = [
80-
{ imageUrl: 'https://picsum.photos/200/300?random=1', widthRatio: 1, heightRatio: 1, text: "Item 1", id: 1 },
81-
{ imageUrl: 'https://picsum.photos/200/300?random=2', widthRatio: 2, heightRatio: 1, text: "Item 2", id: 2 },
82-
{ imageUrl: 'https://picsum.photos/200/300?random=3', widthRatio: 2, heightRatio: 1, text: "Item 3", id: 3 },
76+
{
77+
imageUrl: 'https://picsum.photos/200/300?random=1',
78+
widthRatio: 1,
79+
heightRatio: 1,
80+
text: 'Item 1',
81+
id: 1,
82+
},
83+
{
84+
imageUrl: 'https://picsum.photos/200/300?random=2',
85+
widthRatio: 2,
86+
heightRatio: 1,
87+
text: 'Item 2',
88+
id: 2,
89+
},
90+
{
91+
imageUrl: 'https://picsum.photos/200/300?random=3',
92+
widthRatio: 2,
93+
heightRatio: 1,
94+
text: 'Item 3',
95+
id: 3,
96+
},
8397
];
8498

85-
const renderItem = ({item, index}) => (
86-
<View style={styles.boxContainer}>
87-
<Image
88-
source={{ uri: item.imageUrl }}
89-
style={styles.box}
90-
resizeMode="cover"
91-
/>
92-
<Text style={styles.text}>{item.text}</Text>
93-
</View>
99+
const renderItem = ({ item, index }) => (
100+
<View style={styles.boxContainer}>
101+
<Image
102+
source={{ uri: item.imageUrl }}
103+
style={styles.box}
104+
resizeMode="cover"
105+
/>
106+
<Text style={styles.text}>{item.text}</Text>
107+
</View>
94108
);
95109

96110
return (
@@ -109,44 +123,58 @@ export default function App() {
109123
</View>
110124
);
111125
}
112-
113126
```
114127

115-
116128
#### See Examples:
117-
1. <a href="https://github.com/iNerdStack/react-native-flexible-grid/blob/main/example/src/PinterestHomeExample.tsx">Grid Board Example </a>
118-
119129

130+
1. <a href="https://github.com/iNerdStack/react-native-flexible-grid/blob/main/example/src/PinterestHomeExample.tsx">Grid Board Example </a>
120131

121132
### 2. Responsive Grid
122133

123134
The `ResponsiveGrid` is designed for optimal responsiveness, dynamically adjusting grid items based on the container's width or a specified width within the component's style properties. Utilizing a combination of `maxItemsPerColumn` alongside item-specific `widthRatio` and `heightRatio`, it efficiently organizes content into a vertically scrollable grid. This component is ideally suited for layouts where vertical scrolling is preferred and where the grid's adaptability to varying container widths or device width is crucial.
124135

125136
#### Use Cases:
137+
126138
- **Content Feeds**: Perfect for vertically scrolling content feeds that require adaptability to different screen sizes.
127139
- **Image Galleries**: Ideal for image galleries where images need to be displayed in a responsive, organized or uneven manner.
128140
- **Product Listings**: Suitable for e-commerce apps needing to showcase products in a neatly arranged, responsive grid.
129141

130-
131-
132142
```jsx
133143
import { ResponsiveGrid } from 'react-native-flexible-grid';
134144

135145
export default function App() {
136146
const data = [
137-
{ imageUrl: 'https://picsum.photos/200/300?random=1', widthRatio: 1, heightRatio: 1, text: "Item 1", id: 1 },
138-
{ imageUrl: 'https://picsum.photos/200/300?random=2', widthRatio: 2, heightRatio: 1, text: "Item 2", id: 2 },
139-
{ imageUrl: 'https://picsum.photos/200/300?random=3', widthRatio: 2, heightRatio: 1, text: "Item 3", id: 3 },
147+
{
148+
imageUrl: 'https://picsum.photos/200/300?random=1',
149+
widthRatio: 1,
150+
heightRatio: 1,
151+
text: 'Item 1',
152+
id: 1,
153+
},
154+
{
155+
imageUrl: 'https://picsum.photos/200/300?random=2',
156+
widthRatio: 2,
157+
heightRatio: 1,
158+
text: 'Item 2',
159+
id: 2,
160+
},
161+
{
162+
imageUrl: 'https://picsum.photos/200/300?random=3',
163+
widthRatio: 2,
164+
heightRatio: 1,
165+
text: 'Item 3',
166+
id: 3,
167+
},
140168
];
141169

142-
const renderItem = ({item, index}) => (
143-
<View style={styles.boxContainer}>
144-
<Image
145-
source={{ uri: item.imageUrl }}
146-
style={styles.box}
147-
resizeMode="cover"
148-
/>
149-
</View>
170+
const renderItem = ({ item, index }) => (
171+
<View style={styles.boxContainer}>
172+
<Image
173+
source={{ uri: item.imageUrl }}
174+
style={styles.box}
175+
resizeMode="cover"
176+
/>
177+
</View>
150178
);
151179

152180
return (
@@ -161,15 +189,12 @@ export default function App() {
161189
</View>
162190
);
163191
}
164-
165-
166192
```
167193

168194
#### See Examples:
169-
1. <a href="https://github.com/iNerdStack/react-native-flexible-grid/blob/main/example/src/InstagramExploreExample.tsx"> Instagram Explore Example</a>
170-
2. <a href="https://github.com/iNerdStack/react-native-flexible-grid/blob/main/example/src/PinterestHomeExample.tsx">Pinterest Example</a>
171-
172195

196+
1. <a href="https://github.com/iNerdStack/react-native-flexible-grid/blob/main/example/src/InstagramExploreExample.tsx"> Instagram Explore Example</a>
197+
2. <a href="https://github.com/iNerdStack/react-native-flexible-grid/blob/main/example/src/PinterestHomeExample.tsx">Pinterest Example</a>
173198

174199
## ⚙️ Props
175200

@@ -240,19 +265,21 @@ export default function App() {
240265
<br/>
241266

242267
A higher buffer factor increases the number of items pre-loaded outside the viewport, contributing to a smoother scrolling experience as more content is ready for immediate display when scrolling. However, setting a large buffer factor can affect overall performance, especially on devices with limited resources, as it increases the number of components rendered off-screen.
243-
<br/>
268+
<br/>
244269

245270
While, a lower buffer factor reduces the off-screen component count, optimizing performance and resource usage. This setting is beneficial for large data or resource-constrained environments. However, it may lead to brief moments where content needs to catch up with the user's scroll speed, momentarily displaying blank areas until new items are rendered.
246-
</td>
247-
</tr>
248-
<tr>
249-
<td><code>scrollEventInterval</code></td>
250-
<td><code>Number</code></td>
251-
<td><code>200</code></td>
252-
<td><code>false</code></td>
253-
<td>Defines the interval, in milliseconds, at which scroll events are processed for the purpose of recalculating visible items and buffer in a virtualized grid. By setting this prop, developers can throttle the frequency of scroll event handling, optimizing performance during rapid scrolling by reducing the computational load associated with updating the list of visible items and buffer.
271+
272+
</td>
273+
</tr>
274+
<tr>
275+
<td><code>scrollEventInterval</code></td>
276+
<td><code>Number</code></td>
277+
<td><code>200</code></td>
278+
<td><code>false</code></td>
279+
<td>Defines the interval, in milliseconds, at which scroll events are processed for the purpose of recalculating visible items and buffer in a virtualized grid. By setting this prop, you can throttle the frequency of scroll event handling, optimizing performance during rapid scrolling by reducing the computational load associated with updating the list of visible items and buffer.
254280

255281
A lower value results in more frequent updates, offering smoother visual updates of the grid's content at the potential cost of higher computational overhead. While, a higher interval decreases the frequency of updates, potentially improving performance but with less immediate recalculation triggered by scroll actions. This is crucial for fine-tuning the performance and experience of virtualized grid.
282+
256283
</td>
257284
</tr>
258285
<tr>
@@ -410,19 +437,21 @@ A lower value results in more frequent updates, offering smoother visual updates
410437
<br/>
411438

412439
A higher buffer factor increases the number of items pre-loaded outside the viewport, contributing to a smoother scrolling experience as more content is ready for immediate display when scrolling. However, setting a large buffer factor can affect overall performance, especially on devices with limited resources, as it increases the number of components rendered off-screen.
413-
<br/>
440+
<br/>
414441

415442
While, a lower buffer factor reduces the off-screen component count, optimizing performance and resource usage. This setting is beneficial for large data or resource-constrained environments. However, it may lead to brief moments where content needs to catch up with the user's scroll speed, momentarily displaying blank areas until new items are rendered.
416-
</td>
417-
</tr>
418-
<tr>
419-
<td><code>scrollEventInterval</code></td>
420-
<td><code>Number</code></td>
421-
<td><code>200</code></td>
422-
<td><code>false</code></td>
423-
<td>Defines the interval, in milliseconds, at which scroll events are processed for the purpose of recalculating visible items and buffer in a virtualized grid. By setting this prop, developers can throttle the frequency of scroll event handling, optimizing performance during rapid scrolling by reducing the computational load associated with updating the list of visible items and buffer.
443+
444+
</td>
445+
</tr>
446+
<tr>
447+
<td><code>scrollEventInterval</code></td>
448+
<td><code>Number</code></td>
449+
<td><code>200</code></td>
450+
<td><code>false</code></td>
451+
<td>Defines the interval, in milliseconds, at which scroll events are processed for the purpose of recalculating visible items and buffer in a virtualized grid. By setting this prop, you can throttle the frequency of scroll event handling, optimizing performance during rapid scrolling by reducing the computational load associated with updating the list of visible items and buffer.
424452

425453
A lower value results in more frequent updates, offering smoother visual updates of the grid's content at the potential cost of higher computational overhead. While, a higher interval decreases the frequency of updates, potentially improving performance but with less immediate recalculation triggered by scroll actions. This is crucial for fine-tuning the performance and experience of virtualized grid.
454+
426455
</td>
427456
</tr>
428457
<tr>
@@ -461,6 +490,22 @@ A lower value results in more frequent updates, offering smoother visual updates
461490
<td> Defines the distance from the end of the content at which <code>onEndReached</code> should be triggered, expressed as a proportion of the total content length. For example, a value of <code>0.1</code> triggers the callback when the user has scrolled to within 10% of the end of the content. </td>
462491
</tr>
463492

493+
<tr>
494+
<td><code>onScroll</code></td>
495+
<td><code>(event: NativeSyntheticEvent<NativeScrollEvent>) => void</code></td>
496+
<td><code>undefined</code></td>
497+
<td><code>false</code></td>
498+
<td>Callback function triggered when the scroll view is scrolled. Receives the scroll event as a parameter and can be used for custom scroll handling.</td>
499+
</tr>
500+
501+
<tr>
502+
<td><code>bounces</code></td>
503+
<td><code>boolean</code></td>
504+
<td><code>true</code></td>
505+
<td><code>false</code></td>
506+
<td>Controls whether the ScrollView content can "bounce" when it reaches the end of the content. When set to <code>false</code>, disables the bouncing effect.</td>
507+
</tr>
508+
464509
<tr>
465510
<td><code>autoAdjustItemWidth</code></td>
466511
<td><code>boolean</code></td>
@@ -487,8 +532,8 @@ A lower value results in more frequent updates, offering smoother visual updates
487532
</tbody>
488533
</table>
489534

490-
491535
## 🚀 Vision and Roadmap
536+
492537
Our mission is not just to provide a flexible layout solution but to improve grid systems and layout flexibility in React Native. By continuously refining our algorithm and incorporating feedback, we aim to bring CSS Grid-like capabilities to the React Native ecosystem, fostering creativity and pushing the boundaries of what's possible in app design with React Native.
493538

494539
## 🤝 Contributing

example/package.json

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -9,16 +9,16 @@
99
"web": "expo start --web"
1010
},
1111
"dependencies": {
12-
"expo": "~51.0.22",
13-
"expo-build-properties": "~0.12.3",
14-
"expo-status-bar": "~1.12.1",
15-
"react": "18.2.0",
16-
"react-dom": "18.2.0",
17-
"react-native": "0.74.3",
18-
"react-native-web": "~0.19.6"
12+
"expo": "^53.0.0",
13+
"expo-build-properties": "~0.14.6",
14+
"expo-status-bar": "~2.2.3",
15+
"react": "19.0.0",
16+
"react-dom": "19.0.0",
17+
"react-native": "0.79.2",
18+
"react-native-web": "^0.20.0"
1919
},
2020
"devDependencies": {
21-
"@babel/core": "^7.24.0",
21+
"@babel/core": "^7.26.0",
2222
"@expo/webpack-config": "~19.0.1",
2323
"babel-loader": "^8.1.0",
2424
"babel-plugin-module-resolver": "^5.0.0"

example/src/PinterestHomeExample.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,7 @@ const styles = StyleSheet.create({
9898
boxContainer: {
9999
flex: 1,
100100
padding: 5,
101+
width: '100%',
101102
},
102103
image: {
103104
width: 100,

package.json

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@
2626
"example": "yarn workspace react-native-flexible-grid-example",
2727
"test": "jest",
2828
"typecheck": "tsc --noEmit",
29-
"lint": "eslint \"**/*.{js,ts,tsx}\"",
29+
"lint": "eslint \"src/**/*.{js,ts,tsx}\" \"example/src/**/*.{js,ts,tsx}\" --fix",
3030
"clean": "del-cli lib",
3131
"prepare": "bob build"
3232
},
@@ -55,6 +55,7 @@
5555
"registry": "https://registry.npmjs.org/"
5656
},
5757
"devDependencies": {
58+
"@react-native/babel-preset": "^0.79.2",
5859
"@react-native/eslint-config": "^0.73.1",
5960
"@types/jest": "^29.5.5",
6061
"@types/react": "^18.2.44",
@@ -130,4 +131,4 @@
130131
"directories": {
131132
"example": "example"
132133
}
133-
}
134+
}

0 commit comments

Comments
 (0)