@onekeyfe/react-native-pager-view 6.7.0-alpha.378 → 6.7.0-alpha.383
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/README.md +5 -0
- package/android/src/androidTest/AndroidManifest.xml +7 -0
- package/android/src/androidTest/java/com/reactnativepagerview/CollapsiblePagerTabReservationTest.kt +247 -0
- package/android/src/main/java/com/reactnativepagerview/CollapsiblePagerHost.kt +76 -21
- package/android/src/main/java/com/reactnativepagerview/CollapsiblePagerNativeHeaders.kt +72 -7
- package/android/src/main/java/com/reactnativepagerview/CollapsiblePagerViewManager.kt +27 -0
- package/android/src/main/java/com/reactnativepagerview/NativeScrollerView.kt +50 -6
- package/docs/SPEC.md +114 -1
- package/ios/RNCCollapsiblePagerViewComponentView.mm +126 -12
- package/ios/tests/RNCCollapsiblePagerFirstFrameTests.mm +83 -0
- package/ios/tests/RNCCollapsiblePagerHitTestTests.mm +178 -0
- package/ios/tests/RNCCollapsiblePagerPressCancellationTests.mm +65 -0
- package/lib/module/CollapsiblePagerView.js +20 -4
- package/lib/module/CollapsiblePagerView.web.js +11 -2
- package/lib/module/CollapsiblePagerViewNativeComponent.ts +13 -0
- package/lib/typescript/src/CollapsiblePagerView.d.ts +6 -1
- package/lib/typescript/src/CollapsiblePagerView.web.d.ts +2 -0
- package/lib/typescript/src/CollapsiblePagerViewNativeComponent.d.ts +5 -0
- package/package.json +2 -2
- package/react-native-pager-view.podspec +1 -0
- package/src/CollapsiblePagerView.tsx +68 -4
- package/src/CollapsiblePagerView.web.tsx +19 -2
- package/src/CollapsiblePagerViewNativeComponent.ts +13 -0
|
@@ -32,8 +32,11 @@ export type CollapsiblePagerNativeTabBarItem = Readonly<{
|
|
|
32
32
|
}>;
|
|
33
33
|
|
|
34
34
|
export type CollapsiblePagerNativeTabBarStyle = Readonly<{
|
|
35
|
+
variant?: "underline" | "segmented";
|
|
35
36
|
height?: number;
|
|
37
|
+
trailingReservedWidth?: number;
|
|
36
38
|
contentPaddingHorizontal?: number;
|
|
39
|
+
contentPaddingVertical?: number;
|
|
37
40
|
itemSpacing?: number;
|
|
38
41
|
fontSize?: number;
|
|
39
42
|
fontFamily?: string;
|
|
@@ -94,7 +97,10 @@ export interface CollapsiblePagerViewProps
|
|
|
94
97
|
| "retainedPages"
|
|
95
98
|
| "nativeTabBarItems"
|
|
96
99
|
| "nativeTabBarHeight"
|
|
100
|
+
| "nativeTabBarVariant"
|
|
101
|
+
| "nativeTabBarTrailingReservedWidth"
|
|
97
102
|
| "nativeTabBarContentPaddingHorizontal"
|
|
103
|
+
| "nativeTabBarContentPaddingVertical"
|
|
98
104
|
| "nativeTabBarItemSpacing"
|
|
99
105
|
| "nativeTabBarFontSize"
|
|
100
106
|
| "nativeTabBarFontFamily"
|
|
@@ -290,6 +296,22 @@ export class CollapsiblePagerView extends React.PureComponent<
|
|
|
290
296
|
);
|
|
291
297
|
};
|
|
292
298
|
|
|
299
|
+
public scrollHeaderBy = (delta: number) => {
|
|
300
|
+
if (this.nativeRef && Number.isFinite(delta))
|
|
301
|
+
CollapsiblePagerViewNativeCommands.scrollHeaderBy(
|
|
302
|
+
this.nativeRef,
|
|
303
|
+
delta
|
|
304
|
+
);
|
|
305
|
+
};
|
|
306
|
+
|
|
307
|
+
public scrollHeaderToOffset = (offset: number) => {
|
|
308
|
+
if (this.nativeRef && Number.isFinite(offset))
|
|
309
|
+
CollapsiblePagerViewNativeCommands.scrollHeaderToOffset(
|
|
310
|
+
this.nativeRef,
|
|
311
|
+
offset
|
|
312
|
+
);
|
|
313
|
+
};
|
|
314
|
+
|
|
293
315
|
public scrollToStickyTop = (options?: Readonly<{ animated?: boolean }>) => {
|
|
294
316
|
if (this.nativeRef)
|
|
295
317
|
CollapsiblePagerViewNativeCommands.scrollToTop(
|
|
@@ -319,7 +341,11 @@ export class CollapsiblePagerView extends React.PureComponent<
|
|
|
319
341
|
);
|
|
320
342
|
}
|
|
321
343
|
|
|
322
|
-
private dispatchNativeTabPageCommand(
|
|
344
|
+
private dispatchNativeTabPageCommand(
|
|
345
|
+
position: number,
|
|
346
|
+
animated: boolean,
|
|
347
|
+
expectedKey?: string
|
|
348
|
+
) {
|
|
323
349
|
const commandId = ++this.nativeTabCommandId;
|
|
324
350
|
this.nativeTabCommandQueuedDuringScroll =
|
|
325
351
|
this.nativePagerScrollState !== "idle";
|
|
@@ -332,7 +358,13 @@ export class CollapsiblePagerView extends React.PureComponent<
|
|
|
332
358
|
}),
|
|
333
359
|
() => {
|
|
334
360
|
requestAnimationFrame(() => {
|
|
335
|
-
if (
|
|
361
|
+
if (
|
|
362
|
+
commandId !== this.nativeTabCommandId ||
|
|
363
|
+
!this.nativeRef ||
|
|
364
|
+
(expectedKey !== undefined &&
|
|
365
|
+
(!this.nativeTabBarEnabled() ||
|
|
366
|
+
this.props.nativeTabBar?.items[position]?.key !== expectedKey))
|
|
367
|
+
) {
|
|
336
368
|
return;
|
|
337
369
|
}
|
|
338
370
|
this.dispatchedNativeTabTarget = position;
|
|
@@ -458,7 +490,13 @@ export class CollapsiblePagerView extends React.PureComponent<
|
|
|
458
490
|
) => {
|
|
459
491
|
const position = pageIndex(event.nativeEvent.position);
|
|
460
492
|
if (
|
|
461
|
-
|
|
493
|
+
!this.nativeTabBarEnabled() ||
|
|
494
|
+
position === null ||
|
|
495
|
+
this.props.nativeTabBar?.items[position]?.key !== event.nativeEvent.key
|
|
496
|
+
) {
|
|
497
|
+
return;
|
|
498
|
+
}
|
|
499
|
+
if (
|
|
462
500
|
position >= 0 &&
|
|
463
501
|
position < this.pages().length &&
|
|
464
502
|
(position !== this.state.selectedPage ||
|
|
@@ -470,7 +508,8 @@ export class CollapsiblePagerView extends React.PureComponent<
|
|
|
470
508
|
this.dispatchNativeTabPageCommand(
|
|
471
509
|
position,
|
|
472
510
|
this.props.nativeTabPressAnimationEnabled ??
|
|
473
|
-
Math.abs(position - currentPage) <= 1
|
|
511
|
+
Math.abs(position - currentPage) <= 1,
|
|
512
|
+
event.nativeEvent.key
|
|
474
513
|
);
|
|
475
514
|
}
|
|
476
515
|
this.props.onNativeTabPress?.(event);
|
|
@@ -533,6 +572,22 @@ export class CollapsiblePagerView extends React.PureComponent<
|
|
|
533
572
|
(Platform.OS === "ios" || Platform.OS === "android") &&
|
|
534
573
|
!!nativeTabBar?.items.length;
|
|
535
574
|
const nativeTabBarStyle = nativeTabBar?.style;
|
|
575
|
+
const requestedContentPaddingVertical =
|
|
576
|
+
nativeTabBarStyle?.contentPaddingVertical;
|
|
577
|
+
const nativeTabBarContentPaddingVertical =
|
|
578
|
+
typeof requestedContentPaddingVertical === "number" &&
|
|
579
|
+
Number.isFinite(requestedContentPaddingVertical) &&
|
|
580
|
+
requestedContentPaddingVertical >= 0
|
|
581
|
+
? requestedContentPaddingVertical
|
|
582
|
+
: 0;
|
|
583
|
+
const requestedTrailingReservedWidth =
|
|
584
|
+
nativeTabBarStyle?.trailingReservedWidth;
|
|
585
|
+
const nativeTabBarTrailingReservedWidth =
|
|
586
|
+
typeof requestedTrailingReservedWidth === "number" &&
|
|
587
|
+
Number.isFinite(requestedTrailingReservedWidth) &&
|
|
588
|
+
requestedTrailingReservedWidth >= 0
|
|
589
|
+
? requestedTrailingReservedWidth
|
|
590
|
+
: 0;
|
|
536
591
|
const nativeSubHeaderEnabled =
|
|
537
592
|
(Platform.OS === "ios" || Platform.OS === "android") &&
|
|
538
593
|
!!nativeSubHeader?.items.length;
|
|
@@ -586,11 +641,20 @@ export class CollapsiblePagerView extends React.PureComponent<
|
|
|
586
641
|
nativeTabBarHeight={
|
|
587
642
|
nativeTabBarEnabled ? nativeTabBarStyle?.height ?? 44 : undefined
|
|
588
643
|
}
|
|
644
|
+
nativeTabBarVariant={
|
|
645
|
+
nativeTabBarEnabled ? nativeTabBarStyle?.variant ?? "underline" : undefined
|
|
646
|
+
}
|
|
647
|
+
nativeTabBarTrailingReservedWidth={
|
|
648
|
+
nativeTabBarEnabled ? nativeTabBarTrailingReservedWidth : 0
|
|
649
|
+
}
|
|
589
650
|
nativeTabBarContentPaddingHorizontal={
|
|
590
651
|
nativeTabBarEnabled
|
|
591
652
|
? nativeTabBarStyle?.contentPaddingHorizontal ?? 20
|
|
592
653
|
: undefined
|
|
593
654
|
}
|
|
655
|
+
nativeTabBarContentPaddingVertical={
|
|
656
|
+
nativeTabBarEnabled ? nativeTabBarContentPaddingVertical : undefined
|
|
657
|
+
}
|
|
594
658
|
nativeTabBarItemSpacing={
|
|
595
659
|
nativeTabBarEnabled ? nativeTabBarStyle?.itemSpacing ?? 8 : undefined
|
|
596
660
|
}
|
|
@@ -580,6 +580,23 @@ export class CollapsiblePagerView extends React.PureComponent<
|
|
|
580
580
|
this.scrollCurrentPageToTop(0, options?.animated ?? true);
|
|
581
581
|
};
|
|
582
582
|
|
|
583
|
+
public scrollHeaderBy = (delta: number) => {
|
|
584
|
+
if (!Number.isFinite(delta)) return;
|
|
585
|
+
const offset = Math.min(
|
|
586
|
+
this.headerHeight,
|
|
587
|
+
Math.max(0, this.sharedHeaderOffset + delta)
|
|
588
|
+
);
|
|
589
|
+
this.scrollCurrentPageToTop(offset, false);
|
|
590
|
+
};
|
|
591
|
+
|
|
592
|
+
public scrollHeaderToOffset = (offset: number) => {
|
|
593
|
+
if (!Number.isFinite(offset)) return;
|
|
594
|
+
this.scrollCurrentPageToTop(
|
|
595
|
+
Math.min(this.headerHeight, Math.max(0, offset)),
|
|
596
|
+
false
|
|
597
|
+
);
|
|
598
|
+
};
|
|
599
|
+
|
|
583
600
|
public scrollToStickyTop = (options?: Readonly<{ animated?: boolean }>) => {
|
|
584
601
|
this.scrollCurrentPageToTop(
|
|
585
602
|
this.headerHeight,
|
|
@@ -674,10 +691,10 @@ export class CollapsiblePagerView extends React.PureComponent<
|
|
|
674
691
|
)
|
|
675
692
|
return;
|
|
676
693
|
this.pageOffsets.set(key, 0);
|
|
677
|
-
this.sharedHeaderOffset = offset;
|
|
694
|
+
this.sharedHeaderOffset = Math.min(this.headerHeight, Math.max(0, offset));
|
|
678
695
|
this.bodyAlignment = { element, key };
|
|
679
696
|
scrollElementTo(element, {
|
|
680
|
-
top:
|
|
697
|
+
top: this.sharedHeaderOffset,
|
|
681
698
|
behavior: animated ? "smooth" : "instant",
|
|
682
699
|
});
|
|
683
700
|
this.syncFallbackHeader();
|
|
@@ -67,7 +67,10 @@ export interface NativeProps extends ViewProps {
|
|
|
67
67
|
retainedPages?: string;
|
|
68
68
|
nativeTabBarItems?: string;
|
|
69
69
|
nativeTabBarHeight?: Double;
|
|
70
|
+
nativeTabBarVariant?: string;
|
|
71
|
+
nativeTabBarTrailingReservedWidth?: WithDefault<Double, 0>;
|
|
70
72
|
nativeTabBarContentPaddingHorizontal?: Double;
|
|
73
|
+
nativeTabBarContentPaddingVertical?: Double;
|
|
71
74
|
nativeTabBarItemSpacing?: Double;
|
|
72
75
|
nativeTabBarFontSize?: Double;
|
|
73
76
|
nativeTabBarFontFamily?: string;
|
|
@@ -91,6 +94,14 @@ export interface NativeProps extends ViewProps {
|
|
|
91
94
|
type CollapsiblePagerViewNativeType = HostComponent<NativeProps>;
|
|
92
95
|
|
|
93
96
|
export interface NativeCommands {
|
|
97
|
+
scrollHeaderToOffset: (
|
|
98
|
+
viewRef: React.ElementRef<CollapsiblePagerViewNativeType>,
|
|
99
|
+
offset: Double
|
|
100
|
+
) => void;
|
|
101
|
+
scrollHeaderBy: (
|
|
102
|
+
viewRef: React.ElementRef<CollapsiblePagerViewNativeType>,
|
|
103
|
+
delta: Double
|
|
104
|
+
) => void;
|
|
94
105
|
scrollToTop: (
|
|
95
106
|
viewRef: React.ElementRef<CollapsiblePagerViewNativeType>,
|
|
96
107
|
target: Int32,
|
|
@@ -112,6 +123,8 @@ export interface NativeCommands {
|
|
|
112
123
|
|
|
113
124
|
export const Commands: NativeCommands = codegenNativeCommands<NativeCommands>({
|
|
114
125
|
supportedCommands: [
|
|
126
|
+
"scrollHeaderToOffset",
|
|
127
|
+
"scrollHeaderBy",
|
|
115
128
|
"scrollToTop",
|
|
116
129
|
"setPage",
|
|
117
130
|
"setPageWithoutAnimation",
|