@onekeyfe/react-native-pager-view 6.7.0-alpha.344 → 6.7.0-alpha.359

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.
@@ -2,13 +2,35 @@
2
2
 
3
3
  #import "RNCCollapsiblePagerViewComponentView.h"
4
4
  #import "RNCPagerViewComponentView.h"
5
+ #import <React/RCTViewComponentView.h>
5
6
  #import <react/renderer/components/pagerview/Props.h>
7
+ #import <react/renderer/components/view/ViewProps.h>
6
8
 
7
9
  using namespace facebook::react;
8
10
 
9
11
  @interface RNCCollapsiblePagerViewComponentView (ScrollEdgeTesting)
10
12
  - (void)updateTopScrollEdgeForScrollView:(UIScrollView *)scrollView;
11
13
  - (void)updateScrollEdgeContentMasks;
14
+ - (void)layoutSharedHeaders;
15
+ @end
16
+
17
+ @interface UIView (NativeTabReservationTesting)
18
+ - (void)updateItemsJSON:(NSString *)itemsJSON;
19
+ - (void)updateStyleWithHeight:(CGFloat)height
20
+ variant:(NSString *)variant
21
+ contentPaddingHorizontal:(CGFloat)contentPaddingHorizontal
22
+ contentPaddingVertical:(CGFloat)contentPaddingVertical
23
+ itemSpacing:(CGFloat)itemSpacing
24
+ fontSize:(CGFloat)fontSize
25
+ fontFamily:(NSString *)fontFamily
26
+ backgroundColor:(UIColor *)backgroundColor
27
+ activeTextColor:(UIColor *)activeTextColor
28
+ inactiveTextColor:(UIColor *)inactiveTextColor
29
+ indicatorColor:(UIColor *)indicatorColor
30
+ indicatorHeight:(CGFloat)indicatorHeight
31
+ indicatorBottom:(CGFloat)indicatorBottom;
32
+ - (void)setProgress:(CGFloat)progress;
33
+ - (void)setLeftToRight:(BOOL)leftToRight;
12
34
  @end
13
35
 
14
36
  @interface RNCCollapsiblePagerHitTestTests : XCTestCase
@@ -56,6 +78,162 @@ using namespace facebook::react;
56
78
  XCTAssertEqual([self.root hitTest:CGPointMake(20, 80) withEvent:nil], self.toolbar);
57
79
  }
58
80
 
