Skip to content

Commit ffb59aa

Browse files
authored
refactor: deprecate width/height props in favor of style-based sizing (#873)
* chore: update .gitignore to exclude .claude file * refactor: deprecate width/height props in favor of style-based sizing - Add @deprecated annotations to width/height props - Prioritize style dimensions over legacy props - Add scrollOffsetValue as preferred alternative to defaultScrollOffsetValue - Update documentation, migration guide, and examples
1 parent 66ccb6d commit ffb59aa

18 files changed

Lines changed: 220 additions & 48 deletions

File tree

.changeset/style-based-sizing.md

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
---
2+
"react-native-reanimated-carousel": minor
3+
---
4+
5+
# Deprecate width/height props in favor of style-based sizing
6+
7+
## Changes
8+
9+
### Deprecated Props
10+
- `width` and `height` props are now deprecated. Use `style={{ width: ..., height: ... }}` instead
11+
- `defaultScrollOffsetValue` is deprecated in favor of `scrollOffsetValue`
12+
13+
### New Behavior
14+
- Carousel now prioritizes dimensions from `style` prop over legacy `width`/`height` props
15+
- When both `style` and legacy props are provided, `style` takes precedence
16+
17+
### Migration
18+
19+
**Before (v4 style):**
20+
```tsx
21+
<Carousel width={300} height={200} />
22+
```
23+
24+
**After (v5 style):**
25+
```tsx
26+
<Carousel style={{ width: 300, height: 200 }} />
27+
```
28+
29+
**Scroll offset:**
30+
```tsx
31+
// Before
32+
<Carousel defaultScrollOffsetValue={sharedValue} />
33+
34+
// After
35+
<Carousel scrollOffsetValue={sharedValue} />
36+
```
37+
38+
### Notes
39+
- Legacy props remain functional for backwards compatibility
40+
- Console warnings will guide migration in development mode
41+
- Full removal planned for next major version

.gitignore

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84,4 +84,5 @@ coverage/
8484
*.local.md
8585

8686
# Claude
87-
CLAUDE.md
87+
CLAUDE.md
88+
.claude

README.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,12 @@
1616
- [Getting Started](https://rn-carousel.dev)
1717
- [Examples](https://rn-carousel.dev/Examples/summary)
1818

19+
## v5 beta notes
20+
21+
- **Sizing**: `style` controls the **container size**; `itemWidth`/`itemHeight` control the **page size** (snap distance & animation progress).
22+
- **Scroll offset shared value**: use `scrollOffsetValue` (recommended). `defaultScrollOffsetValue` is deprecated but still supported.
23+
- **Progress**: `onProgressChange` supports both a callback and `SharedValue<number>`.
24+
1925
## 📊 Version Compatibility
2026

2127
| Carousel Version | Expo SDK | React Native | Reanimated | Gesture Handler | Worklets |

docs/ARCHITECTURE.md

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -186,8 +186,10 @@ Input Props → Default Value Filling → Size Standardization → Data Processi
186186

187187
**Core SharedValues**:
188188
```typescript
189-
const handlerOffset = useSharedValue(defaultScrollOffsetValue || 0);
190-
const size = vertical ? height : width;
189+
const handlerOffset = scrollOffsetValue ?? defaultScrollOffsetValue ?? useSharedValue(0);
190+
// `size` is the "page size" used for snapping & animations:
191+
// itemWidth/itemHeight (preferred) -> style axis size -> deprecated width/height -> measurement
192+
const size = /* resolved page size */;
191193
const validLength = dataLength - 1;
192194
```
193195

example/app/app/demos/basic-layouts/normal/demo.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ function Index() {
2020
pagingEnabled={true}
2121
autoPlayInterval={2000}
2222
data={defaultDataWith6Colors}
23-
defaultScrollOffsetValue={scrollOffsetValue}
23+
scrollOffsetValue={scrollOffsetValue}
2424
style={{ width: window.width, height: 258 }}
2525
onScrollStart={() => {
2626
console.log("Scroll start");

example/app/app/demos/basic-layouts/normal/index.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ function Index() {
3434
<Carousel
3535
{...advancedSettings}
3636
ref={ref}
37-
defaultScrollOffsetValue={scrollOffsetValue}
37+
scrollOffsetValue={scrollOffsetValue}
3838
testID={"xxx"}
3939
style={{
4040
height: 258,

example/app/app/demos/custom-animations/quick-swipe/demo.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ function Index() {
4242
loop={false}
4343
enabled // Default is true, just for demo
4444
ref={ref}
45-
defaultScrollOffsetValue={scrollOffsetValue}
45+
scrollOffsetValue={scrollOffsetValue}
4646
testID={"xxx"}
4747
contentContainerStyle={{ width: "100%" }}
4848
style={{ width: window.width, height: window.width / 2 }}

example/app/app/demos/custom-animations/quick-swipe/index.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ function Index() {
4848
loop={false}
4949
enabled // Default is true, just for demo
5050
ref={ref}
51-
defaultScrollOffsetValue={scrollOffsetValue}
51+
scrollOffsetValue={scrollOffsetValue}
5252
testID={"xxx"}
5353
contentContainerStyle={{ width: "100%" }}
5454
style={{ width: window.width, height: window.width / 2 }}

example/website/pages/Examples/basic-layouts/normal.mdx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ function Index() {
7777
pagingEnabled={true}
7878
autoPlayInterval={2000}
7979
data={defaultDataWith6Colors}
80-
defaultScrollOffsetValue={scrollOffsetValue}
80+
scrollOffsetValue={scrollOffsetValue}
8181
style={{ width: window.width, height: 258 }}
8282
onScrollStart={() => {
8383
console.log("Scroll start");

example/website/pages/Examples/custom-animations/quick-swipe.mdx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@ function Index() {
8989
loop={false}
9090
enabled // Default is true, just for demo
9191
ref={ref}
92-
defaultScrollOffsetValue={scrollOffsetValue}
92+
scrollOffsetValue={scrollOffsetValue}
9393
testID={"xxx"}
9494
contentContainerStyle={{ width: "100%" }}
9595
style={{ width: window.width, height: window.width / 2 }}

0 commit comments

Comments
 (0)