@onekeyfe/react-native-pager-view 6.7.0-3 → 6.7.0-30
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 +21 -0
- package/android/build.gradle +1 -0
- package/android/src/androidTest/AndroidManifest.xml +7 -0
- package/android/src/androidTest/java/com/reactnativepagerview/CollapsiblePagerTabReservationTest.kt +476 -0
- package/android/src/main/java/com/reactnativepagerview/CollapsiblePagerHost.kt +215 -39
- package/android/src/main/java/com/reactnativepagerview/CollapsiblePagerNativeHeaders.kt +518 -21
- package/android/src/main/java/com/reactnativepagerview/CollapsiblePagerViewManager.kt +40 -0
- package/android/src/main/java/com/reactnativepagerview/NativeScrollerScrollAwayInsets.kt +19 -0
- package/android/src/main/java/com/reactnativepagerview/NativeScrollerView.kt +50 -6
- package/android/src/main/java/com/reactnativepagerview/NestedScrollableHost.kt +8 -2
- package/android/src/main/java/com/reactnativepagerview/event/NativeHeaderPressEvent.kt +8 -0
- package/android/src/test/java/com/reactnativepagerview/NativeScrollerScrollAwayInsetsTest.kt +40 -0
- package/docs/SPEC.md +606 -10
- package/ios/RNCCollapsiblePagerViewComponentView.mm +1903 -91
- package/ios/RNCNativeScrollerComponentView.h +2 -0
- package/ios/RNCNativeScrollerComponentView.mm +42 -0
- package/ios/tests/RNCCollapsiblePagerFirstFrameTests.mm +562 -1
- package/ios/tests/RNCCollapsiblePagerHitTestTests.mm +1116 -0
- package/ios/tests/RNCCollapsiblePagerPressCancellationTests.mm +74 -9
- package/ios/tests/RNCCollapsiblePagerRefreshControlTests.mm +50 -0
- package/lib/module/CollapsiblePagerView.js +70 -11
- package/lib/module/CollapsiblePagerView.web.js +532 -8
- package/lib/module/CollapsiblePagerViewNativeComponent.ts +57 -42
- package/lib/module/NativeScroller.web.js +3 -0
- package/lib/module/NativeScrollerNativeComponent.ts +42 -46
- package/lib/module/PagerViewNativeComponent.ts +20 -25
- package/lib/module/WebCollapsiblePagerPage.js +7 -2
- package/lib/module/index.native.js +9 -0
- package/lib/typescript/src/CollapsiblePagerView.d.ts +42 -4
- package/lib/typescript/src/CollapsiblePagerView.web.d.ts +48 -2
- package/lib/typescript/src/CollapsiblePagerViewNativeComponent.d.ts +54 -38
- package/lib/typescript/src/NativeScroller.d.ts +5 -3
- package/lib/typescript/src/NativeScroller.web.d.ts +1 -1
- package/lib/typescript/src/NativeScrollerNativeComponent.d.ts +47 -48
- package/lib/typescript/src/PagerView.d.ts +1 -1
- package/lib/typescript/src/PagerView.web.d.ts +1 -1
- package/lib/typescript/src/PagerViewNativeComponent.d.ts +20 -21
- package/lib/typescript/src/WebCollapsiblePagerPage.d.ts +1 -1
- package/lib/typescript/src/index.native.d.ts +13 -0
- package/lib/typescript/src/usePagerView.d.ts +2 -2
- package/lib/typescript/src/utils.d.ts +2 -2
- package/package.json +22 -7
- package/react-native-pager-view.podspec +1 -0
- package/src/CollapsiblePagerView.tsx +179 -12
- package/src/CollapsiblePagerView.web.tsx +486 -7
- package/src/CollapsiblePagerViewNativeComponent.ts +57 -42
- package/src/NativeScroller.tsx +14 -4
- package/src/NativeScroller.web.tsx +15 -1
- package/src/NativeScrollerNativeComponent.ts +42 -46
- package/src/PagerViewNativeComponent.ts +20 -25
- package/src/WebCollapsiblePagerPage.tsx +7 -2
- package/src/index.native.tsx +30 -0
|
@@ -668,6 +668,7 @@ typedef struct __IOHIDEvent *RNCTestHIDEventRef;
|
|
|
668
668
|
@property (nonatomic, strong) RNCSynthesizedTouchDriver *driver;
|
|
669
669
|
@property (nonatomic, strong) UIView *firstPage;
|
|
670
670
|
@property (nonatomic) NSUInteger longPressBegins;
|
|
671
|
+
@property (nonatomic, strong) XCTestExpectation *longPressExpectation;
|
|
671
672
|
@property (nonatomic) NSUInteger pagerPanBegins;
|
|
672
673
|
@end
|
|
673
674
|
|
|
@@ -763,6 +764,26 @@ typedef struct __IOHIDEvent *RNCTestHIDEventRef;
|
|
|
763
764
|
XCTAssertTrue([pager isKindOfClass:NSClassFromString(@"RNCCollapsiblePagerDirectScrollView")]);
|
|
764
765
|
}
|
|
765
766
|
|
|
767
|
+
- (void)configureSegmentedTabsForTwoPages
|
|
768
|
+
{
|
|
769
|
+
auto baseline = std::make_shared<RNCCollapsiblePagerViewProps>();
|
|
770
|
+
baseline->nativeSmoothHeaderScrollEnabled = true;
|
|
771
|
+
baseline->headerHeight = 120;
|
|
772
|
+
baseline->stickyHeaderHeight = 44;
|
|
773
|
+
auto segmented = std::make_shared<RNCCollapsiblePagerViewProps>();
|
|
774
|
+
segmented->nativeSmoothHeaderScrollEnabled = true;
|
|
775
|
+
segmented->headerHeight = 120;
|
|
776
|
+
segmented->stickyHeaderHeight = 56;
|
|
777
|
+
segmented->nativeTabBarItems =
|
|
778
|
+
R"([{"key":"recent","title":"Recents"},{"key":"account","title":"Accounts"}])";
|
|
779
|
+
segmented->nativeTabBarVariant = "segmented";
|
|
780
|
+
segmented->nativeTabBarHeight = 56;
|
|
781
|
+
segmented->nativeTabBarContentPaddingHorizontal = 20;
|
|
782
|
+
segmented->nativeTabBarContentPaddingVertical = 12;
|
|
783
|
+
[self.pager updateProps:segmented oldProps:baseline];
|
|
784
|
+
[self.window layoutIfNeeded];
|
|
785
|
+
}
|
|
786
|
+
|
|
766
787
|
- (void)recordPagerPan:(UIPanGestureRecognizer *)pan
|
|
767
788
|
{
|
|
768
789
|
if (pan.state == UIGestureRecognizerStateBegan) self.pagerPanBegins += 1;
|
|
@@ -904,6 +925,51 @@ typedef struct __IOHIDEvent *RNCTestHIDEventRef;
|
|
|
904
925
|
XCTAssertEqual(self.handler.events.count, eventsBeforeLift);
|
|
905
926
|
}
|
|
906
927
|
|
|
928
|
+
- (void)testSegmentedThumbTracksDeliveredPagerDragAndReverseBeforeLift
|
|
929
|
+
{
|
|
930
|
+
[self assertFixtureIsReadyForDelivery];
|
|
931
|
+
[self assertDirectPagerForRegression];
|
|
932
|
+
[self configureSegmentedTabsForTwoPages];
|
|
933
|
+
|
|
934
|
+
UIScrollView *pagerScrollView = [self.pager valueForKey:@"pagerScrollView"];
|
|
935
|
+
UIView *tabBar = [self.pager valueForKey:@"nativeTabBarView"];
|
|
936
|
+
UIView *thumb = [tabBar valueForKey:@"indicatorView"];
|
|
937
|
+
NSArray<UIButton *> *buttons = [tabBar valueForKey:@"buttons"];
|
|
938
|
+
XCTAssertEqual(buttons.count, 2);
|
|
939
|
+
XCTAssertFalse(tabBar.hidden);
|
|
940
|
+
XCTAssertEqualWithAccuracy(CGRectGetHeight(tabBar.bounds), 56, 0.01);
|
|
941
|
+
CGFloat firstThumbX = CGRectGetMinX(buttons[0].frame) + 2;
|
|
942
|
+
CGFloat secondThumbX = CGRectGetMinX(buttons[1].frame) + 2;
|
|
943
|
+
XCTAssertEqualWithAccuracy(CGRectGetMinX(thumb.frame), firstThumbX, 1);
|
|
944
|
+
|
|
945
|
+
CGPoint point = CGPointMake(350, 600);
|
|
946
|
+
UITouch *touch = [self.driver beginAt:point];
|
|
947
|
+
CGFloat largestOffset = 0;
|
|
948
|
+
NSUInteger intermediateFrames = 0;
|
|
949
|
+
for (NSInteger step = 1; step <= 18; ++step) {
|
|
950
|
+
[self.driver move:touch to:CGPointMake(point.x - 14 * step, point.y)];
|
|
951
|
+
CGFloat offset = pagerScrollView.contentOffset.x;
|
|
952
|
+
largestOffset = MAX(largestOffset, offset);
|
|
953
|
+
if (offset > 1 && offset < CGRectGetWidth(pagerScrollView.bounds) - 1) {
|
|
954
|
+
CGFloat progress = offset / CGRectGetWidth(pagerScrollView.bounds);
|
|
955
|
+
XCTAssertEqualWithAccuracy(CGRectGetMinX(thumb.frame),
|
|
956
|
+
firstThumbX + (secondThumbX - firstThumbX) * progress, 1);
|
|
957
|
+
intermediateFrames += 1;
|
|
958
|
+
}
|
|
959
|
+
}
|
|
960
|
+
XCTAssertTrue(pagerScrollView.isDragging);
|
|
961
|
+
XCTAssertGreaterThan(largestOffset, 80);
|
|
962
|
+
XCTAssertGreaterThan(intermediateFrames, 2);
|
|
963
|
+
|
|
964
|
+
for (NSInteger step = 17; step >= 0; --step) {
|
|
965
|
+
[self.driver move:touch to:CGPointMake(point.x - 14 * step, point.y)];
|
|
966
|
+
}
|
|
967
|
+
// UIKit can briefly bounce past the leading edge before the finger lifts.
|
|
968
|
+
XCTAssertLessThan(fabs(pagerScrollView.contentOffset.x), 10);
|
|
969
|
+
XCTAssertEqualWithAccuracy(CGRectGetMinX(thumb.frame), firstThumbX, 1);
|
|
970
|
+
[self.driver end:touch];
|
|
971
|
+
}
|
|
972
|
+
|
|
907
973
|
- (void)testStationaryTapKeepsReactPress
|
|
908
974
|
{
|
|
909
975
|
[self assertFixtureIsReadyForDelivery];
|
|
@@ -1001,7 +1067,10 @@ typedef struct __IOHIDEvent *RNCTestHIDEventRef;
|
|
|
1001
1067
|
|
|
1002
1068
|
- (void)nestedLongPress:(UILongPressGestureRecognizer *)recognizer
|
|
1003
1069
|
{
|
|
1004
|
-
if (recognizer.state == UIGestureRecognizerStateBegan)
|
|
1070
|
+
if (recognizer.state == UIGestureRecognizerStateBegan) {
|
|
1071
|
+
self.longPressBegins += 1;
|
|
1072
|
+
[self.longPressExpectation fulfill];
|
|
1073
|
+
}
|
|
1005
1074
|
}
|
|
1006
1075
|
|
|
1007
1076
|
- (CGPoint)pressPointInNestedScrollView:(UIScrollView *)scroll
|
|
@@ -1022,14 +1091,12 @@ typedef struct __IOHIDEvent *RNCTestHIDEventRef;
|
|
|
1022
1091
|
[pager addGestureRecognizer:longPress];
|
|
1023
1092
|
// Exercise production wiring after a root recognizer is attached.
|
|
1024
1093
|
((void (*)(id, SEL))objc_msgSend)(self.pager, NSSelectorFromString(@"connectVerticalPagerGuard"));
|
|
1094
|
+
self.longPressExpectation = [self expectationWithDescription:@"root long press recognized before finger-up"];
|
|
1025
1095
|
UITouch *touch = [self.driver beginAt:[self pressPoint]];
|
|
1026
1096
|
UIGestureRecognizer *guard = [self.pager valueForKey:@"verticalPagerGesture"];
|
|
1027
1097
|
XCTAssertEqual(guard.state, UIGestureRecognizerStatePossible);
|
|
1028
1098
|
XCTAssertEqual(pager.panGestureRecognizer.minimumNumberOfTouches, 2);
|
|
1029
|
-
|
|
1030
|
-
dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(0.25 * NSEC_PER_SEC)),
|
|
1031
|
-
dispatch_get_main_queue(), ^{ [hold fulfill]; });
|
|
1032
|
-
[self waitForExpectations:@[hold] timeout:2];
|
|
1099
|
+
[self waitForExpectations:@[self.longPressExpectation] timeout:2];
|
|
1033
1100
|
NSLog(@"[PagerPressDelivery] rootLongPress begins=%lu state=%ld touchPhase=%ld guardState=%ld pagerPanMinTouches=%lu",
|
|
1034
1101
|
(unsigned long)self.longPressBegins, (long)longPress.state, (long)touch.phase,
|
|
1035
1102
|
(long)guard.state, (unsigned long)pager.panGestureRecognizer.minimumNumberOfTouches);
|
|
@@ -1045,14 +1112,12 @@ typedef struct __IOHIDEvent *RNCTestHIDEventRef;
|
|
|
1045
1112
|
- (void)testNestedStationaryNativeLongPressRecognizesBeforeFingerUp
|
|
1046
1113
|
{
|
|
1047
1114
|
UIScrollView *scroll = [self mountNestedHorizontalScrollView];
|
|
1115
|
+
self.longPressExpectation = [self expectationWithDescription:@"nested long press recognized before finger-up"];
|
|
1048
1116
|
UITouch *touch = [self.driver beginAt:[self pressPointInNestedScrollView:scroll]];
|
|
1049
1117
|
UIGestureRecognizer *guard = [self.pager valueForKey:@"verticalPagerGesture"];
|
|
1050
1118
|
XCTAssertEqual(guard.state, UIGestureRecognizerStatePossible);
|
|
1051
1119
|
XCTAssertEqual(scroll.panGestureRecognizer.minimumNumberOfTouches, 2);
|
|
1052
|
-
|
|
1053
|
-
dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(0.25 * NSEC_PER_SEC)),
|
|
1054
|
-
dispatch_get_main_queue(), ^{ [hold fulfill]; });
|
|
1055
|
-
[self waitForExpectations:@[hold] timeout:2];
|
|
1120
|
+
[self waitForExpectations:@[self.longPressExpectation] timeout:2];
|
|
1056
1121
|
// The real UIKit target action must arrive while the finger is still down.
|
|
1057
1122
|
XCTAssertEqual(self.longPressBegins, 1);
|
|
1058
1123
|
XCTAssertEqual(touch.phase, UITouchPhaseBegan);
|
|
@@ -60,6 +60,56 @@
|
|
|
60
60
|
XCTAssertEqualWithAccuracy(control.bounds.origin.x, 3, 0.001);
|
|
61
61
|
}
|
|
62
62
|
|
|
63
|
+
- (void)testRefreshLayerWindowGeometryStartsBelowFixedOverlay
|
|
64
|
+
{
|
|
65
|
+
for (NSNumber *overlayHeight in @[@0, @162]) {
|
|
66
|
+
CGFloat fixedHeight = overlayHeight.doubleValue;
|
|
67
|
+
CGFloat baseInset = fixedHeight + 180 + 44;
|
|
68
|
+
UIWindow *window = [[UIWindow alloc] initWithFrame:CGRectMake(0, 0, 390, 844)];
|
|
69
|
+
UIViewController *root = [UIViewController new];
|
|
70
|
+
window.rootViewController = root;
|
|
71
|
+
UIScrollView *scroll = [[UIScrollView alloc] initWithFrame:window.bounds];
|
|
72
|
+
scroll.contentInsetAdjustmentBehavior = UIScrollViewContentInsetAdjustmentNever;
|
|
73
|
+
scroll.contentSize = CGSizeMake(390, 1500);
|
|
74
|
+
scroll.contentInset = UIEdgeInsetsMake(baseInset + 60, 0, 0, 0);
|
|
75
|
+
scroll.contentOffset = CGPointMake(0, -baseInset - 102);
|
|
76
|
+
[root.view addSubview:scroll];
|
|
77
|
+
UIView *overlay = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 390, fixedHeight)];
|
|
78
|
+
[root.view addSubview:overlay];
|
|
79
|
+
UIRefreshControl *control = [UIRefreshControl new];
|
|
80
|
+
scroll.refreshControl = control;
|
|
81
|
+
window.hidden = NO;
|
|
82
|
+
[root.view layoutIfNeeded];
|
|
83
|
+
[control layoutIfNeeded];
|
|
84
|
+
// Match the control's window position recorded during a real refresh drag.
|
|
85
|
+
control.frame = [scroll convertRect:CGRectMake(0, baseInset, 390, 60)
|
|
86
|
+
fromView:window];
|
|
87
|
+
|
|
88
|
+
RNCCollapsiblePagerViewComponentView *pager = [self pagerWithHeader:180];
|
|
89
|
+
[pager setValue:@(fixedHeight) forKey:@"topOverlayHeight"];
|
|
90
|
+
if (fixedHeight > 0) [pager setValue:overlay forKey:@"topOverlayView"];
|
|
91
|
+
[pager updateRefreshControlForScrollView:scroll];
|
|
92
|
+
[CATransaction flush];
|
|
93
|
+
CALayer *firstChild = control.layer.sublayers.firstObject;
|
|
94
|
+
XCTAssertNotNil(firstChild);
|
|
95
|
+
XCTAssertEqual(control.window, window);
|
|
96
|
+
CGRect overlayWindow = [overlay convertRect:overlay.bounds toView:window];
|
|
97
|
+
CGRect controlWindow = [control convertRect:control.bounds toView:window];
|
|
98
|
+
CGRect childWindow = [firstChild convertRect:firstChild.bounds toLayer:window.layer];
|
|
99
|
+
XCTAssertEqualWithAccuracy(CGRectGetMinY(controlWindow), baseInset, 0.01);
|
|
100
|
+
XCTAssertEqualWithAccuracy(CGRectGetMinY(childWindow),
|
|
101
|
+
CGRectGetMaxY(overlayWindow), 0.01);
|
|
102
|
+
XCTAssertEqualWithAccuracy(scroll.contentInset.top, baseInset + 60, 0.01);
|
|
103
|
+
[pager updateRefreshControlForScrollView:scroll];
|
|
104
|
+
XCTAssertEqualWithAccuracy(CGRectGetMinY(
|
|
105
|
+
[firstChild convertRect:firstChild.bounds toLayer:window.layer]),
|
|
106
|
+
CGRectGetMaxY(overlayWindow), 0.01);
|
|
107
|
+
[pager releaseRefreshControlForScrollView:scroll];
|
|
108
|
+
XCTAssertTrue(CATransform3DIsIdentity(control.layer.sublayerTransform));
|
|
109
|
+
window.hidden = YES;
|
|
110
|
+
}
|
|
111
|
+
}
|
|
112
|
+
|
|
63
113
|
- (void)testUIKitSizeChangesAndRefreshCycleDoNotAccumulateOffset
|
|
64
114
|
{
|
|
65
115
|
RNCCollapsiblePagerViewComponentView *pager = [self pagerWithHeader:64];
|
|
@@ -1,9 +1,23 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
|
|
3
3
|
import React from "react";
|
|
4
|
-
import { I18nManager, Platform, StyleSheet, View } from "react-native";
|
|
4
|
+
import { I18nManager, Platform, StyleSheet, View, processColor } from "react-native";
|
|
5
5
|
import CollapsiblePagerViewNativeComponent, { Commands as CollapsiblePagerViewNativeCommands } from "./CollapsiblePagerViewNativeComponent";
|
|
6
6
|
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
7
|
+
const nativeToolbar = toolbar => {
|
|
8
|
+
if (!toolbar) return undefined;
|
|
9
|
+
return Object.fromEntries(Object.entries(toolbar).map(([key, item]) => {
|
|
10
|
+
const color = processColor(item.iconColor ?? "#000000");
|
|
11
|
+
const argb = typeof color === "number" ? color >>> 0 : 0xff000000;
|
|
12
|
+
return [key, {
|
|
13
|
+
...item,
|
|
14
|
+
iconColor: `rgba(${argb >>> 16 & 255},${argb >>> 8 & 255},${argb & 255},${Math.round((argb >>> 24) / 255 * 1000000) / 1000000})`,
|
|
15
|
+
selectedBackgroundColor: processColor(item.selectedBackgroundColor ?? "transparent"),
|
|
16
|
+
hoverBackgroundColor: processColor(item.hoverBackgroundColor ?? "transparent"),
|
|
17
|
+
pressedBackgroundColor: processColor(item.pressedBackgroundColor ?? "transparent")
|
|
18
|
+
}];
|
|
19
|
+
}));
|
|
20
|
+
};
|
|
7
21
|
const pageIndex = value => {
|
|
8
22
|
const index = Math.trunc(value);
|
|
9
23
|
return Number.isFinite(index) ? index : null;
|
|
@@ -23,7 +37,7 @@ const pageKey = (child, index) => {
|
|
|
23
37
|
*/
|
|
24
38
|
export class CollapsiblePagerView extends React.PureComponent {
|
|
25
39
|
state = {
|
|
26
|
-
topOverlayHeight:
|
|
40
|
+
topOverlayHeight: null,
|
|
27
41
|
selectedPage: clampedPageIndex(this.props.initialPage ?? 0, React.Children.toArray(this.props.children).length),
|
|
28
42
|
transientRetainedPages: []
|
|
29
43
|
};
|
|
@@ -41,7 +55,14 @@ export class CollapsiblePagerView extends React.PureComponent {
|
|
|
41
55
|
componentDidMount() {
|
|
42
56
|
this.notifyMountedPagesChanged();
|
|
43
57
|
}
|
|
44
|
-
componentDidUpdate() {
|
|
58
|
+
componentDidUpdate(previousProps) {
|
|
59
|
+
const previousOverlayEnabled = previousProps.topOverlay != null && (previousProps.topScrollEdgeEffect === "hard" || previousProps.topScrollEdgeEffect === "soft");
|
|
60
|
+
const overlayEnabled = this.props.topOverlay != null && (this.props.topScrollEdgeEffect === "hard" || this.props.topScrollEdgeEffect === "soft");
|
|
61
|
+
if (previousOverlayEnabled && !overlayEnabled && this.state.topOverlayHeight !== null) {
|
|
62
|
+
this.setState({
|
|
63
|
+
topOverlayHeight: null
|
|
64
|
+
});
|
|
65
|
+
}
|
|
45
66
|
const pageCount = this.pages().length;
|
|
46
67
|
const selectedPage = clampedPageIndex(this.state.selectedPage, pageCount);
|
|
47
68
|
if (selectedPage !== this.state.selectedPage) {
|
|
@@ -55,7 +76,7 @@ export class CollapsiblePagerView extends React.PureComponent {
|
|
|
55
76
|
setPage = selectedPage => {
|
|
56
77
|
const position = pageIndex(selectedPage);
|
|
57
78
|
if (this.nativeRef && position !== null && position >= 0 && position < this.pages().length) {
|
|
58
|
-
if (this.nativeTabBarEnabled()) {
|
|
79
|
+
if (this.nativeTabBarEnabled() && !this.props.nativeTabBar?.controlled) {
|
|
59
80
|
this.dispatchNativeTabPageCommand(position, true);
|
|
60
81
|
} else {
|
|
61
82
|
CollapsiblePagerViewNativeCommands.setPage(this.nativeRef, position);
|
|
@@ -65,7 +86,7 @@ export class CollapsiblePagerView extends React.PureComponent {
|
|
|
65
86
|
setPageWithoutAnimation = selectedPage => {
|
|
66
87
|
const position = pageIndex(selectedPage);
|
|
67
88
|
if (this.nativeRef && position !== null && position >= 0 && position < this.pages().length) {
|
|
68
|
-
if (this.nativeTabBarEnabled()) {
|
|
89
|
+
if (this.nativeTabBarEnabled() && !this.props.nativeTabBar?.controlled) {
|
|
69
90
|
this.dispatchNativeTabPageCommand(position, false);
|
|
70
91
|
} else {
|
|
71
92
|
CollapsiblePagerViewNativeCommands.setPageWithoutAnimation(this.nativeRef, position);
|
|
@@ -75,6 +96,12 @@ export class CollapsiblePagerView extends React.PureComponent {
|
|
|
75
96
|
scrollToPageTop = options => {
|
|
76
97
|
if (this.nativeRef) CollapsiblePagerViewNativeCommands.scrollToTop(this.nativeRef, 0, options?.animated ?? true);
|
|
77
98
|
};
|
|
99
|
+
scrollHeaderBy = delta => {
|
|
100
|
+
if (this.nativeRef && Number.isFinite(delta)) CollapsiblePagerViewNativeCommands.scrollHeaderBy(this.nativeRef, delta);
|
|
101
|
+
};
|
|
102
|
+
scrollHeaderToOffset = offset => {
|
|
103
|
+
if (this.nativeRef && Number.isFinite(offset)) CollapsiblePagerViewNativeCommands.scrollHeaderToOffset(this.nativeRef, offset);
|
|
104
|
+
};
|
|
78
105
|
scrollToStickyTop = options => {
|
|
79
106
|
if (this.nativeRef) CollapsiblePagerViewNativeCommands.scrollToTop(this.nativeRef, 1, options?.animated ?? true);
|
|
80
107
|
};
|
|
@@ -89,7 +116,7 @@ export class CollapsiblePagerView extends React.PureComponent {
|
|
|
89
116
|
nativeTabBarEnabled() {
|
|
90
117
|
return (Platform.OS === "ios" || Platform.OS === "android") && !!this.props.nativeTabBar?.items.length;
|
|
91
118
|
}
|
|
92
|
-
dispatchNativeTabPageCommand(position, animated) {
|
|
119
|
+
dispatchNativeTabPageCommand(position, animated, expectedKey) {
|
|
93
120
|
const commandId = ++this.nativeTabCommandId;
|
|
94
121
|
this.nativeTabCommandQueuedDuringScroll = this.nativePagerScrollState !== "idle";
|
|
95
122
|
this.latestNativeTabTarget = position;
|
|
@@ -97,7 +124,7 @@ export class CollapsiblePagerView extends React.PureComponent {
|
|
|
97
124
|
transientRetainedPages: state.transientRetainedPages.includes(position) ? state.transientRetainedPages : [...state.transientRetainedPages, position]
|
|
98
125
|
}), () => {
|
|
99
126
|
requestAnimationFrame(() => {
|
|
100
|
-
if (commandId !== this.nativeTabCommandId || !this.nativeRef) {
|
|
127
|
+
if (commandId !== this.nativeTabCommandId || !this.nativeRef || expectedKey !== undefined && (!this.nativeTabBarEnabled() || this.props.nativeTabBar?.items[position]?.key !== expectedKey)) {
|
|
101
128
|
return;
|
|
102
129
|
}
|
|
103
130
|
this.dispatchedNativeTabTarget = position;
|
|
@@ -179,13 +206,20 @@ export class CollapsiblePagerView extends React.PureComponent {
|
|
|
179
206
|
};
|
|
180
207
|
onNativeTabPress = event => {
|
|
181
208
|
const position = pageIndex(event.nativeEvent.position);
|
|
182
|
-
if (
|
|
209
|
+
if (!this.nativeTabBarEnabled() || position === null || this.props.nativeTabBar?.items[position]?.key !== event.nativeEvent.key) {
|
|
210
|
+
return;
|
|
211
|
+
}
|
|
212
|
+
if (!this.props.nativeTabBar?.controlled && position >= 0 && position < this.pages().length && (position !== this.state.selectedPage || this.latestNativeTabTarget !== null)) {
|
|
183
213
|
// Selection state lags an in-flight transition until native reports it.
|
|
184
214
|
const currentPage = this.dispatchedNativeTabTarget ?? this.state.selectedPage;
|
|
185
|
-
this.dispatchNativeTabPageCommand(position, this.props.nativeTabPressAnimationEnabled ?? Math.abs(position - currentPage) <= 1);
|
|
215
|
+
this.dispatchNativeTabPageCommand(position, this.props.nativeTabPressAnimationEnabled ?? Math.abs(position - currentPage) <= 1, event.nativeEvent.key);
|
|
186
216
|
}
|
|
187
217
|
this.props.onNativeTabPress?.(event);
|
|
188
218
|
};
|
|
219
|
+
onNativeToolbarPress = event => {
|
|
220
|
+
if (!this.props.nativeTabBar?.toolbar?.[event.nativeEvent.key]?.iconName) return;
|
|
221
|
+
this.props.onNativeToolbarPress?.(event);
|
|
222
|
+
};
|
|
189
223
|
onNativeSubHeaderPress = event => {
|
|
190
224
|
this.props.onNativeSubHeaderPress?.(event);
|
|
191
225
|
};
|
|
@@ -196,7 +230,9 @@ export class CollapsiblePagerView extends React.PureComponent {
|
|
|
196
230
|
stickyHeader,
|
|
197
231
|
headerHeight,
|
|
198
232
|
stickyHeaderHeight,
|
|
233
|
+
stickyHeaderHeights,
|
|
199
234
|
topOverlay,
|
|
235
|
+
topOverlayHeightHint,
|
|
200
236
|
externalTopOverlayTag,
|
|
201
237
|
topScrollEdgeEffect,
|
|
202
238
|
topOverlayColorScheme,
|
|
@@ -219,11 +255,16 @@ export class CollapsiblePagerView extends React.PureComponent {
|
|
|
219
255
|
const supportsTopScrollEdge = Platform.OS === "ios" && parseInt(String(Platform.Version), 10) >= 26;
|
|
220
256
|
const scrollEdgeEnabled = supportsTopScrollEdge && (topScrollEdgeEffect === "hard" || topScrollEdgeEffect === "soft");
|
|
221
257
|
const hasTopOverlay = scrollEdgeEnabled && topOverlay != null;
|
|
258
|
+
const initialTopOverlayHeight = typeof topOverlayHeightHint === "number" && Number.isFinite(topOverlayHeightHint) ? Math.max(0, Math.ceil(topOverlayHeightHint)) : 0;
|
|
222
259
|
const pageKeys = pages.map(pageKey);
|
|
223
260
|
const retained = new Set(this.mountedPages(pages.length));
|
|
224
261
|
const deducedLayoutDirection = !layoutDirection || layoutDirection === "locale" ? I18nManager.isRTL ? "rtl" : "ltr" : layoutDirection;
|
|
225
262
|
const nativeTabBarEnabled = (Platform.OS === "ios" || Platform.OS === "android") && !!nativeTabBar?.items.length;
|
|
226
263
|
const nativeTabBarStyle = nativeTabBar?.style;
|
|
264
|
+
const requestedContentPaddingVertical = nativeTabBarStyle?.contentPaddingVertical;
|
|
265
|
+
const nativeTabBarContentPaddingVertical = typeof requestedContentPaddingVertical === "number" && Number.isFinite(requestedContentPaddingVertical) && requestedContentPaddingVertical >= 0 ? requestedContentPaddingVertical : 0;
|
|
266
|
+
const requestedTrailingReservedWidth = nativeTabBarStyle?.trailingReservedWidth;
|
|
267
|
+
const nativeTabBarTrailingReservedWidth = typeof requestedTrailingReservedWidth === "number" && Number.isFinite(requestedTrailingReservedWidth) && requestedTrailingReservedWidth >= 0 ? requestedTrailingReservedWidth : 0;
|
|
227
268
|
const nativeSubHeaderEnabled = (Platform.OS === "ios" || Platform.OS === "android") && !!nativeSubHeader?.items.length;
|
|
228
269
|
const nativeSubHeaderStyle = nativeSubHeader?.style;
|
|
229
270
|
const nativeSubHeaderConfig = nativeSubHeaderEnabled ? JSON.stringify({
|
|
@@ -243,20 +284,38 @@ export class CollapsiblePagerView extends React.PureComponent {
|
|
|
243
284
|
offscreenPageLimit: Math.max(1, offscreenPageLimit ?? 1),
|
|
244
285
|
headerHeight: Math.max(0, Math.round(headerHeight)),
|
|
245
286
|
stickyHeaderHeight: Math.max(0, Math.round(stickyHeaderHeight)),
|
|
287
|
+
stickyHeaderHeights: Platform.OS === "ios" && stickyHeaderHeights ? JSON.stringify(stickyHeaderHeights.slice(0, pages.length).map(height => Number.isFinite(height) && height >= 0 ? Math.round(height) : null)) : undefined,
|
|
246
288
|
topScrollEdgeEffect: scrollEdgeEnabled ? topScrollEdgeEffect : "none",
|
|
247
289
|
topOverlayColorScheme: scrollEdgeEnabled ? topOverlayColorScheme : undefined,
|
|
248
|
-
topOverlayHeight: hasTopOverlay ? this.state.topOverlayHeight : 0,
|
|
290
|
+
topOverlayHeight: hasTopOverlay ? this.state.topOverlayHeight ?? initialTopOverlayHeight : 0,
|
|
249
291
|
externalTopOverlayTag: supportsTopScrollEdge && !hasTopOverlay ? externalTopOverlayTag ?? 0 : 0,
|
|
250
292
|
nativeSmoothHeaderScrollEnabled: nativeSmoothHeaderScrollEnabled,
|
|
251
293
|
pageKeys: JSON.stringify(pageKeys),
|
|
252
294
|
retainedPages: JSON.stringify([...retained]),
|
|
253
295
|
onPageSelected: this.onPageSelected,
|
|
254
296
|
onPageScrollStateChanged: this.onPageScrollStateChanged,
|
|
297
|
+
nativeTabBarConfig: nativeTabBarEnabled ? JSON.stringify({
|
|
298
|
+
controlled: nativeTabBar.controlled,
|
|
299
|
+
selectedKey: nativeTabBar.selectedKey,
|
|
300
|
+
pageKeys: (() => {
|
|
301
|
+
const keys = [];
|
|
302
|
+
React.Children.forEach(this.props.children, child => {
|
|
303
|
+
if (child !== null && child !== undefined && typeof child !== "boolean") keys.push(pageKey(child, keys.length));
|
|
304
|
+
});
|
|
305
|
+
return keys;
|
|
306
|
+
})(),
|
|
307
|
+
toolbar: nativeToolbar(nativeTabBar.toolbar),
|
|
308
|
+
activeFontFamily: nativeTabBar.style?.activeFontFamily
|
|
309
|
+
}) : undefined,
|
|
310
|
+
onNativeToolbarPress: this.onNativeToolbarPress,
|
|
255
311
|
nativeTabBarItems: nativeTabBarEnabled ? JSON.stringify(nativeTabBar.items) : undefined,
|
|
256
312
|
nativeTabBarHeight: nativeTabBarEnabled ? nativeTabBarStyle?.height ?? 44 : undefined,
|
|
313
|
+
nativeTabBarVariant: nativeTabBarEnabled ? nativeTabBarStyle?.variant ?? "underline" : undefined,
|
|
314
|
+
nativeTabBarTrailingReservedWidth: nativeTabBarEnabled ? nativeTabBarTrailingReservedWidth : 0,
|
|
257
315
|
nativeTabBarContentPaddingHorizontal: nativeTabBarEnabled ? nativeTabBarStyle?.contentPaddingHorizontal ?? 20 : undefined,
|
|
316
|
+
nativeTabBarContentPaddingVertical: nativeTabBarEnabled ? nativeTabBarContentPaddingVertical : undefined,
|
|
258
317
|
nativeTabBarItemSpacing: nativeTabBarEnabled ? nativeTabBarStyle?.itemSpacing ?? 8 : undefined,
|
|
259
|
-
nativeTabBarFontSize: nativeTabBarEnabled ? nativeTabBarStyle?.fontSize ?? 16 : undefined,
|
|
318
|
+
nativeTabBarFontSize: nativeTabBarEnabled ? nativeTabBarStyle?.fontSize ?? (nativeTabBarStyle?.variant === "text" ? 18 : 16) : undefined,
|
|
260
319
|
nativeTabBarFontFamily: nativeTabBarEnabled ? nativeTabBarStyle?.fontFamily : undefined,
|
|
261
320
|
nativeTabBarBackgroundColor: nativeTabBarEnabled ? nativeTabBarStyle?.backgroundColor : undefined,
|
|
262
321
|
nativeTabBarActiveTextColor: nativeTabBarEnabled ? nativeTabBarStyle?.activeTextColor : undefined,
|