81
+ - (void)testNativeTabReservationKeepsReactToolbarAboveTabsAndResetsInRTL
82
+ {
83
+ UIView *sharedHost = [self.pager valueForKey:@"sharedHeaderHostView"];
84
+ UIView *tabBar = [self.pager valueForKey:@"nativeTabBarView"];
85
+ [tabBar updateItemsJSON:@"[{\"key\":\"a\",\"title\":\"Overview\"},"
86
+ @"{\"key\":\"b\",\"title\":\"Ethereum\"},"
87
+ @"{\"key\":\"c\",\"title\":\"BNB Chain\"},"
88
+ @"{\"key\":\"d\",\"title\":\"Polygon\"}]"];
89
+ RCTViewComponentView *sticky = [RCTViewComponentView new];
90
+ auto stickyProps = std::make_shared<ViewProps>();
91
+ stickyProps->pointerEvents = PointerEventsMode::BoxNone;
92
+ [sticky updateProps:stickyProps oldProps:nullptr];
93
+ UIButton *trailingControl = [[UIButton alloc] initWithFrame:CGRectMake(250, 0, 70, 44)];
94
+ [sticky addSubview:trailingControl];
95
+ [sharedHost addSubview:sticky];
96
+ [sharedHost addSubview:tabBar];
97
+ [self.pager setValue:sticky forKey:@"stickyHeaderView"];
98
+ [self.pager setValue:@0 forKey:@"headerHeight"];
99
+ [self.pager setValue:@44 forKey:@"stickyHeaderHeight"];
100
+ tabBar.hidden = NO;
101
+
102
+ [self.pager setValue:@64 forKey:@"nativeTabBarTrailingReservedWidth"];
103
+ [self.pager layoutSharedHeaders];
104
+ XCTAssertEqualWithAccuracy(CGRectGetWidth(sticky.frame), 320, 0.001);
105
+ XCTAssertEqualWithAccuracy(CGRectGetWidth(tabBar.frame), 256, 0.001);
106
+ XCTAssertEqualWithAccuracy(CGRectGetMinX(tabBar.frame), 0, 0.001);
107
+ XCTAssertEqual(sharedHost.subviews.lastObject, sticky);
108
+ XCTAssertEqual([sharedHost hitTest:CGPointMake(300, 22) withEvent:nil], trailingControl);
109
+ XCTAssertTrue([tabBar pointInside:CGPointMake(250, 22) withEvent:nil]);
110
+ [tabBar layoutIfNeeded];
111
+ [tabBar setProgress:3];
112
+ UIScrollView *tabScroll = (UIScrollView *)tabBar.subviews.firstObject;
113
+ NSArray<UIButton *> *buttons = [tabScroll.subviews filteredArrayUsingPredicate:
114
+ [NSPredicate predicateWithBlock:^BOOL(UIView *view, NSDictionary *bindings) {
115
+ return [view isKindOfClass:UIButton.class];
116
+ }]];
117
+ UIButton *lastTab = buttons.lastObject;
118
+ XCTAssertNotNil(lastTab);
119
+ XCTAssertGreaterThanOrEqual(CGRectGetMinX(lastTab.frame), tabScroll.contentOffset.x - 1);
120
+ XCTAssertLessThanOrEqual(CGRectGetMaxX(lastTab.frame),
121
+ tabScroll.contentOffset.x + CGRectGetWidth(tabScroll.bounds) + 1);
122
+
123
+ [self.pager setValue:@"rtl" forKey:@"layoutDirection"];
124
+ [tabBar setLeftToRight:NO];
125
+ trailingControl.frame = CGRectMake(0, 0, 70, 44);
126
+ [self.pager layoutSharedHeaders];
127
+ XCTAssertEqualWithAccuracy(CGRectGetMinX(tabBar.frame), 64, 0.001);
128
+ XCTAssertEqualWithAccuracy(CGRectGetMaxX(tabBar.frame), 320, 0.001);
129
+ XCTAssertEqual([sharedHost hitTest:CGPointMake(20, 22) withEvent:nil], trailingControl);
130
+
131
+ [self.pager setValue:@500 forKey:@"nativeTabBarTrailingReservedWidth"];
132
+ [self.pager layoutSharedHeaders];
133
+ XCTAssertEqualWithAccuracy(CGRectGetMinX(tabBar.frame), 320, 0.001);
134
+ XCTAssertEqualWithAccuracy(CGRectGetWidth(tabBar.frame), 0, 0.001);
135
+
136
+ [self.pager setValue:@0 forKey:@"nativeTabBarTrailingReservedWidth"];
137
+ [self.pager layoutSharedHeaders];
138
+ XCTAssertEqualWithAccuracy(CGRectGetMinX(tabBar.frame), 0, 0.001);
139
+ XCTAssertEqualWithAccuracy(CGRectGetWidth(tabBar.frame), 320, 0.001);
140
+ XCTAssertEqual(sharedHost.subviews.lastObject, tabBar);
141
+ }
142
+
143
+ - (void)testNativeTabReservationPropsRestoreDefaultOnRemoval
144
+ {
145
+ auto reservedProps = std::make_shared<RNCCollapsiblePagerViewProps>();
146
+ reservedProps->nativeSmoothHeaderScrollEnabled = true;
147
+ reservedProps->nativeTabBarTrailingReservedWidth = 64;
148
+ [self.pager updateProps:reservedProps oldProps:nullptr];
149
+ XCTAssertEqualWithAccuracy(
150
+ [[self.pager valueForKey:@"nativeTabBarTrailingReservedWidth"] doubleValue], 64, 0.001);
151
+
152
+ auto defaultProps = std::make_shared<RNCCollapsiblePagerViewProps>();
153
+ defaultProps->nativeSmoothHeaderScrollEnabled = true;
154
+ [self.pager updateProps:defaultProps oldProps:reservedProps];
155
+ XCTAssertEqualWithAccuracy(
156
+ [[self.pager valueForKey:@"nativeTabBarTrailingReservedWidth"] doubleValue], 0, 0.001);
157
+ }
158
+
159
+ - (void)testSegmentedNativeTabsFollowFractionalProgressAndResetToUnderline
160
+ {
161
+ UIView *tabBar = [self.pager valueForKey:@"nativeTabBarView"];
162
+ [tabBar updateItemsJSON:@"[{\"key\":\"recent\",\"title\":\"Recents\"},"
163
+ @"{\"key\":\"account\",\"title\":\"Accounts\"},"
164
+ @"{\"key\":\"book\",\"title\":\"Address Book\"}]"];
165
+ [tabBar updateStyleWithHeight:56 variant:@"segmented"
166
+ contentPaddingHorizontal:20 contentPaddingVertical:12 itemSpacing:0
167
+ fontSize:14 fontFamily:nil backgroundColor:UIColor.lightGrayColor
168
+ activeTextColor:UIColor.blackColor inactiveTextColor:UIColor.grayColor
169
+ indicatorColor:UIColor.whiteColor indicatorHeight:2 indicatorBottom:0];
170
+ tabBar.frame = CGRectMake(0, 0, 320, 56);
171
+ [tabBar layoutIfNeeded];
172
+ UIScrollView *scroll = (UIScrollView *)tabBar.subviews.firstObject;
173
+ UIView *track = scroll.subviews.firstObject;
174
+ UIView *thumb = [tabBar valueForKey:@"indicatorView"];
175
+ NSArray<UIButton *> *buttons = [scroll.subviews filteredArrayUsingPredicate:
176
+ [NSPredicate predicateWithBlock:^BOOL(UIView *view, NSDictionary *bindings) {
177
+ return [view isKindOfClass:UIButton.class];
178
+ }]];
179
+ XCTAssertEqual(buttons.count, 3);
180
+ XCTAssertFalse(scroll.scrollEnabled);
181
+ XCTAssertEqualWithAccuracy(CGRectGetMinX(track.frame), 20, 0.01);
182
+ XCTAssertEqualWithAccuracy(CGRectGetHeight(track.frame), 32, 0.01);
183
+ XCTAssertEqualWithAccuracy(CGRectGetWidth(buttons[0].frame),
184
+ CGRectGetWidth(buttons[1].frame), 0.01);
185
+ [tabBar setProgress:0];
186
+ CGFloat firstX = CGRectGetMinX(thumb.frame);
187
+ [tabBar setProgress:1];
188
+ CGFloat secondX = CGRectGetMinX(thumb.frame);
189
+ [tabBar setProgress:0.25];
190
+ XCTAssertEqualWithAccuracy(CGRectGetMinX(thumb.frame), firstX + (secondX - firstX) * 0.25, 0.01);
191
+ [tabBar setProgress:0.5];
192
+ XCTAssertEqualWithAccuracy(CGRectGetMinX(thumb.frame), (firstX + secondX) / 2, 0.01);
193
+ [tabBar setProgress:0];
194
+ XCTAssertEqualWithAccuracy(CGRectGetMinX(thumb.frame), firstX, 0.01);
195
+
196
+ [tabBar setLeftToRight:NO];
197
+ [tabBar layoutIfNeeded];
198
+ XCTAssertGreaterThan(CGRectGetMinX(buttons[0].frame), CGRectGetMinX(buttons[1].frame));
199
+ [tabBar updateItemsJSON:@"[{\"key\":\"recent\",\"title\":\"Recents (8)\"},"
200
+ @"{\"key\":\"account\",\"title\":\"Accounts\"}]"];
201
+ [tabBar layoutIfNeeded];
202
+ NSArray<UIButton *> *twoButtons = [scroll.subviews filteredArrayUsingPredicate:
203
+ [NSPredicate predicateWithBlock:^BOOL(UIView *view, NSDictionary *bindings) {
204
+ return [view isKindOfClass:UIButton.class];
205
+ }]];
206
+ XCTAssertEqual(twoButtons.count, 2);
207
+ XCTAssertEqualWithAccuracy(CGRectGetWidth(twoButtons[0].frame),
208
+ CGRectGetWidth(track.frame) / 2, 0.01);
209
+ [tabBar updateStyleWithHeight:56 variant:@"segmented"
210
+ contentPaddingHorizontal:20 contentPaddingVertical:40 itemSpacing:0
211
+ fontSize:14 fontFamily:nil backgroundColor:UIColor.lightGrayColor
212
+ activeTextColor:UIColor.blackColor inactiveTextColor:UIColor.grayColor
213
+ indicatorColor:UIColor.whiteColor indicatorHeight:2 indicatorBottom:0];
214
+ tabBar.frame = CGRectMake(0, 0, 30, 56);
215
+ [tabBar layoutIfNeeded];
216
+ XCTAssertEqualWithAccuracy(CGRectGetMinX(track.frame), 15, 0.01);
217
+ XCTAssertEqualWithAccuracy(CGRectGetWidth(track.frame), 0, 0.01);
218
+ XCTAssertEqualWithAccuracy(CGRectGetMinY(track.frame), 28, 0.01);
219
+ XCTAssertEqualWithAccuracy(CGRectGetHeight(track.frame), 0, 0.01);
220
+ XCTAssertTrue(thumb.hidden);
221
+ [tabBar updateItemsJSON:@"[]"];
222
+ XCTAssertTrue(tabBar.hidden);
223
+
224
+ [tabBar updateItemsJSON:@"[{\"key\":\"recent\",\"title\":\"Recents\"}]"];
225
+ [tabBar updateStyleWithHeight:44 variant:@"underline"
226
+ contentPaddingHorizontal:20 contentPaddingVertical:0 itemSpacing:8
227
+ fontSize:16 fontFamily:nil backgroundColor:UIColor.clearColor
228
+ activeTextColor:UIColor.blackColor inactiveTextColor:UIColor.grayColor
229
+ indicatorColor:UIColor.blackColor indicatorHeight:2 indicatorBottom:0];
230
+ tabBar.frame = CGRectMake(0, 0, 320, 44);
231
+ [tabBar layoutIfNeeded];
232
+ XCTAssertTrue(scroll.scrollEnabled);
233
+ XCTAssertTrue(track.hidden);
234
+ XCTAssertEqualWithAccuracy(CGRectGetHeight(thumb.frame), 2, 0.01);
235
+ }
236
+
59
237
  - (void)testPinnedChildOutsideHeaderHostStillReceivesViewportTouches
