@onekeyfe/react-native-pager-view 6.7.0-36 → 6.7.0-38
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/android/src/main/java/com/reactnativepagerview/CollapsiblePagerNativeHeaders.kt +86 -14
- package/android/src/main/java/com/reactnativepagerview/CollapsiblePagerViewManager.kt +1 -1
- package/docs/SPEC.md +44 -0
- package/ios/RNCCollapsiblePagerViewComponentView.mm +67 -6
- package/lib/module/CollapsiblePagerView.js +6 -1
- package/lib/module/CollapsiblePagerView.web.js +132 -11
- package/lib/typescript/src/CollapsiblePagerView.d.ts +21 -1
- package/lib/typescript/src/CollapsiblePagerView.web.d.ts +8 -0
- package/package.json +1 -1
- package/src/CollapsiblePagerView.tsx +30 -1
- package/src/CollapsiblePagerView.web.tsx +110 -9
|
@@ -86,6 +86,9 @@ private class CollapsiblePagerHorizontalItemsView(
|
|
|
86
86
|
private var contentPaddingVerticalPx = 0
|
|
87
87
|
private var segmented = false
|
|
88
88
|
private var textVariant = false
|
|
89
|
+
private var pillVariant = false
|
|
90
|
+
private var itemPaddingHorizontalDp: Double? = null
|
|
91
|
+
private var pillAnimationEnabled = true
|
|
89
92
|
private var itemSpacingPx = dp(8.0)
|
|
90
93
|
private var fontSize = if (showsProgressIndicator) 16.0 else 14.0
|
|
91
94
|
private var fontFamily: String? = null
|
|
@@ -177,6 +180,7 @@ private class CollapsiblePagerHorizontalItemsView(
|
|
|
177
180
|
val wasSegmented = segmented
|
|
178
181
|
segmented = showsProgressIndicator && variant == "segmented"
|
|
179
182
|
textVariant = showsProgressIndicator && variant == "text"
|
|
183
|
+
pillVariant = showsProgressIndicator && variant == "pill"
|
|
180
184
|
itemSpacingPx = max(0, dp(itemSpacing))
|
|
181
185
|
this.fontSize = max(1.0, fontSize)
|
|
182
186
|
this.fontFamily = fontFamily
|
|
@@ -217,6 +221,25 @@ private class CollapsiblePagerHorizontalItemsView(
|
|
|
217
221
|
|
|
218
222
|
fun usesTextVariant(): Boolean = textVariant
|
|
219
223
|
|
|
224
|
+
// Variants whose label colors (and pill) follow controlled pager progress.
|
|
225
|
+
fun usesProgressDrivenItems(): Boolean = textVariant || (pillVariant && pillAnimationEnabled)
|
|
226
|
+
|
|
227
|
+
fun setPillAnimationEnabled(value: Boolean) {
|
|
228
|
+
if (pillAnimationEnabled == value) return
|
|
229
|
+
pillAnimationEnabled = value
|
|
230
|
+
updatePresentation()
|
|
231
|
+
}
|
|
232
|
+
|
|
233
|
+
fun pillAnimationDisabled(): Boolean = pillVariant && !pillAnimationEnabled
|
|
234
|
+
|
|
235
|
+
fun setItemPaddingHorizontal(value: Double?) {
|
|
236
|
+
if (itemPaddingHorizontalDp == value) return
|
|
237
|
+
itemPaddingHorizontalDp = value
|
|
238
|
+
requestLayout()
|
|
239
|
+
}
|
|
240
|
+
|
|
241
|
+
private fun itemPaddingPx(): Int = dp(itemPaddingHorizontalDp ?: if (textVariant) 10.0 else if (pillVariant) 14.0 else 8.0)
|
|
242
|
+
|
|
220
243
|
fun setActiveFontFamily(value: String?) { activeFontFamily = value; requestLayout() }
|
|
221
244
|
|
|
222
245
|
fun setProgress(value: Float, source: Int? = null, destination: Int? = null, fraction: Float = 0f) {
|
|
@@ -253,7 +276,7 @@ private class CollapsiblePagerHorizontalItemsView(
|
|
|
253
276
|
val fontOwner = visualFontOwnerIndex(buttons.indexOfFirst { it.isSelected })
|
|
254
277
|
buttons.forEachIndexed { index, button ->
|
|
255
278
|
button.typeface = if (textVariant && index == fontOwner) selectedTypeface() else typeface
|
|
256
|
-
button.setPadding(
|
|
279
|
+
button.setPadding(itemPaddingPx(), 0, itemPaddingPx(), 0)
|
|
257
280
|
button.setTextSize(TypedValue.COMPLEX_UNIT_SP, fontSize.toFloat())
|
|
258
281
|
}
|
|
259
282
|
}
|
|
@@ -332,11 +355,20 @@ private class CollapsiblePagerHorizontalItemsView(
|
|
|
332
355
|
dp(20.0)
|
|
333
356
|
}
|
|
334
357
|
val buttonWidth = max(dp(44.0), textWidth + horizontalPadding)
|
|
335
|
-
val indicatorWidth = textWidth
|
|
358
|
+
val indicatorWidth = if (pillVariant) buttonWidth else textWidth
|
|
336
359
|
val indicatorX = x + (buttonWidth - indicatorWidth) / 2
|
|
337
360
|
itemFrames.add(intArrayOf(x, buttonWidth, indicatorX, indicatorWidth))
|
|
338
|
-
val
|
|
339
|
-
val
|
|
361
|
+
val pillInset = min(contentPaddingVerticalPx, height / 2)
|
|
362
|
+
val itemHeight = when {
|
|
363
|
+
pillVariant -> max(0, height - 2 * pillInset)
|
|
364
|
+
showsProgressIndicator -> height
|
|
365
|
+
else -> min(dp(32.0), height)
|
|
366
|
+
}
|
|
367
|
+
val top = when {
|
|
368
|
+
pillVariant -> pillInset
|
|
369
|
+
showsProgressIndicator -> 0
|
|
370
|
+
else -> max(0, (height - itemHeight) / 2)
|
|
371
|
+
}
|
|
340
372
|
button.layoutParams = FrameLayout.LayoutParams(buttonWidth, itemHeight).apply {
|
|
341
373
|
leftMargin = x
|
|
342
374
|
topMargin = top
|
|
@@ -377,19 +409,44 @@ private class CollapsiblePagerHorizontalItemsView(
|
|
|
377
409
|
val selectedIndex: Int
|
|
378
410
|
val scrollTargetCenterX: Float
|
|
379
411
|
if (showsProgressIndicator) {
|
|
380
|
-
|
|
412
|
+
// A pill without animation jumps (with its label colors) to the selection.
|
|
413
|
+
val snapToSelection = pillAnimationDisabled()
|
|
414
|
+
val snappedIndex = if (snapToSelection) {
|
|
415
|
+
(controlledSelectedKey?.let { key -> items.indexOfFirst { it.key == key }.takeIf { it >= 0 } }
|
|
416
|
+
?: progress.roundToInt()).coerceIn(0, buttons.lastIndex)
|
|
417
|
+
} else -1
|
|
418
|
+
val clamped = if (snapToSelection) snappedIndex.toFloat() else progress.coerceIn(0f, buttons.lastIndex.toFloat())
|
|
381
419
|
val lower = floor(clamped).toInt()
|
|
382
420
|
val upper = min(lower + 1, buttons.lastIndex)
|
|
383
421
|
val fraction = clamped - lower
|
|
384
422
|
val from = itemFrames[lower]
|
|
385
423
|
val to = itemFrames[upper]
|
|
386
|
-
|
|
387
|
-
|
|
424
|
+
var interpolatedIndicatorX = from[2] + (to[2] - from[2]) * fraction
|
|
425
|
+
var interpolatedIndicatorWidth = from[3] + (to[3] - from[3]) * fraction
|
|
426
|
+
if (pillVariant) {
|
|
427
|
+
// Leading edge leads and trailing edge lags while moving between tabs.
|
|
428
|
+
val leading = 1f - (1f - fraction) * (1f - fraction)
|
|
429
|
+
val trailing = fraction * fraction
|
|
430
|
+
val forward = to[2] >= from[2]
|
|
431
|
+
val leftEdge = from[2] + (to[2] - from[2]) * (if (forward) trailing else leading)
|
|
432
|
+
val rightEdge = from[2] + from[3] + (to[2] + to[3] - from[2] - from[3]) * (if (forward) leading else trailing)
|
|
433
|
+
interpolatedIndicatorX = leftEdge
|
|
434
|
+
interpolatedIndicatorWidth = max(0f, rightEdge - leftEdge)
|
|
435
|
+
}
|
|
388
436
|
val indicatorX = interpolatedIndicatorX.roundToInt()
|
|
389
437
|
val indicatorWidth = interpolatedIndicatorWidth.roundToInt()
|
|
390
438
|
val actualPaddingVertical = min(contentPaddingVerticalPx, measuredHeight / 2)
|
|
391
|
-
val indicatorHeight =
|
|
392
|
-
|
|
439
|
+
val indicatorHeight = when {
|
|
440
|
+
segmented -> max(0, measuredHeight - 2 * actualPaddingVertical - dp(4.0))
|
|
441
|
+
pillVariant -> max(0, measuredHeight - 2 * actualPaddingVertical)
|
|
442
|
+
else -> indicatorHeightPx
|
|
443
|
+
}
|
|
444
|
+
val indicatorTop = when {
|
|
445
|
+
segmented -> actualPaddingVertical + dp(2.0)
|
|
446
|
+
pillVariant -> actualPaddingVertical
|
|
447
|
+
else -> max(0, measuredHeight - indicatorBottomPx - indicatorHeightPx)
|
|
448
|
+
}
|
|
449
|
+
if (pillVariant) indicatorBackground.cornerRadius = indicatorHeight / 2f
|
|
393
450
|
indicator.layout(
|
|
394
451
|
indicatorX,
|
|
395
452
|
indicatorTop,
|
|
@@ -401,7 +458,7 @@ private class CollapsiblePagerHorizontalItemsView(
|
|
|
401
458
|
selectedIndex = if (controlledSelectedKey != null) items.indexOfFirst { it.key == controlledSelectedKey } else clamped.roundToInt()
|
|
402
459
|
val fontOwner = visualFontOwnerIndex(selectedIndex)
|
|
403
460
|
buttons.forEachIndexed { index, button ->
|
|
404
|
-
val emphasis = if (mappedSource != null && mappedDestination != null) {
|
|
461
|
+
val emphasis = if (!snapToSelection && mappedSource != null && mappedDestination != null) {
|
|
405
462
|
(if (index == mappedSource) 1f - mappedFraction else 0f) + (if (index == mappedDestination) mappedFraction else 0f)
|
|
406
463
|
} else 1f - min(1f, kotlin.math.abs(clamped - index))
|
|
407
464
|
button.setTextColor(ColorUtils.blendARGB(inactiveTextColor, activeTextColor, emphasis))
|
|
@@ -473,6 +530,9 @@ internal class CollapsiblePagerNativeTabBarView(context: Context) : FrameLayout(
|
|
|
473
530
|
fun updateConfigJSON(value: String?) {
|
|
474
531
|
config = runCatching { JSONObject(value ?: "{}") }.getOrDefault(JSONObject())
|
|
475
532
|
row.setActiveFontFamily(config.optString("activeFontFamily").takeIf(String::isNotEmpty))
|
|
533
|
+
row.setItemPaddingHorizontal(config.optDouble("itemPaddingHorizontal", Double.NaN).takeIf { it.isFinite() && it >= 0 })
|
|
534
|
+
row.setPillAnimationEnabled(config.optBoolean("indicatorAnimationEnabled", true))
|
|
535
|
+
requestLayout()
|
|
476
536
|
selectedKey = if (config.optBoolean("controlled")) config.optString("selectedKey") else items.getOrNull(lastNativeProgress.roundToInt())?.key ?: ""
|
|
477
537
|
row.setControlledSelectedKey(if (config.optBoolean("controlled")) selectedKey else null, controlledPageIndices() != null)
|
|
478
538
|
if (hasNativeProgress) setProgress(lastNativeProgress)
|
|
@@ -811,7 +871,17 @@ internal class CollapsiblePagerNativeTabBarView(context: Context) : FrameLayout(
|
|
|
811
871
|
}
|
|
812
872
|
|
|
813
873
|
fun usesControlledTextProgress(): Boolean {
|
|
814
|
-
return row.
|
|
874
|
+
return row.usesProgressDrivenItems() && config.optBoolean("controlled") && controlledPageIndices() != null
|
|
875
|
+
}
|
|
876
|
+
|
|
877
|
+
// The tab row and toolbar share a centered band no wider than contentMaxWidth;
|
|
878
|
+
// the bar background still covers the full width.
|
|
879
|
+
private fun contentBand(width: Int): IntArray {
|
|
880
|
+
val maxWidth = config.optDouble("contentMaxWidth", Double.NaN)
|
|
881
|
+
if (!maxWidth.isFinite() || maxWidth <= 0 || dp(maxWidth) >= width) return intArrayOf(0, width)
|
|
882
|
+
val bandWidth = dp(maxWidth)
|
|
883
|
+
val start = (width - bandWidth) / 2
|
|
884
|
+
return intArrayOf(start, start + bandWidth)
|
|
815
885
|
}
|
|
816
886
|
|
|
817
887
|
fun setProgress(progress: Float) {
|
|
@@ -851,7 +921,8 @@ internal class CollapsiblePagerNativeTabBarView(context: Context) : FrameLayout(
|
|
|
851
921
|
val width = MeasureSpec.getSize(widthMeasureSpec)
|
|
852
922
|
val height = MeasureSpec.getSize(heightMeasureSpec)
|
|
853
923
|
val reserved = dp(toolbarReservedWidth)
|
|
854
|
-
|
|
924
|
+
val band = contentBand(width)
|
|
925
|
+
row.measure(MeasureSpec.makeMeasureSpec(max(0, band[1] - band[0] - reserved), MeasureSpec.EXACTLY), heightMeasureSpec)
|
|
855
926
|
toolbar.measure(MeasureSpec.makeMeasureSpec(dp(toolbarSize), MeasureSpec.EXACTLY), MeasureSpec.makeMeasureSpec(dp(toolbarSize), MeasureSpec.EXACTLY))
|
|
856
927
|
setMeasuredDimension(width, height)
|
|
857
928
|
}
|
|
@@ -861,9 +932,10 @@ internal class CollapsiblePagerNativeTabBarView(context: Context) : FrameLayout(
|
|
|
861
932
|
val height = bottom - top
|
|
862
933
|
val reserved = dp(toolbarReservedWidth)
|
|
863
934
|
val rtl = layoutDirection == View.LAYOUT_DIRECTION_RTL
|
|
864
|
-
|
|
935
|
+
val band = contentBand(width)
|
|
936
|
+
row.layout(if (rtl) band[0] + reserved else band[0], 0, if (rtl) band[1] else band[1] - reserved, height)
|
|
865
937
|
val inset = dp(toolbarTrailingInset) - (dp(toolbarSize) - dp(toolbarContentWidth)) / 2
|
|
866
|
-
val x = if (rtl) inset else
|
|
938
|
+
val x = if (rtl) band[0] + inset else band[1] - inset - dp(toolbarSize)
|
|
867
939
|
toolbar.layout(x, (height - dp(toolbarSize)) / 2, x + dp(toolbarSize), (height + dp(toolbarSize)) / 2)
|
|
868
940
|
}
|
|
869
941
|
|
|
@@ -254,7 +254,7 @@ class CollapsiblePagerViewManager : ViewGroupManager<CollapsiblePagerHost>(),
|
|
|
254
254
|
@ReactProp(name = "nativeTabBarVariant")
|
|
255
255
|
override fun setNativeTabBarVariant(view: CollapsiblePagerHost?, value: String?) {
|
|
256
256
|
view ?: return
|
|
257
|
-
view.nativeTabBarVariant = if (value == "segmented" || value == "text") value else "underline"
|
|
257
|
+
view.nativeTabBarVariant = if (value == "segmented" || value == "text" || value == "pill") value else "underline"
|
|
258
258
|
view.applyNativeHeaderStyle()
|
|
259
259
|
}
|
|
260
260
|
|
package/docs/SPEC.md
CHANGED
|
@@ -1499,3 +1499,47 @@ commit checks passed 9/9; unrelated postinstall noble patch and Web notification
|
|
|
1499
1499
|
external-image warnings remain separately recorded. Alpha.445 failed Pod
|
|
1500
1500
|
integration and was not reused. SDK iOS CI ran on iOS 26.5: iOS-27-only incoming
|
|
1501
1501
|
lifecycle cases remained skipped; no local SDK UIKit execution is claimed.
|
|
1502
|
+
|
|
1503
|
+
## Pill tabs and centered content band
|
|
1504
|
+
|
|
1505
|
+
`nativeTabBar.style.variant` also accepts `"pill"` on iOS, Android and Web. It
|
|
1506
|
+
lets wide/desktop consumers replace a JS pill tab bar with the native one, so
|
|
1507
|
+
every platform draws Home tabs from the same config.
|
|
1508
|
+
|
|
1509
|
+
- Items keep intrinsic-width labels (medium face, `fontSize` default 16) with
|
|
1510
|
+
`itemPaddingHorizontal` on each side (default 14; text keeps 10, underline and
|
|
1511
|
+
segmented keep 8). Each item is `height - 2 * contentPaddingVertical` tall and
|
|
1512
|
+
vertically inset by `contentPaddingVertical`.
|
|
1513
|
+
- One rounded background (`indicatorColor`, radius = half its height) sits
|
|
1514
|
+
behind the selected item and follows pager progress. Between two items, the
|
|
1515
|
+
leading edge eases out and the trailing edge eases in, so the pill stretches
|
|
1516
|
+
toward the target before it contracts. Label colors blend from
|
|
1517
|
+
`inactiveTextColor` to `activeTextColor` with the same progress rules as the
|
|
1518
|
+
text variant. With `controlled: true`, programmatic page changes drive the same
|
|
1519
|
+
progress animation as the text variant does.
|
|
1520
|
+
- Pill geometry is always taken from the current item frames (iOS and Android
|
|
1521
|
+
layout passes; Web reads live button boxes on every sync and observes item and
|
|
1522
|
+
list resizes). No size is cached per index, so items that only move when the
|
|
1523
|
+
item list changes still get their own offset and width.
|
|
1524
|
+
- Web only: unselected items use `itemHoverBackgroundColor` and
|
|
1525
|
+
`itemPressedBackgroundColor` for hover / pressed feedback. When the pill
|
|
1526
|
+
changes target without pager progress (Web pages switch instantly), it moves
|
|
1527
|
+
with a 220 ms CSS transition; it does not animate on first placement.
|
|
1528
|
+
Native items have no hover or pressed fill.
|
|
1529
|
+
|
|
1530
|
+
`style.contentMaxWidth` (all variants, all three platforms) caps the width of the
|
|
1531
|
+
tab row together with the toolbar slot and centers that band in the bar. The bar
|
|
1532
|
+
background still covers the full width. Values that are missing, not positive,
|
|
1533
|
+
or at least the bar width leave the existing full-width layout unchanged.
|
|
1534
|
+
|
|
1535
|
+
`style.indicatorAnimationEnabled` (pill only, default true) turns the motion
|
|
1536
|
+
off. When false, the pill sits on the selected item (controlled `selectedKey`,
|
|
1537
|
+
otherwise the rounded pager position) on every update, label colors switch
|
|
1538
|
+
between active and inactive without blending, the Web CSS transition is
|
|
1539
|
+
skipped, and programmatic page changes no longer drive progress frames for the
|
|
1540
|
+
tab bar. Swiping the pages still moves the pages; only the tab bar snaps.
|
|
1541
|
+
|
|
1542
|
+
`itemPaddingHorizontal`, `itemHoverBackgroundColor`, `itemPressedBackgroundColor`,
|
|
1543
|
+
`contentMaxWidth` and `indicatorAnimationEnabled` travel to native code inside the existing
|
|
1544
|
+
`nativeTabBarConfig` JSON (colors through `processColor`), so the codegen props
|
|
1545
|
+
and native component schema stay the same. Existing variants keep their defaults.
|
|
@@ -492,6 +492,7 @@ static CGFloat RNCPagerToolbarDimension(NSDictionary *entry, NSString *key, CGFl
|
|
|
492
492
|
CGFloat _contentPaddingVertical;
|
|
493
493
|
BOOL _segmented;
|
|
494
494
|
BOOL _textVariant;
|
|
495
|
+
BOOL _pillVariant;
|
|
495
496
|
NSDictionary *_config;
|
|
496
497
|
RNCPagerToolbarButton *_toolbarButton;
|
|
497
498
|
NSString *_toolbarKey;
|
|
@@ -677,6 +678,7 @@ static CGFloat RNCPagerToolbarDimension(NSDictionary *entry, NSString *key, CGFl
|
|
|
677
678
|
BOOL wasSegmented = _segmented;
|
|
678
679
|
_segmented = [variant isEqualToString:@"segmented"];
|
|
679
680
|
_textVariant = [variant isEqualToString:@"text"];
|
|
681
|
+
_pillVariant = [variant isEqualToString:@"pill"];
|
|
680
682
|
_contentPaddingHorizontal = MAX(0, contentPaddingHorizontal);
|
|
681
683
|
_contentPaddingVertical = MAX(0, contentPaddingVertical);
|
|
682
684
|
_itemSpacing = MAX(0, itemSpacing);
|
|
@@ -749,15 +751,39 @@ static CGFloat RNCPagerToolbarDimension(NSDictionary *entry, NSString *key, CGFl
|
|
|
749
751
|
RNCLogNativeTabScrollBoundary(@"primary", @"end", scrollView, _scrollStartOffsetX);
|
|
750
752
|
}
|
|
751
753
|
|
|
754
|
+
- (CGFloat)itemPaddingHorizontal
|
|
755
|
+
{
|
|
756
|
+
id value = _config[@"itemPaddingHorizontal"];
|
|
757
|
+
if ([value isKindOfClass:NSNumber.class] && std::isfinite([value doubleValue]) && [value doubleValue] >= 0) {
|
|
758
|
+
return [value doubleValue];
|
|
759
|
+
}
|
|
760
|
+
return _textVariant ? 10 : (_pillVariant ? 14 : 8);
|
|
761
|
+
}
|
|
762
|
+
|
|
763
|
+
// The tab row and toolbar share a centered band no wider than contentMaxWidth;
|
|
764
|
+
// the bar background still covers the full width.
|
|
765
|
+
- (CGRect)contentRowFrame
|
|
766
|
+
{
|
|
767
|
+
CGFloat width = CGRectGetWidth(self.bounds);
|
|
768
|
+
id value = _config[@"contentMaxWidth"];
|
|
769
|
+
if ([value isKindOfClass:NSNumber.class] && std::isfinite([value doubleValue]) && [value doubleValue] > 0 &&
|
|
770
|
+
[value doubleValue] < width) {
|
|
771
|
+
CGFloat rowWidth = [value doubleValue];
|
|
772
|
+
return CGRectMake(floor((width - rowWidth) / 2), 0, rowWidth, CGRectGetHeight(self.bounds));
|
|
773
|
+
}
|
|
774
|
+
return self.bounds;
|
|
775
|
+
}
|
|
776
|
+
|
|
752
777
|
- (void)layoutSubviews
|
|
753
778
|
{
|
|
754
779
|
[super layoutSubviews];
|
|
755
780
|
CGFloat reserved = _toolbarReservedWidth;
|
|
781
|
+
CGRect row = [self contentRowFrame];
|
|
756
782
|
[self bringSubviewToFront:_toolbarButton];
|
|
757
|
-
_scrollView.frame = CGRectMake(_leftToRight ? 0 : reserved, 0,
|
|
758
|
-
MAX(0, CGRectGetWidth(
|
|
783
|
+
_scrollView.frame = CGRectMake(CGRectGetMinX(row) + (_leftToRight ? 0 : reserved), 0,
|
|
784
|
+
MAX(0, CGRectGetWidth(row) - reserved), CGRectGetHeight(self.bounds));
|
|
759
785
|
CGFloat inset = _toolbarTrailingInset - (_toolbarSize - _toolbarContentWidth) / 2;
|
|
760
|
-
_toolbarButton.frame = CGRectMake(_leftToRight ?
|
|
786
|
+
_toolbarButton.frame = CGRectMake(_leftToRight ? CGRectGetMaxX(row) - inset - _toolbarSize : CGRectGetMinX(row) + inset,
|
|
761
787
|
(CGRectGetHeight(self.bounds) - _toolbarSize) / 2, _toolbarSize, _toolbarSize);
|
|
762
788
|
if (_segmented) {
|
|
763
789
|
CGFloat width = CGRectGetWidth(_scrollView.bounds);
|
|
@@ -796,7 +822,7 @@ static CGFloat RNCPagerToolbarDimension(NSDictionary *entry, NSString *key, CGFl
|
|
|
796
822
|
UIFont *activeFont = self.activeTabFont;
|
|
797
823
|
textWidth = MAX(textWidth, ceil([title sizeWithAttributes:@{NSFontAttributeName: activeFont}].width));
|
|
798
824
|
}
|
|
799
|
-
CGFloat buttonWidth = MAX(44, textWidth +
|
|
825
|
+
CGFloat buttonWidth = MAX(44, textWidth + 2 * self.itemPaddingHorizontal);
|
|
800
826
|
[widths addObject:@(buttonWidth)];
|
|
801
827
|
itemsWidth += buttonWidth;
|
|
802
828
|
}
|
|
@@ -812,6 +838,14 @@ static CGFloat RNCPagerToolbarDimension(NSDictionary *entry, NSString *key, CGFl
|
|
|
812
838
|
[_buttons enumerateObjectsUsingBlock:^(UIButton *button, NSUInteger index, BOOL *stop) {
|
|
813
839
|
CGFloat buttonWidth = widths[index].doubleValue;
|
|
814
840
|
if (!self->_leftToRight) x -= buttonWidth;
|
|
841
|
+
if (self->_pillVariant) {
|
|
842
|
+
CGFloat insetY = MIN(self->_contentPaddingVertical, self->_barHeight / 2);
|
|
843
|
+
button.frame = CGRectMake(x, insetY, buttonWidth, MAX(0, self->_barHeight - 2 * insetY));
|
|
844
|
+
[self->_indicatorFrames addObject:[NSValue valueWithCGRect:button.frame]];
|
|
845
|
+
if (self->_leftToRight) x += buttonWidth + self->_itemSpacing;
|
|
846
|
+
else x -= self->_itemSpacing;
|
|
847
|
+
return;
|
|
848
|
+
}
|
|
815
849
|
button.frame = CGRectMake(x, 0, buttonWidth, self->_barHeight);
|
|
816
850
|
NSString *title = [button titleForState:UIControlStateNormal] ?: @"";
|
|
817
851
|
CGFloat textWidth = ceil([title sizeWithAttributes:@{NSFontAttributeName: font}].width);
|
|
@@ -887,7 +921,14 @@ static CGFloat RNCPagerToolbarDimension(NSDictionary *entry, NSString *key, CGFl
|
|
|
887
921
|
[self updateToolbarForKey:key];
|
|
888
922
|
[self setNeedsLayout];
|
|
889
923
|
}
|
|
890
|
-
- (BOOL)
|
|
924
|
+
- (BOOL)pillAnimationDisabled
|
|
925
|
+
{
|
|
926
|
+
id value = _config[@"indicatorAnimationEnabled"];
|
|
927
|
+
return _pillVariant && [value isKindOfClass:NSNumber.class] && ![value boolValue];
|
|
928
|
+
}
|
|
929
|
+
- (BOOL)usesControlledTextProgress {
|
|
930
|
+
return (_textVariant || (_pillVariant && !self.pillAnimationDisabled)) && [_config[@"controlled"] boolValue];
|
|
931
|
+
}
|
|
891
932
|
- (void)setLegacyToolbarVisible:(BOOL)visible {
|
|
892
933
|
_toolbarButton.enabled = visible;
|
|
893
934
|
_toolbarButton.userInteractionEnabled = visible;
|
|
@@ -1323,6 +1364,16 @@ static CGFloat RNCPagerToolbarDimension(NSDictionary *entry, NSString *key, CGFl
|
|
|
1323
1364
|
NSInteger count = _buttons.count;
|
|
1324
1365
|
if (count == 0 || _indicatorFrames.count != count) return;
|
|
1325
1366
|
CGFloat progress = RNCClamp(_progress, 0, count - 1);
|
|
1367
|
+
BOOL snapToSelection = self.pillAnimationDisabled;
|
|
1368
|
+
if (snapToSelection) {
|
|
1369
|
+
// The pill and label colors jump to the selection instead of following progress.
|
|
1370
|
+
NSInteger snapped = (NSInteger)round(progress);
|
|
1371
|
+
if ([_config[@"controlled"] boolValue]) {
|
|
1372
|
+
NSUInteger selected = [_items indexOfObjectPassingTest:^BOOL(NSDictionary *item, NSUInteger i, BOOL *stop) { return [item[@"key"] isEqual:self->_config[@"selectedKey"]]; }];
|
|
1373
|
+
if (selected != NSNotFound) snapped = (NSInteger)selected;
|
|
1374
|
+
}
|
|
1375
|
+
progress = RNCClamp(snapped, 0, count - 1);
|
|
1376
|
+
}
|
|
1326
1377
|
NSInteger lower = (NSInteger)floor(progress);
|
|
1327
1378
|
NSInteger upper = MIN(lower + 1, count - 1);
|
|
1328
1379
|
CGFloat fraction = progress - lower;
|
|
@@ -1334,6 +1385,16 @@ static CGFloat RNCPagerToolbarDimension(NSDictionary *entry, NSString *key, CGFl
|
|
|
1334
1385
|
CGRectGetWidth(fromFrame) + (CGRectGetWidth(toFrame) - CGRectGetWidth(fromFrame)) * fraction,
|
|
1335
1386
|
_segmented ? CGRectGetHeight(fromFrame) : _indicatorHeight
|
|
1336
1387
|
);
|
|
1388
|
+
if (_pillVariant) {
|
|
1389
|
+
// Leading edge leads and trailing edge lags while moving between tabs.
|
|
1390
|
+
CGFloat leading = 1 - (1 - fraction) * (1 - fraction);
|
|
1391
|
+
CGFloat trailing = fraction * fraction;
|
|
1392
|
+
BOOL forward = CGRectGetMinX(toFrame) >= CGRectGetMinX(fromFrame);
|
|
1393
|
+
CGFloat left = CGRectGetMinX(fromFrame) + (CGRectGetMinX(toFrame) - CGRectGetMinX(fromFrame)) * (forward ? trailing : leading);
|
|
1394
|
+
CGFloat right = CGRectGetMaxX(fromFrame) + (CGRectGetMaxX(toFrame) - CGRectGetMaxX(fromFrame)) * (forward ? leading : trailing);
|
|
1395
|
+
indicatorFrame = CGRectMake(left, CGRectGetMinY(fromFrame), MAX(0, right - left), CGRectGetHeight(fromFrame));
|
|
1396
|
+
_indicatorView.layer.cornerRadius = CGRectGetHeight(indicatorFrame) / 2;
|
|
1397
|
+
}
|
|
1337
1398
|
_indicatorView.frame = indicatorFrame;
|
|
1338
1399
|
_indicatorView.hidden = _textVariant || CGRectGetHeight(indicatorFrame) <= 0;
|
|
1339
1400
|
|
|
@@ -1347,7 +1408,7 @@ static CGFloat RNCPagerToolbarDimension(NSDictionary *entry, NSString *key, CGFl
|
|
|
1347
1408
|
[self updateToolbarForKey:key];
|
|
1348
1409
|
[_buttons enumerateObjectsUsingBlock:^(UIButton *button, NSUInteger index, BOOL *stop) {
|
|
1349
1410
|
CGFloat emphasis = 1 - MIN(1, fabs(progress - index));
|
|
1350
|
-
if ([self->_config[@"controlled"] boolValue]) {
|
|
1411
|
+
if ([self->_config[@"controlled"] boolValue] && !snapToSelection) {
|
|
1351
1412
|
emphasis = index == self->_progressSource ? 1 - self->_progressFraction : 0;
|
|
1352
1413
|
if (index == self->_progressDestination) emphasis += self->_progressFraction;
|
|
1353
1414
|
}
|
|
@@ -305,7 +305,12 @@ export class CollapsiblePagerView extends React.PureComponent {
|
|
|
305
305
|
return keys;
|
|
306
306
|
})(),
|
|
307
307
|
toolbar: nativeToolbar(nativeTabBar.toolbar),
|
|
308
|
-
activeFontFamily: nativeTabBar.style?.activeFontFamily
|
|
308
|
+
activeFontFamily: nativeTabBar.style?.activeFontFamily,
|
|
309
|
+
itemPaddingHorizontal: nativeTabBar.style?.itemPaddingHorizontal,
|
|
310
|
+
itemHoverBackgroundColor: nativeTabBar.style?.itemHoverBackgroundColor === undefined ? undefined : processColor(nativeTabBar.style.itemHoverBackgroundColor),
|
|
311
|
+
itemPressedBackgroundColor: nativeTabBar.style?.itemPressedBackgroundColor === undefined ? undefined : processColor(nativeTabBar.style.itemPressedBackgroundColor),
|
|
312
|
+
contentMaxWidth: nativeTabBar.style?.contentMaxWidth,
|
|
313
|
+
indicatorAnimationEnabled: nativeTabBar.style?.indicatorAnimationEnabled
|
|
309
314
|
}) : undefined,
|
|
310
315
|
onNativeToolbarPress: this.onNativeToolbarPress,
|
|
311
316
|
nativeTabBarItems: nativeTabBarEnabled ? JSON.stringify(nativeTabBar.items) : undefined,
|
|
@@ -53,6 +53,9 @@ export class CollapsiblePagerView extends React.PureComponent {
|
|
|
53
53
|
tabProgressFrame = null;
|
|
54
54
|
tabProgressGeneration = 0;
|
|
55
55
|
tabButtons = new Map();
|
|
56
|
+
tabList = null;
|
|
57
|
+
tabButtonRefs = new Map();
|
|
58
|
+
tabPill = null;
|
|
56
59
|
headerSlot = null;
|
|
57
60
|
stickySlot = null;
|
|
58
61
|
cssTimelineSupported = false;
|
|
@@ -231,6 +234,8 @@ export class CollapsiblePagerView extends React.PureComponent {
|
|
|
231
234
|
if (this.root) this.chromeObserver.observe(this.root);
|
|
232
235
|
if (this.headerContent) this.chromeObserver.observe(this.headerContent);
|
|
233
236
|
if (this.stickyContent) this.chromeObserver.observe(this.stickyContent);
|
|
237
|
+
if (this.tabList) this.chromeObserver.observe(this.tabList);
|
|
238
|
+
for (const button of this.tabButtons.values()) this.chromeObserver.observe(button);
|
|
234
239
|
this.scheduleChromeMeasurement();
|
|
235
240
|
}
|
|
236
241
|
scheduleChromeMeasurement = () => {
|
|
@@ -539,7 +544,10 @@ export class CollapsiblePagerView extends React.PureComponent {
|
|
|
539
544
|
}
|
|
540
545
|
tabColorWeights() {
|
|
541
546
|
const config = this.props.nativeTabBar;
|
|
542
|
-
|
|
547
|
+
const variant = config?.style?.variant;
|
|
548
|
+
if (!config?.controlled || variant !== "text" && variant !== "pill" || this.tabProgress === null) return null;
|
|
549
|
+
// A pill that does not animate also snaps label colors to the selection.
|
|
550
|
+
if (variant === "pill" && config.style?.indicatorAnimationEnabled === false) return null;
|
|
543
551
|
const keys = [];
|
|
544
552
|
React.Children.forEach(this.props.children, child => {
|
|
545
553
|
if (child !== null && child !== undefined && typeof child !== "boolean") keys.push(pageKey(child, keys.length));
|
|
@@ -590,6 +598,79 @@ export class CollapsiblePagerView extends React.PureComponent {
|
|
|
590
598
|
if (label) label.style.fontFamily = fontFamily;
|
|
591
599
|
} else button.style.fontFamily = fontFamily;
|
|
592
600
|
}
|
|
601
|
+
this.syncTabPill(weights, selectedKey);
|
|
602
|
+
}
|
|
603
|
+
|
|
604
|
+
// Positions the pill from the live button boxes on every sync. Nothing is
|
|
605
|
+
// cached per index, so a tab that only moved (same size, new position) still
|
|
606
|
+
// gets its own width and offset.
|
|
607
|
+
syncTabPill(weights, selectedKey) {
|
|
608
|
+
const pill = this.tabPill;
|
|
609
|
+
if (!pill) return;
|
|
610
|
+
let fromKey = selectedKey;
|
|
611
|
+
let toKey = selectedKey;
|
|
612
|
+
let fraction = 0;
|
|
613
|
+
if (weights && this.tabProgress !== null) {
|
|
614
|
+
const keys = Array.from(weights.keys());
|
|
615
|
+
const progress = Math.min(Math.max(0, this.tabProgress), keys.length - 1);
|
|
616
|
+
const source = Math.floor(progress);
|
|
617
|
+
fromKey = keys[source];
|
|
618
|
+
toKey = keys[Math.min(source + 1, keys.length - 1)];
|
|
619
|
+
fraction = progress - source;
|
|
620
|
+
}
|
|
621
|
+
const from = fromKey === undefined ? undefined : this.tabButtons.get(fromKey);
|
|
622
|
+
const to = toKey === undefined ? undefined : this.tabButtons.get(toKey);
|
|
623
|
+
if (!from || !to || !from.isConnected || !to.isConnected || from.offsetWidth <= 0) {
|
|
624
|
+
pill.style.visibility = "hidden";
|
|
625
|
+
pill.removeAttribute("data-placed");
|
|
626
|
+
return;
|
|
627
|
+
}
|
|
628
|
+
// Leading edge leads, trailing edge lags, like the JS pill this replaces.
|
|
629
|
+
const leading = 1 - (1 - fraction) * (1 - fraction);
|
|
630
|
+
const trailing = fraction * fraction;
|
|
631
|
+
const forward = to.offsetLeft >= from.offsetLeft;
|
|
632
|
+
const leftFraction = forward ? trailing : leading;
|
|
633
|
+
const rightFraction = forward ? leading : trailing;
|
|
634
|
+
const fromRight = from.offsetLeft + from.offsetWidth;
|
|
635
|
+
const toRight = to.offsetLeft + to.offsetWidth;
|
|
636
|
+
const left = from.offsetLeft + (to.offsetLeft - from.offsetLeft) * leftFraction;
|
|
637
|
+
const right = fromRight + (toRight - fromRight) * rightFraction;
|
|
638
|
+
const animationEnabled = this.props.nativeTabBar?.style?.indicatorAnimationEnabled !== false;
|
|
639
|
+
const animate = animationEnabled && pill.hasAttribute("data-placed") && this.tabProgressFrame === null && fraction === 0;
|
|
640
|
+
pill.style.transition = animate ? "transform 220ms cubic-bezier(0.2, 0, 0, 1), width 220ms cubic-bezier(0.2, 0, 0, 1)" : "none";
|
|
641
|
+
pill.style.top = `${from.offsetTop}px`;
|
|
642
|
+
pill.style.height = `${from.offsetHeight}px`;
|
|
643
|
+
pill.style.width = `${Math.max(0, right - left)}px`;
|
|
644
|
+
pill.style.transform = `translateX(${left}px)`;
|
|
645
|
+
pill.style.visibility = "visible";
|
|
646
|
+
pill.setAttribute("data-placed", "");
|
|
647
|
+
}
|
|
648
|
+
setTabList = node => {
|
|
649
|
+
if (node === this.tabList) return;
|
|
650
|
+
if (this.tabList) this.chromeObserver?.unobserve(this.tabList);
|
|
651
|
+
this.tabList = node;
|
|
652
|
+
if (node) this.chromeObserver?.observe(node);
|
|
653
|
+
};
|
|
654
|
+
setTabPill = node => {
|
|
655
|
+
this.tabPill = node;
|
|
656
|
+
if (node) this.syncTabColors();
|
|
657
|
+
};
|
|
658
|
+
tabButtonRef(key) {
|
|
659
|
+
let ref = this.tabButtonRefs.get(key);
|
|
660
|
+
if (!ref) {
|
|
661
|
+
ref = button => this.setTabButton(key, button);
|
|
662
|
+
this.tabButtonRefs.set(key, ref);
|
|
663
|
+
}
|
|
664
|
+
return ref;
|
|
665
|
+
}
|
|
666
|
+
setTabButton(key, button) {
|
|
667
|
+
const previous = this.tabButtons.get(key);
|
|
668
|
+
if (previous === button) return;
|
|
669
|
+
if (previous) this.chromeObserver?.unobserve(previous);
|
|
670
|
+
if (button) {
|
|
671
|
+
this.tabButtons.set(key, button);
|
|
672
|
+
this.chromeObserver?.observe(button);
|
|
673
|
+
} else this.tabButtons.delete(key);
|
|
593
674
|
}
|
|
594
675
|
pageScrollElement(index) {
|
|
595
676
|
const pageHost = this.pageHosts.get(index);
|
|
@@ -1269,30 +1350,71 @@ export class CollapsiblePagerView extends React.PureComponent {
|
|
|
1269
1350
|
return Math.min(size, Math.max(0, entry.contentWidth ?? 24)) + Math.min(128, Math.max(0, entry.trailingInset ?? 20));
|
|
1270
1351
|
}));
|
|
1271
1352
|
const segmented = variant === "segmented";
|
|
1353
|
+
const pill = variant === "pill";
|
|
1272
1354
|
const reserveTextFaces = config.controlled && variant === "text";
|
|
1355
|
+
const itemPadding = style?.itemPaddingHorizontal ?? (variant === "text" ? 10 : pill ? 14 : 8);
|
|
1356
|
+
const cssColor = value => value === undefined ? "transparent" : String(value);
|
|
1357
|
+
for (const key of this.tabButtonRefs.keys()) {
|
|
1358
|
+
if (!config.items.some(item => item.key === key)) this.tabButtonRefs.delete(key);
|
|
1359
|
+
}
|
|
1273
1360
|
const colorWeights = this.tabColorWeights();
|
|
1274
1361
|
const fontOwnerKey = this.tabFontOwnerKey(colorWeights);
|
|
1275
1362
|
return /*#__PURE__*/React.createElement("div", {
|
|
1276
1363
|
className: "ok-pager-tab-bar",
|
|
1277
1364
|
dir: this.props.layoutDirection === "rtl" || (this.props.layoutDirection ?? "locale") === "locale" && I18nManager.isRTL ? "rtl" : "ltr",
|
|
1365
|
+
"data-variant": variant,
|
|
1278
1366
|
style: {
|
|
1279
1367
|
display: "flex",
|
|
1280
1368
|
alignItems: "center",
|
|
1281
1369
|
position: "relative",
|
|
1282
1370
|
height: style?.height ?? 44,
|
|
1283
1371
|
backgroundColor: String(style?.backgroundColor ?? "transparent"),
|
|
1284
|
-
minWidth: 0
|
|
1372
|
+
minWidth: 0,
|
|
1373
|
+
["--pager-tab-hover"]: cssColor(style?.itemHoverBackgroundColor),
|
|
1374
|
+
["--pager-tab-pressed"]: cssColor(style?.itemPressedBackgroundColor)
|
|
1285
1375
|
}
|
|
1286
|
-
}, /*#__PURE__*/React.createElement("style", null, `.ok-pager-tab{box-sizing:border-box;appearance:none;border:0;background:transparent;cursor:default;white-space:nowrap;flex-shrink:0;line-height:normal}.ok-pager-toolbar{box-sizing:border-box;appearance:none;border:1px solid transparent;cursor:default;display:flex;align-items:center;justify-content:center;background:var(--pager-toolbar-base)}.ok-pager-toolbar:hover:enabled{background:var(--pager-toolbar-hover)}.ok-pager-toolbar:active:enabled{background:var(--pager-toolbar-pressed)}`), /*#__PURE__*/React.createElement("div", {
|
|
1376
|
+
}, /*#__PURE__*/React.createElement("style", null, `.ok-pager-tab{box-sizing:border-box;appearance:none;border:0;background:transparent;cursor:default;white-space:nowrap;flex-shrink:0;line-height:normal}.ok-pager-tab-bar[data-variant=pill] .ok-pager-tab{position:relative;z-index:1;border-radius:999px}.ok-pager-tab-bar[data-variant=pill] .ok-pager-tab[aria-selected=false]:hover{background:var(--pager-tab-hover)}.ok-pager-tab-bar[data-variant=pill] .ok-pager-tab[aria-selected=false]:active{background:var(--pager-tab-pressed)}.ok-pager-tablist{scrollbar-width:none}.ok-pager-tablist::-webkit-scrollbar{display:none}.ok-pager-toolbar{box-sizing:border-box;appearance:none;border:1px solid transparent;cursor:default;display:flex;align-items:center;justify-content:center;background:var(--pager-toolbar-base)}.ok-pager-toolbar:hover:enabled{background:var(--pager-toolbar-hover)}.ok-pager-toolbar:active:enabled{background:var(--pager-toolbar-pressed)}`), /*#__PURE__*/React.createElement("div", {
|
|
1377
|
+
className: "ok-pager-tab-row",
|
|
1378
|
+
style: {
|
|
1379
|
+
display: "flex",
|
|
1380
|
+
alignItems: "center",
|
|
1381
|
+
height: "100%",
|
|
1382
|
+
flex: 1,
|
|
1383
|
+
minWidth: 0,
|
|
1384
|
+
maxWidth: style?.contentMaxWidth,
|
|
1385
|
+
margin: style?.contentMaxWidth === undefined ? undefined : "0 auto"
|
|
1386
|
+
}
|
|
1387
|
+
}, /*#__PURE__*/React.createElement("div", {
|
|
1287
1388
|
role: "tablist",
|
|
1389
|
+
className: "ok-pager-tablist",
|
|
1390
|
+
ref: this.setTabList,
|
|
1288
1391
|
style: {
|
|
1289
1392
|
display: "flex",
|
|
1290
1393
|
overflowX: segmented ? "hidden" : "auto",
|
|
1291
1394
|
flex: 1,
|
|
1395
|
+
position: "relative",
|
|
1396
|
+
alignItems: "center",
|
|
1292
1397
|
padding: `${style?.contentPaddingVertical ?? 0}px ${style?.contentPaddingHorizontal ?? 20}px`,
|
|
1293
1398
|
gap: style?.itemSpacing ?? 8
|
|
1294
1399
|
}
|
|
1295
|
-
},
|
|
1400
|
+
}, pill ? /*#__PURE__*/React.createElement("div", {
|
|
1401
|
+
key: "ok-pager-tab-pill",
|
|
1402
|
+
ref: this.setTabPill,
|
|
1403
|
+
className: "ok-pager-tab-pill",
|
|
1404
|
+
"aria-hidden": true,
|
|
1405
|
+
style: {
|
|
1406
|
+
position: "absolute",
|
|
1407
|
+
left: 0,
|
|
1408
|
+
top: 0,
|
|
1409
|
+
width: 0,
|
|
1410
|
+
height: 0,
|
|
1411
|
+
borderRadius: 999,
|
|
1412
|
+
pointerEvents: "none",
|
|
1413
|
+
visibility: "hidden",
|
|
1414
|
+
backgroundColor: String(style?.indicatorColor ?? "#000000"),
|
|
1415
|
+
willChange: "transform, width"
|
|
1416
|
+
}
|
|
1417
|
+
}) : null, ...config.items.map((item, position) => {
|
|
1296
1418
|
const selected = item.key === selectedKey;
|
|
1297
1419
|
const fontSelected = item.key === fontOwnerKey;
|
|
1298
1420
|
return /*#__PURE__*/React.createElement("button", {
|
|
@@ -1301,13 +1423,11 @@ export class CollapsiblePagerView extends React.PureComponent {
|
|
|
1301
1423
|
type: "button",
|
|
1302
1424
|
className: "ok-pager-tab",
|
|
1303
1425
|
"aria-selected": selected,
|
|
1304
|
-
ref:
|
|
1305
|
-
if (button) this.tabButtons.set(item.key, button);else this.tabButtons.delete(item.key);
|
|
1306
|
-
},
|
|
1426
|
+
ref: this.tabButtonRef(item.key),
|
|
1307
1427
|
"aria-label": item.accessibilityLabel ?? item.title,
|
|
1308
1428
|
"data-testid": item.testID,
|
|
1309
1429
|
style: {
|
|
1310
|
-
padding:
|
|
1430
|
+
padding: `6px ${itemPadding}px`,
|
|
1311
1431
|
minWidth: 44,
|
|
1312
1432
|
height: (style?.height ?? 44) - 2 * (style?.contentPaddingVertical ?? 0),
|
|
1313
1433
|
fontSize: style?.fontSize ?? (variant === "text" ? 18 : 16),
|
|
@@ -1318,8 +1438,9 @@ export class CollapsiblePagerView extends React.PureComponent {
|
|
|
1318
1438
|
alignItems: reserveTextFaces ? "center" : undefined,
|
|
1319
1439
|
color: this.tabColor(selected, colorWeights ? colorWeights.get(item.key) ?? 0 : undefined),
|
|
1320
1440
|
flex: segmented ? 1 : undefined,
|
|
1321
|
-
borderRadius: segmented ? 999 : 0,
|
|
1322
|
-
|
|
1441
|
+
borderRadius: segmented || pill ? 999 : 0,
|
|
1442
|
+
// Pill items leave the background to CSS so hover / pressed apply.
|
|
1443
|
+
backgroundColor: pill ? undefined : segmented && selected ? String(style?.indicatorColor ?? "transparent") : "transparent",
|
|
1323
1444
|
borderBottom: variant === "underline" && selected ? `${style?.indicatorHeight ?? 2}px solid ${String(style?.indicatorColor ?? "#000000")}` : undefined
|
|
1324
1445
|
},
|
|
1325
1446
|
onClick: () => {
|
|
@@ -1362,7 +1483,7 @@ export class CollapsiblePagerView extends React.PureComponent {
|
|
|
1362
1483
|
height: "100%",
|
|
1363
1484
|
position: "relative"
|
|
1364
1485
|
}
|
|
1365
|
-
}) : null);
|
|
1486
|
+
}) : null));
|
|
1366
1487
|
}
|
|
1367
1488
|
render() {
|
|
1368
1489
|
const {
|
|
@@ -16,7 +16,11 @@ export type CollapsiblePagerNativeTabBarItem = Readonly<{
|
|
|
16
16
|
testID?: string;
|
|
17
17
|
}>;
|
|
18
18
|
export type CollapsiblePagerNativeTabBarStyle = Readonly<{
|
|
19
|
-
|
|
19
|
+
/**
|
|
20
|
+
* `pill` draws a rounded background behind the selected item that follows
|
|
21
|
+
* pager progress, with active / inactive label colors.
|
|
22
|
+
*/
|
|
23
|
+
variant?: "underline" | "segmented" | "text" | "pill";
|
|
20
24
|
height?: number;
|
|
21
25
|
trailingReservedWidth?: number;
|
|
22
26
|
contentPaddingHorizontal?: number;
|
|
@@ -31,6 +35,22 @@ export type CollapsiblePagerNativeTabBarStyle = Readonly<{
|
|
|
31
35
|
indicatorColor?: ReactNative.ColorValue;
|
|
32
36
|
indicatorHeight?: number;
|
|
33
37
|
indicatorBottom?: number;
|
|
38
|
+
/** Horizontal padding inside each item. Defaults: text 10, pill 14, others 8. */
|
|
39
|
+
itemPaddingHorizontal?: number;
|
|
40
|
+
/** Pill variant: background of an unselected item under the pointer. */
|
|
41
|
+
itemHoverBackgroundColor?: ReactNative.ColorValue;
|
|
42
|
+
/** Pill variant: background of an unselected item while pressed. */
|
|
43
|
+
itemPressedBackgroundColor?: ReactNative.ColorValue;
|
|
44
|
+
/**
|
|
45
|
+
* Caps the width of the tab row and toolbar and centers them; the bar
|
|
46
|
+
* background still spans the full width.
|
|
47
|
+
*/
|
|
48
|
+
contentMaxWidth?: number;
|
|
49
|
+
/**
|
|
50
|
+
* Pill variant: when false, the pill and label colors jump to the selected
|
|
51
|
+
* item instead of following pager progress or animating. Defaults to true.
|
|
52
|
+
*/
|
|
53
|
+
indicatorAnimationEnabled?: boolean;
|
|
34
54
|
}>;
|
|
35
55
|
export type CollapsiblePagerToolbarItem = Readonly<{
|
|
36
56
|
iconName: string;
|
|
@@ -77,6 +77,9 @@ export declare class CollapsiblePagerView extends React.PureComponent<Collapsibl
|
|
|
77
77
|
private tabProgressFrame;
|
|
78
78
|
private tabProgressGeneration;
|
|
79
79
|
private tabButtons;
|
|
80
|
+
private tabList;
|
|
81
|
+
private tabButtonRefs;
|
|
82
|
+
private tabPill;
|
|
80
83
|
private headerSlot;
|
|
81
84
|
private stickySlot;
|
|
82
85
|
private cssTimelineSupported;
|
|
@@ -171,6 +174,11 @@ export declare class CollapsiblePagerView extends React.PureComponent<Collapsibl
|
|
|
171
174
|
private tabFontOwnerKey;
|
|
172
175
|
private tabColor;
|
|
173
176
|
private syncTabColors;
|
|
177
|
+
private syncTabPill;
|
|
178
|
+
private setTabList;
|
|
179
|
+
private setTabPill;
|
|
180
|
+
private tabButtonRef;
|
|
181
|
+
private setTabButton;
|
|
174
182
|
private pageScrollElement;
|
|
175
183
|
private setRoot;
|
|
176
184
|
private overlayTarget;
|
package/package.json
CHANGED
|
@@ -32,7 +32,11 @@ export type CollapsiblePagerNativeTabBarItem = Readonly<{
|
|
|
32
32
|
}>;
|
|
33
33
|
|
|
34
34
|
export type CollapsiblePagerNativeTabBarStyle = Readonly<{
|
|
35
|
-
|
|
35
|
+
/**
|
|
36
|
+
* `pill` draws a rounded background behind the selected item that follows
|
|
37
|
+
* pager progress, with active / inactive label colors.
|
|
38
|
+
*/
|
|
39
|
+
variant?: "underline" | "segmented" | "text" | "pill";
|
|
36
40
|
height?: number;
|
|
37
41
|
trailingReservedWidth?: number;
|
|
38
42
|
contentPaddingHorizontal?: number;
|
|
@@ -47,6 +51,22 @@ export type CollapsiblePagerNativeTabBarStyle = Readonly<{
|
|
|
47
51
|
indicatorColor?: ReactNative.ColorValue;
|
|
48
52
|
indicatorHeight?: number;
|
|
49
53
|
indicatorBottom?: number;
|
|
54
|
+
/** Horizontal padding inside each item. Defaults: text 10, pill 14, others 8. */
|
|
55
|
+
itemPaddingHorizontal?: number;
|
|
56
|
+
/** Pill variant: background of an unselected item under the pointer. */
|
|
57
|
+
itemHoverBackgroundColor?: ReactNative.ColorValue;
|
|
58
|
+
/** Pill variant: background of an unselected item while pressed. */
|
|
59
|
+
itemPressedBackgroundColor?: ReactNative.ColorValue;
|
|
60
|
+
/**
|
|
61
|
+
* Caps the width of the tab row and toolbar and centers them; the bar
|
|
62
|
+
* background still spans the full width.
|
|
63
|
+
*/
|
|
64
|
+
contentMaxWidth?: number;
|
|
65
|
+
/**
|
|
66
|
+
* Pill variant: when false, the pill and label colors jump to the selected
|
|
67
|
+
* item instead of following pager progress or animating. Defaults to true.
|
|
68
|
+
*/
|
|
69
|
+
indicatorAnimationEnabled?: boolean;
|
|
50
70
|
}>;
|
|
51
71
|
|
|
52
72
|
export type CollapsiblePagerToolbarItem = Readonly<{
|
|
@@ -709,6 +729,15 @@ export class CollapsiblePagerView extends React.PureComponent<
|
|
|
709
729
|
})(),
|
|
710
730
|
toolbar: nativeToolbar(nativeTabBar.toolbar),
|
|
711
731
|
activeFontFamily: nativeTabBar.style?.activeFontFamily,
|
|
732
|
+
itemPaddingHorizontal: nativeTabBar.style?.itemPaddingHorizontal,
|
|
733
|
+
itemHoverBackgroundColor: nativeTabBar.style?.itemHoverBackgroundColor === undefined
|
|
734
|
+
? undefined
|
|
735
|
+
: processColor(nativeTabBar.style.itemHoverBackgroundColor),
|
|
736
|
+
itemPressedBackgroundColor: nativeTabBar.style?.itemPressedBackgroundColor === undefined
|
|
737
|
+
? undefined
|
|
738
|
+
: processColor(nativeTabBar.style.itemPressedBackgroundColor),
|
|
739
|
+
contentMaxWidth: nativeTabBar.style?.contentMaxWidth,
|
|
740
|
+
indicatorAnimationEnabled: nativeTabBar.style?.indicatorAnimationEnabled,
|
|
712
741
|
}) : undefined}
|
|
713
742
|
onNativeToolbarPress={this.onNativeToolbarPress}
|
|
714
743
|
nativeTabBarItems={
|
|
@@ -200,6 +200,9 @@ export class CollapsiblePagerView extends React.PureComponent<
|
|
|
200
200
|
private tabProgressFrame: number | null = null;
|
|
201
201
|
private tabProgressGeneration = 0;
|
|
202
202
|
private tabButtons = new Map<string, HTMLButtonElement>();
|
|
203
|
+
private tabList: HTMLElement | null = null;
|
|
204
|
+
private tabButtonRefs = new Map<string, (button: HTMLButtonElement | null) => void>();
|
|
205
|
+
private tabPill: HTMLElement | null = null;
|
|
203
206
|
private headerSlot: HTMLElement | null = null;
|
|
204
207
|
private stickySlot: HTMLElement | null = null;
|
|
205
208
|
private cssTimelineSupported = false;
|
|
@@ -435,6 +438,8 @@ export class CollapsiblePagerView extends React.PureComponent<
|
|
|
435
438
|
if (this.root) this.chromeObserver.observe(this.root);
|
|
436
439
|
if (this.headerContent) this.chromeObserver.observe(this.headerContent);
|
|
437
440
|
if (this.stickyContent) this.chromeObserver.observe(this.stickyContent);
|
|
441
|
+
if (this.tabList) this.chromeObserver.observe(this.tabList);
|
|
442
|
+
for (const button of this.tabButtons.values()) this.chromeObserver.observe(button);
|
|
438
443
|
this.scheduleChromeMeasurement();
|
|
439
444
|
}
|
|
440
445
|
|
|
@@ -855,7 +860,10 @@ export class CollapsiblePagerView extends React.PureComponent<
|
|
|
855
860
|
|
|
856
861
|
private tabColorWeights() {
|
|
857
862
|
const config = this.props.nativeTabBar;
|
|
858
|
-
|
|
863
|
+
const variant = config?.style?.variant;
|
|
864
|
+
if (!config?.controlled || (variant !== "text" && variant !== "pill") || this.tabProgress === null) return null;
|
|
865
|
+
// A pill that does not animate also snaps label colors to the selection.
|
|
866
|
+
if (variant === "pill" && config.style?.indicatorAnimationEnabled === false) return null;
|
|
859
867
|
const keys: string[] = [];
|
|
860
868
|
React.Children.forEach(this.props.children, child => {
|
|
861
869
|
if (child !== null && child !== undefined && typeof child !== "boolean") keys.push(pageKey(child, keys.length));
|
|
@@ -910,6 +918,83 @@ export class CollapsiblePagerView extends React.PureComponent<
|
|
|
910
918
|
if (label) label.style.fontFamily = fontFamily;
|
|
911
919
|
} else button.style.fontFamily = fontFamily;
|
|
912
920
|
}
|
|
921
|
+
this.syncTabPill(weights, selectedKey);
|
|
922
|
+
}
|
|
923
|
+
|
|
924
|
+
// Positions the pill from the live button boxes on every sync. Nothing is
|
|
925
|
+
// cached per index, so a tab that only moved (same size, new position) still
|
|
926
|
+
// gets its own width and offset.
|
|
927
|
+
private syncTabPill(weights: Map<string, number> | null, selectedKey: string | undefined) {
|
|
928
|
+
const pill = this.tabPill;
|
|
929
|
+
if (!pill) return;
|
|
930
|
+
let fromKey = selectedKey;
|
|
931
|
+
let toKey = selectedKey;
|
|
932
|
+
let fraction = 0;
|
|
933
|
+
if (weights && this.tabProgress !== null) {
|
|
934
|
+
const keys = Array.from(weights.keys());
|
|
935
|
+
const progress = Math.min(Math.max(0, this.tabProgress), keys.length - 1);
|
|
936
|
+
const source = Math.floor(progress);
|
|
937
|
+
fromKey = keys[source];
|
|
938
|
+
toKey = keys[Math.min(source + 1, keys.length - 1)];
|
|
939
|
+
fraction = progress - source;
|
|
940
|
+
}
|
|
941
|
+
const from = fromKey === undefined ? undefined : this.tabButtons.get(fromKey);
|
|
942
|
+
const to = toKey === undefined ? undefined : this.tabButtons.get(toKey);
|
|
943
|
+
if (!from || !to || !from.isConnected || !to.isConnected || from.offsetWidth <= 0) {
|
|
944
|
+
pill.style.visibility = "hidden";
|
|
945
|
+
pill.removeAttribute("data-placed");
|
|
946
|
+
return;
|
|
947
|
+
}
|
|
948
|
+
// Leading edge leads, trailing edge lags, like the JS pill this replaces.
|
|
949
|
+
const leading = 1 - (1 - fraction) * (1 - fraction);
|
|
950
|
+
const trailing = fraction * fraction;
|
|
951
|
+
const forward = to.offsetLeft >= from.offsetLeft;
|
|
952
|
+
const leftFraction = forward ? trailing : leading;
|
|
953
|
+
const rightFraction = forward ? leading : trailing;
|
|
954
|
+
const fromRight = from.offsetLeft + from.offsetWidth;
|
|
955
|
+
const toRight = to.offsetLeft + to.offsetWidth;
|
|
956
|
+
const left = from.offsetLeft + (to.offsetLeft - from.offsetLeft) * leftFraction;
|
|
957
|
+
const right = fromRight + (toRight - fromRight) * rightFraction;
|
|
958
|
+
const animationEnabled = this.props.nativeTabBar?.style?.indicatorAnimationEnabled !== false;
|
|
959
|
+
const animate = animationEnabled && pill.hasAttribute("data-placed") && this.tabProgressFrame === null && fraction === 0;
|
|
960
|
+
pill.style.transition = animate ? "transform 220ms cubic-bezier(0.2, 0, 0, 1), width 220ms cubic-bezier(0.2, 0, 0, 1)" : "none";
|
|
961
|
+
pill.style.top = `${from.offsetTop}px`;
|
|
962
|
+
pill.style.height = `${from.offsetHeight}px`;
|
|
963
|
+
pill.style.width = `${Math.max(0, right - left)}px`;
|
|
964
|
+
pill.style.transform = `translateX(${left}px)`;
|
|
965
|
+
pill.style.visibility = "visible";
|
|
966
|
+
pill.setAttribute("data-placed", "");
|
|
967
|
+
}
|
|
968
|
+
|
|
969
|
+
private setTabList = (node: HTMLDivElement | null) => {
|
|
970
|
+
if (node === this.tabList) return;
|
|
971
|
+
if (this.tabList) this.chromeObserver?.unobserve(this.tabList);
|
|
972
|
+
this.tabList = node;
|
|
973
|
+
if (node) this.chromeObserver?.observe(node);
|
|
974
|
+
};
|
|
975
|
+
|
|
976
|
+
private setTabPill = (node: HTMLDivElement | null) => {
|
|
977
|
+
this.tabPill = node;
|
|
978
|
+
if (node) this.syncTabColors();
|
|
979
|
+
};
|
|
980
|
+
|
|
981
|
+
private tabButtonRef(key: string) {
|
|
982
|
+
let ref = this.tabButtonRefs.get(key);
|
|
983
|
+
if (!ref) {
|
|
984
|
+
ref = (button: HTMLButtonElement | null) => this.setTabButton(key, button);
|
|
985
|
+
this.tabButtonRefs.set(key, ref);
|
|
986
|
+
}
|
|
987
|
+
return ref;
|
|
988
|
+
}
|
|
989
|
+
|
|
990
|
+
private setTabButton(key: string, button: HTMLButtonElement | null) {
|
|
991
|
+
const previous = this.tabButtons.get(key);
|
|
992
|
+
if (previous === button) return;
|
|
993
|
+
if (previous) this.chromeObserver?.unobserve(previous);
|
|
994
|
+
if (button) {
|
|
995
|
+
this.tabButtons.set(key, button);
|
|
996
|
+
this.chromeObserver?.observe(button);
|
|
997
|
+
} else this.tabButtons.delete(key);
|
|
913
998
|
}
|
|
914
999
|
|
|
915
1000
|
private pageScrollElement(index: number) {
|
|
@@ -1743,26 +1828,41 @@ export class CollapsiblePagerView extends React.PureComponent<
|
|
|
1743
1828
|
return Math.min(size, Math.max(0, entry.contentWidth ?? 24)) + Math.min(128, Math.max(0, entry.trailingInset ?? 20));
|
|
1744
1829
|
}));
|
|
1745
1830
|
const segmented = variant === "segmented";
|
|
1831
|
+
const pill = variant === "pill";
|
|
1746
1832
|
const reserveTextFaces = config.controlled && variant === "text";
|
|
1833
|
+
const itemPadding = style?.itemPaddingHorizontal ?? (variant === "text" ? 10 : pill ? 14 : 8);
|
|
1834
|
+
const cssColor = (value: ReactNative.ColorValue | undefined) => value === undefined ? "transparent" : String(value);
|
|
1835
|
+
for (const key of this.tabButtonRefs.keys()) {
|
|
1836
|
+
if (!config.items.some(item => item.key === key)) this.tabButtonRefs.delete(key);
|
|
1837
|
+
}
|
|
1747
1838
|
const colorWeights = this.tabColorWeights();
|
|
1748
1839
|
const fontOwnerKey = this.tabFontOwnerKey(colorWeights);
|
|
1749
1840
|
return React.createElement("div", {
|
|
1750
1841
|
className: "ok-pager-tab-bar",
|
|
1751
1842
|
dir: this.props.layoutDirection === "rtl" || ((this.props.layoutDirection ?? "locale") === "locale" && I18nManager.isRTL) ? "rtl" : "ltr",
|
|
1843
|
+
"data-variant": variant,
|
|
1752
1844
|
style: { display: "flex", alignItems: "center", position: "relative", height: style?.height ?? 44,
|
|
1753
|
-
backgroundColor: String(style?.backgroundColor ?? "transparent"), minWidth: 0
|
|
1845
|
+
backgroundColor: String(style?.backgroundColor ?? "transparent"), minWidth: 0,
|
|
1846
|
+
["--pager-tab-hover" as string]: cssColor(style?.itemHoverBackgroundColor),
|
|
1847
|
+
["--pager-tab-pressed" as string]: cssColor(style?.itemPressedBackgroundColor) },
|
|
1754
1848
|
},
|
|
1755
|
-
React.createElement("style", null, `.ok-pager-tab{box-sizing:border-box;appearance:none;border:0;background:transparent;cursor:default;white-space:nowrap;flex-shrink:0;line-height:normal}.ok-pager-toolbar{box-sizing:border-box;appearance:none;border:1px solid transparent;cursor:default;display:flex;align-items:center;justify-content:center;background:var(--pager-toolbar-base)}.ok-pager-toolbar:hover:enabled{background:var(--pager-toolbar-hover)}.ok-pager-toolbar:active:enabled{background:var(--pager-toolbar-pressed)}`),
|
|
1756
|
-
React.createElement("div", {
|
|
1849
|
+
React.createElement("style", null, `.ok-pager-tab{box-sizing:border-box;appearance:none;border:0;background:transparent;cursor:default;white-space:nowrap;flex-shrink:0;line-height:normal}.ok-pager-tab-bar[data-variant=pill] .ok-pager-tab{position:relative;z-index:1;border-radius:999px}.ok-pager-tab-bar[data-variant=pill] .ok-pager-tab[aria-selected=false]:hover{background:var(--pager-tab-hover)}.ok-pager-tab-bar[data-variant=pill] .ok-pager-tab[aria-selected=false]:active{background:var(--pager-tab-pressed)}.ok-pager-tablist{scrollbar-width:none}.ok-pager-tablist::-webkit-scrollbar{display:none}.ok-pager-toolbar{box-sizing:border-box;appearance:none;border:1px solid transparent;cursor:default;display:flex;align-items:center;justify-content:center;background:var(--pager-toolbar-base)}.ok-pager-toolbar:hover:enabled{background:var(--pager-toolbar-hover)}.ok-pager-toolbar:active:enabled{background:var(--pager-toolbar-pressed)}`),
|
|
1850
|
+
React.createElement("div", { className: "ok-pager-tab-row", style: { display: "flex", alignItems: "center", height: "100%", flex: 1, minWidth: 0,
|
|
1851
|
+
maxWidth: style?.contentMaxWidth, margin: style?.contentMaxWidth === undefined ? undefined : "0 auto" } },
|
|
1852
|
+
React.createElement("div", { role: "tablist", className: "ok-pager-tablist", ref: this.setTabList, style: { display: "flex", overflowX: segmented ? "hidden" : "auto", flex: 1,
|
|
1853
|
+
position: "relative", alignItems: "center",
|
|
1757
1854
|
padding: `${style?.contentPaddingVertical ?? 0}px ${style?.contentPaddingHorizontal ?? 20}px`, gap: style?.itemSpacing ?? 8 } },
|
|
1855
|
+
pill ? React.createElement("div", { key: "ok-pager-tab-pill", ref: this.setTabPill, className: "ok-pager-tab-pill", "aria-hidden": true,
|
|
1856
|
+
style: { position: "absolute", left: 0, top: 0, width: 0, height: 0, borderRadius: 999, pointerEvents: "none", visibility: "hidden",
|
|
1857
|
+
backgroundColor: String(style?.indicatorColor ?? "#000000"), willChange: "transform, width" } }) : null,
|
|
1758
1858
|
...config.items.map((item, position) => {
|
|
1759
1859
|
const selected = item.key === selectedKey;
|
|
1760
1860
|
const fontSelected = item.key === fontOwnerKey;
|
|
1761
1861
|
return React.createElement("button", {
|
|
1762
1862
|
key: item.key, role: "tab", type: "button", className: "ok-pager-tab", "aria-selected": selected,
|
|
1763
|
-
ref:
|
|
1863
|
+
ref: this.tabButtonRef(item.key),
|
|
1764
1864
|
"aria-label": item.accessibilityLabel ?? item.title, "data-testid": item.testID,
|
|
1765
|
-
style: { padding:
|
|
1865
|
+
style: { padding: `6px ${itemPadding}px`, minWidth: 44, height: (style?.height ?? 44) - 2 * (style?.contentPaddingVertical ?? 0),
|
|
1766
1866
|
fontSize: style?.fontSize ?? (variant === "text" ? 18 : 16),
|
|
1767
1867
|
fontWeight: variant === "text" && fontSelected ? 600 : 500,
|
|
1768
1868
|
fontFamily: reserveTextFaces ? style?.fontFamily : fontSelected ? style?.activeFontFamily ?? style?.fontFamily : style?.fontFamily,
|
|
@@ -1770,8 +1870,9 @@ export class CollapsiblePagerView extends React.PureComponent<
|
|
|
1770
1870
|
gridTemplateAreas: reserveTextFaces ? '"label"' : undefined,
|
|
1771
1871
|
alignItems: reserveTextFaces ? "center" : undefined,
|
|
1772
1872
|
color: this.tabColor(selected, colorWeights ? colorWeights.get(item.key) ?? 0 : undefined),
|
|
1773
|
-
flex: segmented ? 1 : undefined, borderRadius: segmented ? 999 : 0,
|
|
1774
|
-
|
|
1873
|
+
flex: segmented ? 1 : undefined, borderRadius: segmented || pill ? 999 : 0,
|
|
1874
|
+
// Pill items leave the background to CSS so hover / pressed apply.
|
|
1875
|
+
backgroundColor: pill ? undefined : segmented && selected ? String(style?.indicatorColor ?? "transparent") : "transparent",
|
|
1775
1876
|
borderBottom: variant === "underline" && selected ? `${style?.indicatorHeight ?? 2}px solid ${String(style?.indicatorColor ?? "#000000")}` : undefined },
|
|
1776
1877
|
onClick: () => {
|
|
1777
1878
|
if (!config.controlled) {
|
|
@@ -1792,7 +1893,7 @@ export class CollapsiblePagerView extends React.PureComponent<
|
|
|
1792
1893
|
}, item.title)),
|
|
1793
1894
|
] : item.title);
|
|
1794
1895
|
})),
|
|
1795
|
-
config.toolbar !== undefined ? React.createElement("div", { ref: this.setToolbarSlot, className: "ok-pager-toolbar-slot", style: { flexShrink: 0, width: reservedWidth, height: "100%", position: "relative" } }) : null);
|
|
1896
|
+
config.toolbar !== undefined ? React.createElement("div", { ref: this.setToolbarSlot, className: "ok-pager-toolbar-slot", style: { flexShrink: 0, width: reservedWidth, height: "100%", position: "relative" } }) : null));
|
|
1796
1897
|
}
|
|
1797
1898
|
|
|
1798
1899
|
render() {
|