react-native-collapsible-header-tab-view 1.0.3 → 1.0.4
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 -20
- package/dist/index.mjs +31 -21
- package/dist/{index.d.ts.map → src/index.d.ts.map} +1 -1
- package/package.json +1 -1
- /package/dist/{TabFlatList.d.ts → src/TabFlatList.d.ts} +0 -0
- /package/dist/{TabFlatList.d.ts.map → src/TabFlatList.d.ts.map} +0 -0
- /package/dist/{TabScrollView.d.ts → src/TabScrollView.d.ts} +0 -0
- /package/dist/{TabScrollView.d.ts.map → src/TabScrollView.d.ts.map} +0 -0
- /package/dist/{context.d.ts → src/context.d.ts} +0 -0
- /package/dist/{context.d.ts.map → src/context.d.ts.map} +0 -0
- /package/dist/{index.d.ts → src/index.d.ts} +0 -0
- /package/dist/{types.d.ts → src/types.d.ts} +0 -0
- /package/dist/{types.d.ts.map → src/types.d.ts.map} +0 -0
package/dist/index.js
CHANGED
|
@@ -247,7 +247,7 @@ var CollapsibleTabView = (0, import_react4.forwardRef)(
|
|
|
247
247
|
return { headerHeight: h, tabBarHeight: t, ready: true };
|
|
248
248
|
});
|
|
249
249
|
}
|
|
250
|
-
}, []);
|
|
250
|
+
}, [adjustY]);
|
|
251
251
|
const handleHeaderLayout = (0, import_react4.useCallback)(
|
|
252
252
|
(e) => {
|
|
253
253
|
headerHeightRef.current = e.nativeEvent.layout.height;
|
|
@@ -309,24 +309,33 @@ var CollapsibleTabView = (0, import_react4.forwardRef)(
|
|
|
309
309
|
}
|
|
310
310
|
}
|
|
311
311
|
}, []);
|
|
312
|
-
const syncTabOnSwitch = (0, import_react4.useCallback)(
|
|
313
|
-
(
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
312
|
+
const syncTabOnSwitch = (0, import_react4.useCallback)((newIndex) => {
|
|
313
|
+
const currentY = tabScrollYMap.current.get(activeIndex) ?? 0;
|
|
314
|
+
const newTabSavedY = tabScrollYMap.current.get(newIndex) ?? 0;
|
|
315
|
+
const isCollapsed = currentY >= collapseRange - 1;
|
|
316
|
+
const targetY = isCollapsed ? Math.max(newTabSavedY, collapseRange) : Math.min(currentY, collapseRange);
|
|
317
|
+
scrollTabTo(newIndex, targetY);
|
|
318
|
+
tabScrollYMap.current.set(newIndex, targetY);
|
|
319
|
+
scrollY.setValue(Math.min(targetY, collapseRange));
|
|
320
|
+
}, []);
|
|
321
|
+
const preSyncAdjacentTabs = (0, import_react4.useCallback)(() => {
|
|
322
|
+
const currentY = tabScrollYMap.current.get(activeIndex) ?? 0;
|
|
323
|
+
const isCollapsed = currentY >= collapseRange - 1;
|
|
324
|
+
for (const i of [activeIndex - 1, activeIndex + 1]) {
|
|
325
|
+
if (i < 0 || i >= pages.length) continue;
|
|
326
|
+
const savedY = tabScrollYMap.current.get(i) ?? 0;
|
|
327
|
+
const targetY = isCollapsed ? Math.max(savedY, collapseRange) : Math.min(currentY, collapseRange);
|
|
328
|
+
scrollTabTo(i, targetY);
|
|
329
|
+
tabScrollYMap.current.set(i, targetY);
|
|
330
|
+
}
|
|
331
|
+
}, [activeIndex, collapseRange, pages.length, scrollTabTo]);
|
|
332
|
+
const handlePageScrollStateChanged = (0, import_react4.useCallback)(
|
|
333
|
+
(e) => {
|
|
334
|
+
if (e.nativeEvent.pageScrollState === "dragging") {
|
|
335
|
+
preSyncAdjacentTabs();
|
|
322
336
|
}
|
|
323
|
-
import_react_native3.InteractionManager.runAfterInteractions(() => {
|
|
324
|
-
scrollTabTo(newIndex, targetY);
|
|
325
|
-
tabScrollYMap.current.set(newIndex, targetY);
|
|
326
|
-
scrollY.setValue(Math.min(targetY, collapseRange));
|
|
327
|
-
});
|
|
328
337
|
},
|
|
329
|
-
[
|
|
338
|
+
[preSyncAdjacentTabs]
|
|
330
339
|
);
|
|
331
340
|
const handleTabPress = (0, import_react4.useCallback)(
|
|
332
341
|
(index) => {
|
|
@@ -336,17 +345,18 @@ var CollapsibleTabView = (0, import_react4.forwardRef)(
|
|
|
336
345
|
pagerRef.current?.setPageWithoutAnimation(index);
|
|
337
346
|
onTabChange?.(index);
|
|
338
347
|
},
|
|
339
|
-
[activeIndex,
|
|
348
|
+
[activeIndex, syncTabOnSwitch, onTabChange]
|
|
340
349
|
);
|
|
341
350
|
const handlePageSelected = (0, import_react4.useCallback)(
|
|
342
351
|
(e) => {
|
|
343
352
|
const newIndex = e.nativeEvent.position;
|
|
344
353
|
if (newIndex === activeIndex) return;
|
|
345
|
-
|
|
354
|
+
const savedY = tabScrollYMap.current.get(newIndex) ?? 0;
|
|
355
|
+
scrollY.setValue(Math.min(savedY, collapseRange));
|
|
346
356
|
setActiveIndex(newIndex);
|
|
347
357
|
onTabChange?.(newIndex);
|
|
348
358
|
},
|
|
349
|
-
[activeIndex,
|
|
359
|
+
[activeIndex, collapseRange, scrollY, onTabChange]
|
|
350
360
|
);
|
|
351
361
|
const tabBarProps = (0, import_react4.useMemo)(
|
|
352
362
|
() => ({
|
|
@@ -399,6 +409,7 @@ var CollapsibleTabView = (0, import_react4.forwardRef)(
|
|
|
399
409
|
style: styles.pager,
|
|
400
410
|
initialPage: initialTabIndex,
|
|
401
411
|
onPageSelected: handlePageSelected,
|
|
412
|
+
onPageScrollStateChanged: handlePageScrollStateChanged,
|
|
402
413
|
scrollEnabled: swipeEnabled
|
|
403
414
|
},
|
|
404
415
|
pages.map((page, i) => /* @__PURE__ */ import_react4.default.createElement(import_react_native3.View, { key: page?.key ?? i, style: styles.page }, /* @__PURE__ */ import_react4.default.createElement(TabIndexContext.Provider, { value: i }, page)))
|
package/dist/index.mjs
CHANGED
|
@@ -9,7 +9,6 @@ import React3, {
|
|
|
9
9
|
} from "react";
|
|
10
10
|
import {
|
|
11
11
|
Animated as Animated3,
|
|
12
|
-
InteractionManager,
|
|
13
12
|
StyleSheet,
|
|
14
13
|
View as View2
|
|
15
14
|
} from "react-native";
|
|
@@ -244,7 +243,7 @@ var CollapsibleTabView = forwardRef3(
|
|
|
244
243
|
return { headerHeight: h, tabBarHeight: t, ready: true };
|
|
245
244
|
});
|
|
246
245
|
}
|
|
247
|
-
}, []);
|
|
246
|
+
}, [adjustY]);
|
|
248
247
|
const handleHeaderLayout = useCallback3(
|
|
249
248
|
(e) => {
|
|
250
249
|
headerHeightRef.current = e.nativeEvent.layout.height;
|
|
@@ -306,24 +305,33 @@ var CollapsibleTabView = forwardRef3(
|
|
|
306
305
|
}
|
|
307
306
|
}
|
|
308
307
|
}, []);
|
|
309
|
-
const syncTabOnSwitch = useCallback3(
|
|
310
|
-
(
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
308
|
+
const syncTabOnSwitch = useCallback3((newIndex) => {
|
|
309
|
+
const currentY = tabScrollYMap.current.get(activeIndex) ?? 0;
|
|
310
|
+
const newTabSavedY = tabScrollYMap.current.get(newIndex) ?? 0;
|
|
311
|
+
const isCollapsed = currentY >= collapseRange - 1;
|
|
312
|
+
const targetY = isCollapsed ? Math.max(newTabSavedY, collapseRange) : Math.min(currentY, collapseRange);
|
|
313
|
+
scrollTabTo(newIndex, targetY);
|
|
314
|
+
tabScrollYMap.current.set(newIndex, targetY);
|
|
315
|
+
scrollY.setValue(Math.min(targetY, collapseRange));
|
|
316
|
+
}, []);
|
|
317
|
+
const preSyncAdjacentTabs = useCallback3(() => {
|
|
318
|
+
const currentY = tabScrollYMap.current.get(activeIndex) ?? 0;
|
|
319
|
+
const isCollapsed = currentY >= collapseRange - 1;
|
|
320
|
+
for (const i of [activeIndex - 1, activeIndex + 1]) {
|
|
321
|
+
if (i < 0 || i >= pages.length) continue;
|
|
322
|
+
const savedY = tabScrollYMap.current.get(i) ?? 0;
|
|
323
|
+
const targetY = isCollapsed ? Math.max(savedY, collapseRange) : Math.min(currentY, collapseRange);
|
|
324
|
+
scrollTabTo(i, targetY);
|
|
325
|
+
tabScrollYMap.current.set(i, targetY);
|
|
326
|
+
}
|
|
327
|
+
}, [activeIndex, collapseRange, pages.length, scrollTabTo]);
|
|
328
|
+
const handlePageScrollStateChanged = useCallback3(
|
|
329
|
+
(e) => {
|
|
330
|
+
if (e.nativeEvent.pageScrollState === "dragging") {
|
|
331
|
+
preSyncAdjacentTabs();
|
|
319
332
|
}
|
|
320
|
-
InteractionManager.runAfterInteractions(() => {
|
|
321
|
-
scrollTabTo(newIndex, targetY);
|
|
322
|
-
tabScrollYMap.current.set(newIndex, targetY);
|
|
323
|
-
scrollY.setValue(Math.min(targetY, collapseRange));
|
|
324
|
-
});
|
|
325
333
|
},
|
|
326
|
-
[
|
|
334
|
+
[preSyncAdjacentTabs]
|
|
327
335
|
);
|
|
328
336
|
const handleTabPress = useCallback3(
|
|
329
337
|
(index) => {
|
|
@@ -333,17 +341,18 @@ var CollapsibleTabView = forwardRef3(
|
|
|
333
341
|
pagerRef.current?.setPageWithoutAnimation(index);
|
|
334
342
|
onTabChange?.(index);
|
|
335
343
|
},
|
|
336
|
-
[activeIndex,
|
|
344
|
+
[activeIndex, syncTabOnSwitch, onTabChange]
|
|
337
345
|
);
|
|
338
346
|
const handlePageSelected = useCallback3(
|
|
339
347
|
(e) => {
|
|
340
348
|
const newIndex = e.nativeEvent.position;
|
|
341
349
|
if (newIndex === activeIndex) return;
|
|
342
|
-
|
|
350
|
+
const savedY = tabScrollYMap.current.get(newIndex) ?? 0;
|
|
351
|
+
scrollY.setValue(Math.min(savedY, collapseRange));
|
|
343
352
|
setActiveIndex(newIndex);
|
|
344
353
|
onTabChange?.(newIndex);
|
|
345
354
|
},
|
|
346
|
-
[activeIndex,
|
|
355
|
+
[activeIndex, collapseRange, scrollY, onTabChange]
|
|
347
356
|
);
|
|
348
357
|
const tabBarProps = useMemo2(
|
|
349
358
|
() => ({
|
|
@@ -396,6 +405,7 @@ var CollapsibleTabView = forwardRef3(
|
|
|
396
405
|
style: styles.pager,
|
|
397
406
|
initialPage: initialTabIndex,
|
|
398
407
|
onPageSelected: handlePageSelected,
|
|
408
|
+
onPageScrollStateChanged: handlePageScrollStateChanged,
|
|
399
409
|
scrollEnabled: swipeEnabled
|
|
400
410
|
},
|
|
401
411
|
pages.map((page, i) => /* @__PURE__ */ React3.createElement(View2, { key: page?.key ?? i, style: styles.page }, /* @__PURE__ */ React3.createElement(TabIndexContext.Provider, { value: i }, page)))
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.tsx"],"names":[],"mappings":"AAAA,OAAO,KAON,MAAM,OAAO,CAAC;
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.tsx"],"names":[],"mappings":"AAAA,OAAO,KAON,MAAM,OAAO,CAAC;AAYf,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,YAAY,EACV,uBAAuB,EACvB,qBAAqB,EACrB,WAAW,GACZ,MAAM,SAAS,CAAC;AAEjB,QAAA,MAAM,kBAAkB,uGA0TvB,CAAC;AAwBF,eAAe,kBAAkB,CAAC"}
|
package/package.json
CHANGED
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|