60
238
  {
61
239
  XCTAssertEqual([self.pager hitTest:CGPointMake(20, 90) withEvent:nil], self.sticky);
@@ -763,6 +763,26 @@ typedef struct __IOHIDEvent *RNCTestHIDEventRef;
763
763
  XCTAssertTrue([pager isKindOfClass:NSClassFromString(@"RNCCollapsiblePagerDirectScrollView")]);
764
764
  }
765
765
 
766
+ - (void)configureSegmentedTabsForTwoPages
767
+ {
768
+ auto baseline = std::make_shared<RNCCollapsiblePagerViewProps>();
769
+ baseline->nativeSmoothHeaderScrollEnabled = true;
770
+ baseline->headerHeight = 120;
771
+ baseline->stickyHeaderHeight = 44;
772
+ auto segmented = std::make_shared<RNCCollapsiblePagerViewProps>();
773
+ segmented->nativeSmoothHeaderScrollEnabled = true;
774
+ segmented->headerHeight = 120;
775
+ segmented->stickyHeaderHeight = 56;
776
+ segmented->nativeTabBarItems =
777
+ R"([{"key":"recent","title":"Recents"},{"key":"account","title":"Accounts"}])";
778
+ segmented->nativeTabBarVariant = "segmented";
779
+ segmented->nativeTabBarHeight = 56;
780
+ segmented->nativeTabBarContentPaddingHorizontal = 20;
781
+ segmented->nativeTabBarContentPaddingVertical = 12;
782
+ [self.pager updateProps:segmented oldProps:baseline];
783
+ [self.window layoutIfNeeded];
784
+ }
785
+
766
786
  - (void)recordPagerPan:(UIPanGestureRecognizer *)pan
