react-native-collapsible-header-tab-view 1.0.5 → 1.0.6
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.
- package/dist/index.js +31 -17
- package/dist/index.mjs +47 -31
- package/dist/src/TabScrollView.d.ts.map +1 -1
- package/dist/src/index.d.ts.map +1 -1
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -135,7 +135,17 @@ var import_react_native2 = require("react-native");
|
|
|
135
135
|
var TabScrollView = (0, import_react3.forwardRef)(
|
|
136
136
|
({ contentContainerStyle, onScroll, children, ...props }, ref) => {
|
|
137
137
|
const index = useTabIndex();
|
|
138
|
-
const {
|
|
138
|
+
const {
|
|
139
|
+
scrollY,
|
|
140
|
+
activeIndex,
|
|
141
|
+
stickyEnabled,
|
|
142
|
+
headerHeight,
|
|
143
|
+
tabBarHeight,
|
|
144
|
+
renderHeader,
|
|
145
|
+
renderTabBar,
|
|
146
|
+
registerRef,
|
|
147
|
+
syncScrollY
|
|
148
|
+
} = useCollapsible();
|
|
139
149
|
const innerRef = (0, import_react3.useRef)(null);
|
|
140
150
|
const isActive = activeIndex === index;
|
|
141
151
|
(0, import_react3.useEffect)(() => {
|
|
@@ -151,8 +161,12 @@ var TabScrollView = (0, import_react3.forwardRef)(
|
|
|
151
161
|
},
|
|
152
162
|
[index, onScroll, syncScrollY]
|
|
153
163
|
);
|
|
154
|
-
const
|
|
155
|
-
|
|
164
|
+
const mergedChildren = (0, import_react3.useMemo)(() => {
|
|
165
|
+
if (stickyEnabled) return children;
|
|
166
|
+
return /* @__PURE__ */ import_react3.default.createElement(import_react_native2.View, null, renderHeader?.(), renderTabBar?.(), children);
|
|
167
|
+
}, [stickyEnabled, children, renderHeader, renderTabBar]);
|
|
168
|
+
const paddingTop = stickyEnabled ? headerHeight + tabBarHeight : 0;
|
|
169
|
+
const collapseRange = stickyEnabled ? headerHeight : 0;
|
|
156
170
|
const [containerHeight, setContainerHeight] = (0, import_react3.useState)(0);
|
|
157
171
|
const handleLayout = (0, import_react3.useCallback)((e) => {
|
|
158
172
|
setContainerHeight(e.nativeEvent.layout.height);
|
|
@@ -165,18 +179,21 @@ var TabScrollView = (0, import_react3.forwardRef)(
|
|
|
165
179
|
...props,
|
|
166
180
|
onLayout: handleLayout,
|
|
167
181
|
contentContainerStyle: [
|
|
168
|
-
{ paddingTop },
|
|
182
|
+
paddingTop > 0 && { paddingTop },
|
|
169
183
|
minHeight > 0 && { minHeight },
|
|
170
184
|
contentContainerStyle
|
|
171
185
|
],
|
|
172
|
-
onScroll: isActive ? import_react_native2.Animated.event(
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
186
|
+
onScroll: isActive && stickyEnabled ? import_react_native2.Animated.event(
|
|
187
|
+
[{ nativeEvent: { contentOffset: { y: scrollY } } }],
|
|
188
|
+
{
|
|
189
|
+
useNativeDriver: true,
|
|
190
|
+
listener: handleScroll
|
|
191
|
+
}
|
|
192
|
+
) : handleScroll,
|
|
176
193
|
scrollEventThrottle: 16,
|
|
177
194
|
showsVerticalScrollIndicator: false
|
|
178
195
|
},
|
|
179
|
-
|
|
196
|
+
mergedChildren
|
|
180
197
|
);
|
|
181
198
|
}
|
|
182
199
|
);
|
|
@@ -337,14 +354,11 @@ var CollapsibleTabView = (0, import_react5.forwardRef)(
|
|
|
337
354
|
/* @__PURE__ */ new Map()
|
|
338
355
|
);
|
|
339
356
|
const collapseRange = stickyEnabled ? Math.max(headerHeight - stickyTop, 0) : 0;
|
|
340
|
-
const headerTranslateY =
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
}) : new import_react_native4.Animated.Value(0),
|
|
346
|
-
[scrollY, collapseRange]
|
|
347
|
-
);
|
|
357
|
+
const headerTranslateY = scrollY.interpolate({
|
|
358
|
+
inputRange: [0, Math.max(collapseRange, 1)],
|
|
359
|
+
outputRange: [0, -collapseRange],
|
|
360
|
+
extrapolate: "clamp"
|
|
361
|
+
});
|
|
348
362
|
const registerRef = (0, import_react5.useCallback)(
|
|
349
363
|
(index, ref2) => {
|
|
350
364
|
if (ref2) {
|
package/dist/index.mjs
CHANGED
|
@@ -3,14 +3,14 @@ import React4, {
|
|
|
3
3
|
forwardRef as forwardRef4,
|
|
4
4
|
useCallback as useCallback4,
|
|
5
5
|
useImperativeHandle as useImperativeHandle4,
|
|
6
|
-
useMemo as
|
|
6
|
+
useMemo as useMemo4,
|
|
7
7
|
useRef as useRef4,
|
|
8
8
|
useState as useState4
|
|
9
9
|
} from "react";
|
|
10
10
|
import {
|
|
11
11
|
Animated as Animated4,
|
|
12
12
|
StyleSheet,
|
|
13
|
-
View as
|
|
13
|
+
View as View4
|
|
14
14
|
} from "react-native";
|
|
15
15
|
import PagerView from "react-native-pager-view";
|
|
16
16
|
|
|
@@ -121,16 +121,28 @@ import React2, {
|
|
|
121
121
|
useCallback as useCallback2,
|
|
122
122
|
useEffect as useEffect2,
|
|
123
123
|
useImperativeHandle as useImperativeHandle2,
|
|
124
|
+
useMemo as useMemo2,
|
|
124
125
|
useRef as useRef2,
|
|
125
126
|
useState as useState2
|
|
126
127
|
} from "react";
|
|
127
128
|
import {
|
|
128
|
-
Animated as Animated2
|
|
129
|
+
Animated as Animated2,
|
|
130
|
+
View as View2
|
|
129
131
|
} from "react-native";
|
|
130
132
|
var TabScrollView = forwardRef2(
|
|
131
133
|
({ contentContainerStyle, onScroll, children, ...props }, ref) => {
|
|
132
134
|
const index = useTabIndex();
|
|
133
|
-
const {
|
|
135
|
+
const {
|
|
136
|
+
scrollY,
|
|
137
|
+
activeIndex,
|
|
138
|
+
stickyEnabled,
|
|
139
|
+
headerHeight,
|
|
140
|
+
tabBarHeight,
|
|
141
|
+
renderHeader,
|
|
142
|
+
renderTabBar,
|
|
143
|
+
registerRef,
|
|
144
|
+
syncScrollY
|
|
145
|
+
} = useCollapsible();
|
|
134
146
|
const innerRef = useRef2(null);
|
|
135
147
|
const isActive = activeIndex === index;
|
|
136
148
|
useEffect2(() => {
|
|
@@ -146,8 +158,12 @@ var TabScrollView = forwardRef2(
|
|
|
146
158
|
},
|
|
147
159
|
[index, onScroll, syncScrollY]
|
|
148
160
|
);
|
|
149
|
-
const
|
|
150
|
-
|
|
161
|
+
const mergedChildren = useMemo2(() => {
|
|
162
|
+
if (stickyEnabled) return children;
|
|
163
|
+
return /* @__PURE__ */ React2.createElement(View2, null, renderHeader?.(), renderTabBar?.(), children);
|
|
164
|
+
}, [stickyEnabled, children, renderHeader, renderTabBar]);
|
|
165
|
+
const paddingTop = stickyEnabled ? headerHeight + tabBarHeight : 0;
|
|
166
|
+
const collapseRange = stickyEnabled ? headerHeight : 0;
|
|
151
167
|
const [containerHeight, setContainerHeight] = useState2(0);
|
|
152
168
|
const handleLayout = useCallback2((e) => {
|
|
153
169
|
setContainerHeight(e.nativeEvent.layout.height);
|
|
@@ -160,18 +176,21 @@ var TabScrollView = forwardRef2(
|
|
|
160
176
|
...props,
|
|
161
177
|
onLayout: handleLayout,
|
|
162
178
|
contentContainerStyle: [
|
|
163
|
-
{ paddingTop },
|
|
179
|
+
paddingTop > 0 && { paddingTop },
|
|
164
180
|
minHeight > 0 && { minHeight },
|
|
165
181
|
contentContainerStyle
|
|
166
182
|
],
|
|
167
|
-
onScroll: isActive ? Animated2.event(
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
183
|
+
onScroll: isActive && stickyEnabled ? Animated2.event(
|
|
184
|
+
[{ nativeEvent: { contentOffset: { y: scrollY } } }],
|
|
185
|
+
{
|
|
186
|
+
useNativeDriver: true,
|
|
187
|
+
listener: handleScroll
|
|
188
|
+
}
|
|
189
|
+
) : handleScroll,
|
|
171
190
|
scrollEventThrottle: 16,
|
|
172
191
|
showsVerticalScrollIndicator: false
|
|
173
192
|
},
|
|
174
|
-
|
|
193
|
+
mergedChildren
|
|
175
194
|
);
|
|
176
195
|
}
|
|
177
196
|
);
|
|
@@ -182,14 +201,14 @@ import React3, {
|
|
|
182
201
|
useCallback as useCallback3,
|
|
183
202
|
useEffect as useEffect3,
|
|
184
203
|
useImperativeHandle as useImperativeHandle3,
|
|
185
|
-
useMemo as
|
|
204
|
+
useMemo as useMemo3,
|
|
186
205
|
useRef as useRef3,
|
|
187
206
|
useState as useState3
|
|
188
207
|
} from "react";
|
|
189
208
|
import {
|
|
190
209
|
Animated as Animated3,
|
|
191
210
|
SectionList,
|
|
192
|
-
View as
|
|
211
|
+
View as View3
|
|
193
212
|
} from "react-native";
|
|
194
213
|
var AnimatedSectionListComponent = Animated3.createAnimatedComponent(SectionList);
|
|
195
214
|
var AnimatedSectionList = AnimatedSectionListComponent;
|
|
@@ -221,10 +240,10 @@ var TabSectionListInner = ({ contentContainerStyle, onScroll, ListHeaderComponen
|
|
|
221
240
|
},
|
|
222
241
|
[index, onScroll, syncScrollY]
|
|
223
242
|
);
|
|
224
|
-
const mergedHeader =
|
|
243
|
+
const mergedHeader = useMemo3(() => {
|
|
225
244
|
if (stickyEnabled) return ListHeaderComponent;
|
|
226
245
|
const OriginalHeader = typeof ListHeaderComponent === "function" ? /* @__PURE__ */ React3.createElement(ListHeaderComponent, null) : ListHeaderComponent ?? null;
|
|
227
|
-
return /* @__PURE__ */ React3.createElement(
|
|
246
|
+
return /* @__PURE__ */ React3.createElement(View3, null, renderHeader?.(), renderTabBar?.(), OriginalHeader);
|
|
228
247
|
}, [stickyEnabled, ListHeaderComponent, renderHeader, renderTabBar]);
|
|
229
248
|
const paddingTop = stickyEnabled ? headerHeight + tabBarHeight : 0;
|
|
230
249
|
const collapseRange = stickyEnabled ? headerHeight : 0;
|
|
@@ -274,7 +293,7 @@ var CollapsibleTabView = forwardRef4(
|
|
|
274
293
|
}, ref) => {
|
|
275
294
|
const [activeIndex, setActiveIndex] = useState4(initialTabIndex);
|
|
276
295
|
const pagerRef = useRef4(null);
|
|
277
|
-
const pages =
|
|
296
|
+
const pages = useMemo4(
|
|
278
297
|
() => React4.Children.toArray(children).filter(React4.isValidElement),
|
|
279
298
|
[children]
|
|
280
299
|
);
|
|
@@ -344,14 +363,11 @@ var CollapsibleTabView = forwardRef4(
|
|
|
344
363
|
/* @__PURE__ */ new Map()
|
|
345
364
|
);
|
|
346
365
|
const collapseRange = stickyEnabled ? Math.max(headerHeight - stickyTop, 0) : 0;
|
|
347
|
-
const headerTranslateY =
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
}) : new Animated4.Value(0),
|
|
353
|
-
[scrollY, collapseRange]
|
|
354
|
-
);
|
|
366
|
+
const headerTranslateY = scrollY.interpolate({
|
|
367
|
+
inputRange: [0, Math.max(collapseRange, 1)],
|
|
368
|
+
outputRange: [0, -collapseRange],
|
|
369
|
+
extrapolate: "clamp"
|
|
370
|
+
});
|
|
355
371
|
const registerRef = useCallback4(
|
|
356
372
|
(index, ref2) => {
|
|
357
373
|
if (ref2) {
|
|
@@ -434,7 +450,7 @@ var CollapsibleTabView = forwardRef4(
|
|
|
434
450
|
},
|
|
435
451
|
[activeIndex, collapseRange, scrollY, onTabChange]
|
|
436
452
|
);
|
|
437
|
-
const tabBarProps =
|
|
453
|
+
const tabBarProps = useMemo4(
|
|
438
454
|
() => ({
|
|
439
455
|
activeIndex,
|
|
440
456
|
onTabPress: handleTabPress
|
|
@@ -445,7 +461,7 @@ var CollapsibleTabView = forwardRef4(
|
|
|
445
461
|
() => renderTabBar(tabBarProps),
|
|
446
462
|
[renderTabBar, tabBarProps]
|
|
447
463
|
);
|
|
448
|
-
const contextValue =
|
|
464
|
+
const contextValue = useMemo4(
|
|
449
465
|
() => ({
|
|
450
466
|
scrollY,
|
|
451
467
|
activeIndex,
|
|
@@ -469,7 +485,7 @@ var CollapsibleTabView = forwardRef4(
|
|
|
469
485
|
syncScrollY
|
|
470
486
|
]
|
|
471
487
|
);
|
|
472
|
-
return /* @__PURE__ */ React4.createElement(CollapsibleContext.Provider, { value: contextValue }, /* @__PURE__ */ React4.createElement(
|
|
488
|
+
return /* @__PURE__ */ React4.createElement(CollapsibleContext.Provider, { value: contextValue }, /* @__PURE__ */ React4.createElement(View4, { style: [styles.container, style] }, /* @__PURE__ */ React4.createElement(
|
|
473
489
|
Animated4.View,
|
|
474
490
|
{
|
|
475
491
|
style: [
|
|
@@ -488,7 +504,7 @@ var CollapsibleTabView = forwardRef4(
|
|
|
488
504
|
onPageScrollStateChanged: handlePageScrollStateChanged,
|
|
489
505
|
scrollEnabled: swipeEnabled
|
|
490
506
|
},
|
|
491
|
-
pages.map((page, i) => /* @__PURE__ */ React4.createElement(
|
|
507
|
+
pages.map((page, i) => /* @__PURE__ */ React4.createElement(View4, { key: page?.key ?? i, style: styles.page }, /* @__PURE__ */ React4.createElement(TabIndexContext.Provider, { value: i }, page)))
|
|
492
508
|
)
|
|
493
509
|
), stickyEnabled && /* @__PURE__ */ React4.createElement(
|
|
494
510
|
Animated4.View,
|
|
@@ -499,8 +515,8 @@ var CollapsibleTabView = forwardRef4(
|
|
|
499
515
|
],
|
|
500
516
|
pointerEvents: "box-none"
|
|
501
517
|
},
|
|
502
|
-
/* @__PURE__ */ React4.createElement(
|
|
503
|
-
/* @__PURE__ */ React4.createElement(
|
|
518
|
+
/* @__PURE__ */ React4.createElement(View4, { pointerEvents: "box-none", onLayout: handleHeaderLayout }, renderHeader()),
|
|
519
|
+
/* @__PURE__ */ React4.createElement(View4, { onLayout: handleTabBarLayout }, renderTabBarNode())
|
|
504
520
|
)));
|
|
505
521
|
}
|
|
506
522
|
);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"TabScrollView.d.ts","sourceRoot":"","sources":["../../src/TabScrollView.tsx"],"names":[],"mappings":"AAAA,OAAO,
|
|
1
|
+
{"version":3,"file":"TabScrollView.d.ts","sourceRoot":"","sources":["../../src/TabScrollView.tsx"],"names":[],"mappings":"AAAA,OAAO,KAQN,MAAM,OAAO,CAAC;AACf,OAAO,EAGL,iBAAiB,EACjB,oBAAoB,EACpB,UAAU,EACV,eAAe,EAEhB,MAAM,cAAc,CAAC;AAItB,MAAM,MAAM,kBAAkB,GAAG,IAAI,CAAC,eAAe,EAAE,UAAU,CAAC,GAAG;IACnE,QAAQ,CAAC,EAAE,CAAC,CAAC,EAAE,oBAAoB,CAAC,iBAAiB,CAAC,KAAK,IAAI,CAAC;CACjE,CAAC;AAEF,QAAA,MAAM,aAAa;eAHN,CAAC,CAAC,EAAE,oBAAoB,CAAC,iBAAiB,CAAC,KAAK,IAAI;oCAsFhE,CAAC;AAEF,OAAO,EAAE,aAAa,EAAE,CAAC"}
|
package/dist/src/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.tsx"],"names":[],"mappings":"AAAA,OAAO,KAON,MAAM,OAAO,CAAC;AAaf,OAAO,EAEL,uBAAuB,EACvB,qBAAqB,EAEtB,MAAM,SAAS,CAAC;AAEjB,OAAO,EAAE,WAAW,EAAE,MAAM,eAAe,CAAC;AAC5C,OAAO,EAAE,aAAa,EAAE,MAAM,iBAAiB,CAAC;AAChD,OAAO,EAAE,cAAc,EAAE,MAAM,kBAAkB,CAAC;AAClD,YAAY,EACV,uBAAuB,EACvB,qBAAqB,EACrB,WAAW,GACZ,MAAM,SAAS,CAAC;AAEjB,QAAA,MAAM,kBAAkB,
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.tsx"],"names":[],"mappings":"AAAA,OAAO,KAON,MAAM,OAAO,CAAC;AAaf,OAAO,EAEL,uBAAuB,EACvB,qBAAqB,EAEtB,MAAM,SAAS,CAAC;AAEjB,OAAO,EAAE,WAAW,EAAE,MAAM,eAAe,CAAC;AAC5C,OAAO,EAAE,aAAa,EAAE,MAAM,iBAAiB,CAAC;AAChD,OAAO,EAAE,cAAc,EAAE,MAAM,kBAAkB,CAAC;AAClD,YAAY,EACV,uBAAuB,EACvB,qBAAqB,EACrB,WAAW,GACZ,MAAM,SAAS,CAAC;AAEjB,QAAA,MAAM,kBAAkB,uGAuTvB,CAAC;AAwBF,eAAe,kBAAkB,CAAC"}
|