767
787
  {
768
788
  if (pan.state == UIGestureRecognizerStateBegan) self.pagerPanBegins += 1;
@@ -904,6 +924,51 @@ typedef struct __IOHIDEvent *RNCTestHIDEventRef;
904
924
  XCTAssertEqual(self.handler.events.count, eventsBeforeLift);
905
925
  }
906
926
 
927
+ - (void)testSegmentedThumbTracksDeliveredPagerDragAndReverseBeforeLift
928
+ {
929
+ [self assertFixtureIsReadyForDelivery];
930
+ [self assertDirectPagerForRegression];
931
+ [self configureSegmentedTabsForTwoPages];
932
+
933
+ UIScrollView *pagerScrollView = [self.pager valueForKey:@"pagerScrollView"];
934
+ UIView *tabBar = [self.pager valueForKey:@"nativeTabBarView"];
935
+ UIView *thumb = [tabBar valueForKey:@"indicatorView"];
936
+ NSArray<UIButton *> *buttons = [tabBar valueForKey:@"buttons"];
937
+ XCTAssertEqual(buttons.count, 2);
938
+ XCTAssertFalse(tabBar.hidden);
939
+ XCTAssertEqualWithAccuracy(CGRectGetHeight(tabBar.bounds), 56, 0.01);
940
+ CGFloat firstThumbX = CGRectGetMinX(buttons[0].frame) + 2;
941
+ CGFloat secondThumbX = CGRectGetMinX(buttons[1].frame) + 2;
942
+ XCTAssertEqualWithAccuracy(CGRectGetMinX(thumb.frame), firstThumbX, 1);
943
+
944
+ CGPoint point = CGPointMake(350, 600);
945
+ UITouch *touch = [self.driver beginAt:point];
946
+ CGFloat largestOffset = 0;
947
+ NSUInteger intermediateFrames = 0;
948
+ for (NSInteger step = 1; step <= 18; ++step) {
949
+ [self.driver move:touch to:CGPointMake(point.x - 14 * step, point.y)];
950
+ CGFloat offset = pagerScrollView.contentOffset.x;
951
+ largestOffset = MAX(largestOffset, offset);
952
+ if (offset > 1 && offset < CGRectGetWidth(pagerScrollView.bounds) - 1) {
953
+ CGFloat progress = offset / CGRectGetWidth(pagerScrollView.bounds);
954
+ XCTAssertEqualWithAccuracy(CGRectGetMinX(thumb.frame),
955
+ firstThumbX + (secondThumbX - firstThumbX) * progress, 1);
956
+ intermediateFrames += 1;
957
+ }
958
+ }
959
+ XCTAssertTrue(pagerScrollView.isDragging);
960
+ XCTAssertGreaterThan(largestOffset, 80);
961
+ XCTAssertGreaterThan(intermediateFrames, 2);
962
+
963
+ for (NSInteger step = 17; step >= 0; --step) {
964
+ [self.driver move:touch to:CGPointMake(point.x - 14 * step, point.y)];
965
+ }
966
+ // UIKit can briefly bounce past the leading edge before the finger lifts.
967
+ XCTAssertLessThan(fabs(pagerScrollView.contentOffset.x), 10);
968
+ XCTAssertEqualWithAccuracy(CGRectGetMinX(thumb.frame), firstThumbX, 1);
969
+ [self.driver end:touch];
970
+ }
971
+
907
972
  - (void)testStationaryTapKeepsReactPress
908
973
  {
909
974
  [self assertFixtureIsReadyForDelivery];
@@ -82,6 +82,12 @@ export class CollapsiblePagerView extends React.PureComponent {
82
82
  scrollToPageTop = options => {
83
83
  if (this.nativeRef) CollapsiblePagerViewNativeCommands.scrollToTop(this.nativeRef, 0, options?.animated ?? true);
84
84
  };
85
+ scrollHeaderBy = delta => {
86
+ if (this.nativeRef && Number.isFinite(delta)) CollapsiblePagerViewNativeCommands.scrollHeaderBy(this.nativeRef, delta);
87
+ };
88
+ scrollHeaderToOffset = offset => {
89
+ if (this.nativeRef && Number.isFinite(offset)) CollapsiblePagerViewNativeCommands.scrollHeaderToOffset(this.nativeRef, offset);
90
+ };
85
91
  scrollToStickyTop = options => {
86
92
  if (this.nativeRef) CollapsiblePagerViewNativeCommands.scrollToTop(this.nativeRef, 1, options?.animated ?? true);
87
93
  };
@@ -96,7 +102,7 @@ export class CollapsiblePagerView extends React.PureComponent {
96
102
  nativeTabBarEnabled() {
97
103
  return (Platform.OS === "ios" || Platform.OS === "android") && !!this.props.nativeTabBar?.items.length;
98
104
  }
99
- dispatchNativeTabPageCommand(position, animated) {
105
+ dispatchNativeTabPageCommand(position, animated, expectedKey) {
100
106
  const commandId = ++this.nativeTabCommandId;
101
107
  this.nativeTabCommandQueuedDuringScroll = this.nativePagerScrollState !== "idle";
102
108
  this.latestNativeTabTarget = position;
@@ -104,7 +110,7 @@ export class CollapsiblePagerView extends React.PureComponent {
104
110
  transientRetainedPages: state.transientRetainedPages.includes(position) ? state.transientRetainedPages : [...state.transientRetainedPages, position]
105
111
  }), () => {
106
112
  requestAnimationFrame(() => {
107
- if (commandId !== this.nativeTabCommandId || !this.nativeRef) {
113
+ if (commandId !== this.nativeTabCommandId || !this.nativeRef || expectedKey !== undefined && (!this.nativeTabBarEnabled() || this.props.nativeTabBar?.items[position]?.key !== expectedKey)) {
108
114
  return;
109
115
  }
110
116
  this.dispatchedNativeTabTarget = position;
@@ -186,10 +192,13 @@ export class CollapsiblePagerView extends React.PureComponent {
186
192
  };
187
193
  onNativeTabPress = event => {
188
194
  const position = pageIndex(event.nativeEvent.position);
189
- if (position !== null && position >= 0 && position < this.pages().length && (position !== this.state.selectedPage || this.latestNativeTabTarget !== null)) {
195
+ if (!this.nativeTabBarEnabled() || position === null || this.props.nativeTabBar?.items[position]?.key !== event.nativeEvent.key) {
196
+ return;
197
+ }
198
+ if (position >= 0 && position < this.pages().length && (position !== this.state.selectedPage || this.latestNativeTabTarget !== null)) {
190
199
  // Selection state lags an in-flight transition until native reports it.
191
200
  const currentPage = this.dispatchedNativeTabTarget ?? this.state.selectedPage;
192
- this.dispatchNativeTabPageCommand(position, this.props.nativeTabPressAnimationEnabled ?? Math.abs(position - currentPage) <= 1);
201
+ this.dispatchNativeTabPageCommand(position, this.props.nativeTabPressAnimationEnabled ?? Math.abs(position - currentPage) <= 1, event.nativeEvent.key);
193
202
  }
194
203
  this.props.onNativeTabPress?.(event);
195
204
  };
@@ -233,6 +242,10 @@ export class CollapsiblePagerView extends React.PureComponent {
233
242
  const deducedLayoutDirection = !layoutDirection || layoutDirection === "locale" ? I18nManager.isRTL ? "rtl" : "ltr" : layoutDirection;
234
243
  const nativeTabBarEnabled = (Platform.OS === "ios" || Platform.OS === "android") && !!nativeTabBar?.items.length;
235
244
  const nativeTabBarStyle = nativeTabBar?.style;
245
+ const requestedContentPaddingVertical = nativeTabBarStyle?.contentPaddingVertical;
246
+ const nativeTabBarContentPaddingVertical = typeof requestedContentPaddingVertical === "number" && Number.isFinite(requestedContentPaddingVertical) && requestedContentPaddingVertical >= 0 ? requestedContentPaddingVertical : 0;
247
+ const requestedTrailingReservedWidth = nativeTabBarStyle?.trailingReservedWidth;
248
+ const nativeTabBarTrailingReservedWidth = typeof requestedTrailingReservedWidth === "number" && Number.isFinite(requestedTrailingReservedWidth) && requestedTrailingReservedWidth >= 0 ? requestedTrailingReservedWidth : 0;
236
249
  const nativeSubHeaderEnabled = (Platform.OS === "ios" || Platform.OS === "android") && !!nativeSubHeader?.items.length;
237
250
  const nativeSubHeaderStyle = nativeSubHeader?.style;
238
251
  const nativeSubHeaderConfig = nativeSubHeaderEnabled ? JSON.stringify({
@@ -263,7 +276,10 @@ export class CollapsiblePagerView extends React.PureComponent {
263
276
  onPageScrollStateChanged: this.onPageScrollStateChanged,
264
277
  nativeTabBarItems: nativeTabBarEnabled ? JSON.stringify(nativeTabBar.items) : undefined,
265
278
  nativeTabBarHeight: nativeTabBarEnabled ? nativeTabBarStyle?.height ?? 44 : undefined,
279
+ nativeTabBarVariant: nativeTabBarEnabled ? nativeTabBarStyle?.variant ?? "underline" : undefined,
280
+ nativeTabBarTrailingReservedWidth: nativeTabBarEnabled ? nativeTabBarTrailingReservedWidth : 0,
266
281
  nativeTabBarContentPaddingHorizontal: nativeTabBarEnabled ? nativeTabBarStyle?.contentPaddingHorizontal ?? 20 : undefined,
282
+ nativeTabBarContentPaddingVertical: nativeTabBarEnabled ? nativeTabBarContentPaddingVertical : undefined,
267
283
  nativeTabBarItemSpacing: nativeTabBarEnabled ? nativeTabBarStyle?.itemSpacing ?? 8 : undefined,
268
284
  nativeTabBarFontSize: nativeTabBarEnabled ? nativeTabBarStyle?.fontSize ?? 16 : undefined,
269
285
  nativeTabBarFontFamily: nativeTabBarEnabled ? nativeTabBarStyle?.fontFamily : undefined,
@@ -335,6 +335,15 @@ export class CollapsiblePagerView extends React.PureComponent {
335
335
  scrollToPageTop = options => {
336
336
  this.scrollCurrentPageToTop(0, options?.animated ?? true);
337
337
  };
338
+ scrollHeaderBy = delta => {
339
+ if (!Number.isFinite(delta)) return;
340
+ const offset = Math.min(this.headerHeight, Math.max(0, this.sharedHeaderOffset + delta));
341
+ this.scrollCurrentPageToTop(offset, false);
342
+ };
343
+ scrollHeaderToOffset = offset => {
344
+ if (!Number.isFinite(offset)) return;
345
+ this.scrollCurrentPageToTop(Math.min(this.headerHeight, Math.max(0, offset)), false);
346
+ };
338
347
  scrollToStickyTop = options => {
339
348
  this.scrollCurrentPageToTop(this.headerHeight, options?.animated ?? true);
340
349
  };
@@ -386,13 +395,13 @@ export class CollapsiblePagerView extends React.PureComponent {
386
395
  this.pendingTopFrame = null;
387
396
  if (!element.isConnected || this.horizontalTouch || this.transitionTimer !== null || this.pageScrollElement(this.state.selectedPage) !== element || this.pages().map(pageKey)[this.state.selectedPage] !== key) return;
388
397
  this.pageOffsets.set(key, 0);
389
- this.sharedHeaderOffset = offset;
398
+ this.sharedHeaderOffset = Math.min(this.headerHeight, Math.max(0, offset));
390
399
  this.bodyAlignment = {
391
400
  element,
392
401
  key
393
402
  };
394
403
  scrollElementTo(element, {
395
- top: offset,
404
+ top: this.sharedHeaderOffset,
396
405
  behavior: animated ? "smooth" : "instant"
397
406
  });
398
407
  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",
@@ -16,8 +16,11 @@ export type CollapsiblePagerNativeTabBarItem = Readonly<{
16
16
  testID?: string;
17
17
  }>;
18
18
  export type CollapsiblePagerNativeTabBarStyle = Readonly<{
19
+ variant?: "underline" | "segmented";
19
20
  height?: number;
21
+ trailingReservedWidth?: number;
20
22
  contentPaddingHorizontal?: number;
23
+ contentPaddingVertical?: number;
21
24
  itemSpacing?: number;
22
25
  fontSize?: number;
23
26
  fontFamily?: string;
@@ -56,7 +59,7 @@ export type CollapsiblePagerNativeSubHeaderConfig = Readonly<{
56
59
  }>;
57
60
  export type CollapsiblePagerViewOnNativeTabPressEvent = ReactNative.NativeSyntheticEvent<OnNativeTabPressEventData>;
58
61
  export type CollapsiblePagerViewOnNativeSubHeaderPressEvent = ReactNative.NativeSyntheticEvent<OnNativeTabPressEventData>;
59
- export interface CollapsiblePagerViewProps extends Omit<NativeProps, "children" | "headerHeight" | "stickyHeaderHeight" | "topScrollEdgeEffect" | "topOverlayHeight" | "externalTopOverlayTag" | "pageKeys" | "retainedPages" | "nativeTabBarItems" | "nativeTabBarHeight" | "nativeTabBarContentPaddingHorizontal" | "nativeTabBarItemSpacing" | "nativeTabBarFontSize" | "nativeTabBarFontFamily" | "nativeTabBarBackgroundColor" | "nativeTabBarActiveTextColor" | "nativeTabBarInactiveTextColor" | "nativeTabBarIndicatorColor" | "nativeTabBarIndicatorHeight" | "nativeTabBarIndicatorBottom" | "nativeSubHeaderConfig" | "nativeSubHeaderSelectedBackgroundColor" | "onNativeTabPress" | "onNativeSubHeaderPress" | "layoutDirection"> {
62
+ export interface CollapsiblePagerViewProps extends Omit<NativeProps, "children" | "headerHeight" | "stickyHeaderHeight" | "topScrollEdgeEffect" | "topOverlayHeight" | "externalTopOverlayTag" | "pageKeys" | "retainedPages" | "nativeTabBarItems" | "nativeTabBarHeight" | "nativeTabBarVariant" | "nativeTabBarTrailingReservedWidth" | "nativeTabBarContentPaddingHorizontal" | "nativeTabBarContentPaddingVertical" | "nativeTabBarItemSpacing" | "nativeTabBarFontSize" | "nativeTabBarFontFamily" | "nativeTabBarBackgroundColor" | "nativeTabBarActiveTextColor" | "nativeTabBarInactiveTextColor" | "nativeTabBarIndicatorColor" | "nativeTabBarIndicatorHeight" | "nativeTabBarIndicatorBottom" | "nativeSubHeaderConfig" | "nativeSubHeaderSelectedBackgroundColor" | "onNativeTabPress" | "onNativeSubHeaderPress" | "layoutDirection"> {
60
63
  /** Collapsible content rendered above the sticky bar. */
61
64
  header: React.ReactNode;
62
65
  /** Bar which remains pinned after the header has collapsed. */
@@ -128,6 +131,8 @@ export declare class CollapsiblePagerView extends React.PureComponent<Collapsibl
128
131
  scrollToPageTop: (options?: Readonly<{
129
132
  animated?: boolean;
130
133
  }>) => void;
134
+ scrollHeaderBy: (delta: number) => void;
135
+ scrollHeaderToOffset: (offset: number) => void;
131
136
  scrollToStickyTop: (options?: Readonly<{
132
137
  animated?: boolean;
133
138
  }>) => void;
@@ -132,6 +132,8 @@ export declare class CollapsiblePagerView extends React.PureComponent<Collapsibl
132
132
  scrollToPageTop: (options?: Readonly<{
133
133
  animated?: boolean;
134
134
  }>) => void;
135
+ scrollHeaderBy: (delta: number) => void;
136
+ scrollHeaderToOffset: (offset: number) => void;
135
137
  scrollToStickyTop: (options?: Readonly<{
136
138
  animated?: boolean;
137
139
  }>) => void;
@@ -50,7 +50,10 @@ export interface NativeProps extends ViewProps {
50
50
  retainedPages?: string;
51
51
  nativeTabBarItems?: string;
52
52
  nativeTabBarHeight?: Double;
53
+ nativeTabBarVariant?: string;
54
+ nativeTabBarTrailingReservedWidth?: WithDefault<Double, 0>;
53
55
  nativeTabBarContentPaddingHorizontal?: Double;
56
+ nativeTabBarContentPaddingVertical?: Double;
54
57
  nativeTabBarItemSpacing?: Double;
55
58
  nativeTabBarFontSize?: Double;
56
59
  nativeTabBarFontFamily?: string;
@@ -72,6 +75,8 @@ export interface NativeProps extends ViewProps {
72
75
  }
73
76
  type CollapsiblePagerViewNativeType = HostComponent<NativeProps>;
74
77
  export interface NativeCommands {
78
+ scrollHeaderToOffset: (viewRef: React.ElementRef<CollapsiblePagerViewNativeType>, offset: Double) => void;
79
+ scrollHeaderBy: (viewRef: React.ElementRef<CollapsiblePagerViewNativeType>, delta: Double) => void;
75
80
  scrollToTop: (viewRef: React.ElementRef<CollapsiblePagerViewNativeType>, target: Int32, animated: boolean) => void;
76
81
  setPage: (viewRef: React.ElementRef<CollapsiblePagerViewNativeType>, selectedPage: Int32) => void;
77
82
  setPageWithoutAnimation: (viewRef: React.ElementRef<CollapsiblePagerViewNativeType>, selectedPage: Int32) => void;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@onekeyfe/react-native-pager-view",
3
- "version": "6.7.0-alpha.344",
3
+ "version": "6.7.0-alpha.359",
4
4
  "description": "React Native wrapper for Android and iOS ViewPager",
5
5
  "source": "./src/index.tsx",
6
6
  "main": "./lib/module/index.js",
@@ -73,7 +73,7 @@
73
73
  "typescript": "^5.9.2"
74
74
  },
75
75
  "peerDependencies": {
76
- "@onekeyfe/react-native-native-logger": "6.7.0-alpha.344",
76
+ "@onekeyfe/react-native-native-logger": "6.7.0-alpha.359",
77
77
  "react": "*",
78
78
  "react-native": "*"
79
79
  },
@@ -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(position: number, animated: boolean) {
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 (commandId !== this.nativeTabCommandId || !this.nativeRef) {
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
- position !== null &&
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
  }