@onekeyfe/react-native-pager-view 6.7.0-46 → 6.7.0-47
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 +159 -136
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -1,5 +1,158 @@
|
|
|
1
|
+
<div align="center">
|
|
2
|
+
|
|
1
3
|
# @onekeyfe/react-native-pager-view
|
|
2
4
|
|
|
5
|
+
**OneKey's Fabric fork of `react-native-pager-view`: swipeable pages, a collapsible shared header and a native vertical scroller.**
|
|
6
|
+
|
|
7
|
+
[](https://www.npmjs.com/package/@onekeyfe/react-native-pager-view)
|
|
8
|
+
[](LICENSE)
|
|
9
|
+

|
|
10
|
+

|
|
11
|
+

|
|
12
|
+

|
|
13
|
+
|
|
14
|
+
</div>
|
|
15
|
+
|
|
16
|
+
PagerView flips horizontally or vertically between keyed child pages, rendered by
|
|
17
|
+
a Fabric native view on iOS and Android and by a DOM fallback on Web. This fork
|
|
18
|
+
adds `CollapsiblePagerView` — a header that collapses into a pinned sticky bar
|
|
19
|
+
while pages keep their own offsets and retention window — and `NativeScroller`, a
|
|
20
|
+
non-virtualized vertical scroller that joins that collapse. Upstream remains the
|
|
21
|
+
reference for the original pager behavior.
|
|
22
|
+
|
|
23
|
+
## Features
|
|
24
|
+
|
|
25
|
+
- **Native paging** — horizontal/vertical pages with `setPage`,
|
|
26
|
+
`setPageWithoutAnimation`, `setScrollEnabled` and page events.
|
|
27
|
+
- **Collapsible shared header** — native scroll coordination on mobile and CSS
|
|
28
|
+
scroll timelines on Web via `WebCollapsiblePagerView`.
|
|
29
|
+
- **Bounded page retention** — the selected page and configured neighbours stay
|
|
30
|
+
mounted while distant subtrees are unmounted and restored at their offset.
|
|
31
|
+
- **Native tab bar** — underline, segmented, text and pill variants, toolbar
|
|
32
|
+
slots and controlled selection.
|
|
33
|
+
|
|
34
|
+
## Installation
|
|
35
|
+
|
|
36
|
+
```sh
|
|
37
|
+
yarn add @onekeyfe/react-native-pager-view \
|
|
38
|
+
@onekeyfe/react-native-image \
|
|
39
|
+
@onekeyfe/react-native-native-logger
|
|
40
|
+
```
|
|
41
|
+
|
|
42
|
+
Peer dependencies: `react`, `react-native`, `@onekeyfe/react-native-image` (Web
|
|
43
|
+
icon helper) and `@onekeyfe/react-native-native-logger` (Android logging). Install
|
|
44
|
+
the app's iOS pods and rebuild the native binary; JavaScript-only does not
|
|
45
|
+
register the views:
|
|
46
|
+
|
|
47
|
+
```sh
|
|
48
|
+
cd ios && pod install
|
|
49
|
+
```
|
|
50
|
+
|
|
51
|
+
Android links through autolinking; deployment floors are iOS 15.1 and Android
|
|
52
|
+
API 24.
|
|
53
|
+
|
|
54
|
+
## Usage
|
|
55
|
+
|
|
56
|
+
```tsx
|
|
57
|
+
import PagerView, {
|
|
58
|
+
type PagerViewOnPageSelectedEvent,
|
|
59
|
+
} from '@onekeyfe/react-native-pager-view';
|
|
60
|
+
import { Text, View } from 'react-native';
|
|
61
|
+
|
|
62
|
+
<PagerView
|
|
63
|
+
style={{ flex: 1 }}
|
|
64
|
+
initialPage={0}
|
|
65
|
+
onPageSelected={(event: PagerViewOnPageSelectedEvent) => {
|
|
66
|
+
console.log('selected page', event.nativeEvent.position);
|
|
67
|
+
}}
|
|
68
|
+
>
|
|
69
|
+
<View key="welcome" style={{ flex: 1 }}>
|
|
70
|
+
<Text>Welcome</Text>
|
|
71
|
+
</View>
|
|
72
|
+
<View key="wallet" style={{ flex: 1 }}>
|
|
73
|
+
<Text>Wallet</Text>
|
|
74
|
+
</View>
|
|
75
|
+
</PagerView>
|
|
76
|
+
```
|
|
77
|
+
|
|
78
|
+
The application owns page keys, content and any JS header chrome; the pager owns
|
|
79
|
+
page placement and gestures. Every child must be a keyed `<View>`.
|
|
80
|
+
|
|
81
|
+
## API
|
|
82
|
+
|
|
83
|
+
### Exports
|
|
84
|
+
|
|
85
|
+
| Export | Platforms | Description |
|
|
86
|
+
| --- | :-: | --- |
|
|
87
|
+
| `PagerView` (default) | iOS, Android, Web | Swipeable page container; native page host on mobile, DOM fallback on Web. |
|
|
88
|
+
| `CollapsiblePagerView` | iOS, Android, Web | Collapsible header + sticky bar wrapper. |
|
|
89
|
+
| `WebCollapsiblePagerView`, `useWebCollapsiblePagerPage()` | Web | Explicit Web collapse root that measures omitted heights, and the selected page's scroll owner. |
|
|
90
|
+
| `NativeScroller` | iOS, Android, Web | Non-virtualized vertical scroller; the Web export is a `ScrollView` implementation. |
|
|
91
|
+
| `usePagerView({ pagesAmount })` | iOS, Android, Web | Animated pager progress, scroll state and add/remove page helpers. |
|
|
92
|
+
| `ScrollEdgeEffect` | iOS | `hard` / `soft` values for iOS 26 top scroll-edge effects. |
|
|
93
|
+
|
|
94
|
+
### `PagerView` props
|
|
95
|
+
|
|
96
|
+
| Prop | Type | Default | Platforms | Description |
|
|
97
|
+
| --- | --- | --- | :-: | --- |
|
|
98
|
+
| `initialPage`, `scrollEnabled`, `orientation` | `number`, `boolean`, `'horizontal' \| 'vertical'` | `0`, `true`, `'horizontal'` | all | First page, swipe enablement and paging axis. |
|
|
99
|
+
| `overdrag`, `pageMargin`, `layoutDirection` | `boolean`, `number`, `'ltr' \| 'rtl' \| 'locale'` | `false`, `0`, `'ltr'` | all | Past-edge movement, gap between pages and LTR/RTL order. |
|
|
100
|
+
| `nestedScrollEnabled` | `boolean` | `false` | iOS | Coordinates gestures with a parent pager at sub-tab boundaries. |
|
|
101
|
+
| `scrollSensitivity`, `keyboardDismissMode`, `offscreenPageLimit` | platform props | `2`, `none`, native | Android | Gesture sensitivity (`2`–`8`), keyboard dismissal and offscreen pages. |
|
|
102
|
+
| `onPageScroll`, `onPageSelected`, `onPageScrollStateChanged` | event callbacks | — | all | `{ position, offset }`, `{ position }` and `idle`/`dragging`/`settling`. |
|
|
103
|
+
|
|
104
|
+
The ref exposes `setPage`, `setPageWithoutAnimation` and `setScrollEnabled`.
|
|
105
|
+
|
|
106
|
+
### `CollapsiblePagerView` props
|
|
107
|
+
|
|
108
|
+
| Prop | Type | Platforms | Description |
|
|
109
|
+
| --- | --- | :-: | --- |
|
|
110
|
+
| `header`, `stickyHeader`, `headerHeight`, `stickyHeaderHeight` | `ReactNode`, `number` | all | Collapsible content, the bar pinned after collapse and their measured heights. |
|
|
111
|
+
| `pageRetentionDistance` | `number` | all | Pages retained on each side of the selection. Defaults to `1`. |
|
|
112
|
+
| `nativeTabBar` | config object | iOS, Android, Web | Items, `controlled`/`selectedKey`, toolbar map and style variant. |
|
|
113
|
+
| `nativeTabPressAnimationEnabled` | `boolean` | iOS, Android | Per-press animation policy; see Caveats. |
|
|
114
|
+
| `onMountedPagesChanged`, `onCollapsibleStateChanged` | event callbacks | all | Mount state and settled diagnostics. |
|
|
115
|
+
| `topOverlay`, `topScrollEdgeEffect` | `ReactNode`, `'hard' \| 'soft'` | iOS 26+ | Fixed overlay above the header and UIKit's scroll-edge effect. |
|
|
116
|
+
|
|
117
|
+
The ref exposes `scrollHeaderBy(delta)` and `scrollHeaderToOffset(offset)` to move
|
|
118
|
+
the active page's collapse position.
|
|
119
|
+
|
|
120
|
+
## Platform support
|
|
121
|
+
|
|
122
|
+
| Capability | iOS | Android | Web |
|
|
123
|
+
| --- | :-: | :-: | :-: |
|
|
124
|
+
| `PagerView` paging, events and imperative commands | ✅ | ✅ | ✅ DOM fallback |
|
|
125
|
+
| `CollapsiblePagerView` shared-header collapse | ✅ native | ✅ native | ✅ CSS scroll timelines |
|
|
126
|
+
| Page retention `pageRetentionDistance` | ✅ | ✅ | ✅ |
|
|
127
|
+
| Native tab bar (underline/segmented/text/pill) | ✅ | ✅ | ✅ text/pill |
|
|
128
|
+
| `NativeScroller` non-virtualized scroller | ✅ | ✅ | ⚠️ `ScrollView` implementation |
|
|
129
|
+
| iOS 26 top overlay / scroll-edge effect | ✅ | — | — |
|
|
130
|
+
|
|
131
|
+
## Caveats
|
|
132
|
+
|
|
133
|
+
> [!IMPORTANT]
|
|
134
|
+
> Keep page child keys stable. Retention unmounts distant pages but keeps their
|
|
135
|
+
> slots and offsets; changing a key resets that page's retained state.
|
|
136
|
+
|
|
137
|
+
> [!WARNING]
|
|
138
|
+
> Omitting `nativeTabPressAnimationEnabled` animates adjacent tab presses and
|
|
139
|
+
> jumps for non-adjacent pages. Earlier versions animated every press — pass
|
|
140
|
+
> `true` to restore that behavior.
|
|
141
|
+
|
|
142
|
+
> [!NOTE]
|
|
143
|
+
> `NativeScroller` is not a virtualized list. Horizontal scrolling, sticky rows,
|
|
144
|
+
> snapping, zoom, automatic keyboard insets and the full ScrollView responder
|
|
145
|
+
> API are not provided.
|
|
146
|
+
|
|
147
|
+
## References
|
|
148
|
+
|
|
149
|
+
- [Scroll and collapse contract](docs/SPEC.md)
|
|
150
|
+
- Example pages: [pager](../../example/react-native/pages/PagerViewTestPage.tsx) and [collapsible pager](../../example/react-native/pages/MarketNativePagerExamplePage.tsx)
|
|
151
|
+
- [npm package](https://www.npmjs.com/package/@onekeyfe/react-native-pager-view)
|
|
152
|
+
- [Changelog](../../CHANGELOG.md)
|
|
153
|
+
|
|
154
|
+
## Upstream attribution
|
|
155
|
+
|
|
3
156
|
First, a sincere thank-you to Callstack and the
|
|
4
157
|
`react-native-pager-view` maintainers for their excellent work 🙏
|
|
5
158
|
|
|
@@ -16,145 +169,15 @@ unable to keep this work in patch form.
|
|
|
16
169
|
As the gap grew, we ultimately forked `react-native-pager-view` to keep
|
|
17
170
|
development and delivery stable.
|
|
18
171
|
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
- Repository: [callstack/react-native-pager-view](https://github.com/callstack/react-native-pager-view)
|
|
172
|
+
- Upstream repository:
|
|
173
|
+
[callstack/react-native-pager-view](https://github.com/callstack/react-native-pager-view)
|
|
22
174
|
- License: MIT
|
|
23
|
-
|
|
24
|
-
## Notes
|
|
25
|
-
|
|
26
175
|
- This fork includes OneKey-specific adaptations for our product requirements.
|
|
27
|
-
-
|
|
28
|
-
to the upstream repository.
|
|
29
|
-
|
|
30
|
-
## Collapsible pager
|
|
31
|
-
|
|
32
|
-
`CollapsiblePagerView` is an opt-in container. The default `PagerView` export
|
|
33
|
-
keeps its existing page lifetime and native implementation.
|
|
34
|
-
|
|
35
|
-
```tsx
|
|
36
|
-
<CollapsiblePagerView
|
|
37
|
-
header={<Header />}
|
|
38
|
-
stickyHeader={<Tabs />}
|
|
39
|
-
headerHeight={measuredHeaderHeight}
|
|
40
|
-
stickyHeaderHeight={measuredTabsHeight}
|
|
41
|
-
pageRetentionDistance={1}
|
|
42
|
-
onMountedPagesChanged={({ mountedPages }) => {
|
|
43
|
-
// Selected page plus one neighbour on each side by default.
|
|
44
|
-
}}
|
|
45
|
-
onCollapsibleStateChanged={({ nativeEvent }) => {
|
|
46
|
-
// Settled diagnostics: headerOffset, native/attached page counts, etc.
|
|
47
|
-
}}
|
|
48
|
-
>
|
|
49
|
-
{pages.map((page) => (
|
|
50
|
-
<View key={page.key}>{page.content}</View>
|
|
51
|
-
))}
|
|
52
|
-
</CollapsiblePagerView>
|
|
53
|
-
```
|
|
54
|
-
|
|
55
|
-
Page keys must remain stable. The selected page and configured neighbours stay
|
|
56
|
-
mounted for preheating; distant page slots remain in the pager while their
|
|
57
|
-
React/native heavy subtrees are unmounted. iOS and Android retain a per-key
|
|
58
|
-
scroll offset and preserve the shared header collapse when pages change. A
|
|
59
|
-
NativeList can additionally restore its own stable item-key anchor when it is
|
|
60
|
-
remounted; the pager does not replace that list-level anchor protocol or its
|
|
61
|
-
cell reuse.
|
|
62
|
-
|
|
63
|
-
On iOS the component observes the current `UIScrollView` content offset without
|
|
64
|
-
replacing its delegate. Android coordinates nested scroll with the active
|
|
65
|
-
`RecyclerView`. Web uses the active NativeList viewport automatically; another
|
|
66
|
-
Web scroll child can opt in by exposing a DOM element with
|
|
67
|
-
`data-collapsible-pager-scroll`. CSS scroll timelines drive header/sticky
|
|
68
|
-
movement, so React is not updated on each vertical scroll frame.
|
|
69
|
-
`pagerRef.current?.scrollHeaderBy(delta)` immediately moves the active page's
|
|
70
|
-
collapsible header by a finite logical distance, clamped to its measured range.
|
|
71
|
-
`scrollHeaderToOffset(offset)` targets an absolute collapse position, so a
|
|
72
|
-
keyboard's own scroll adjustment cannot add a second relative movement.
|
|
73
|
-
It is useful for revealing a focused field above a keyboard.
|
|
74
|
-
|
|
75
|
-
On Web, `WebCollapsiblePagerView` is an explicit root export of the existing Web
|
|
76
|
-
pager. It measures Header and sticky content when their heights are omitted.
|
|
77
|
-
`isActive` describes route visibility; the pager preserves a pending scroll
|
|
78
|
-
target across a short or temporarily hidden page and retries when real content
|
|
79
|
-
geometry becomes ready. `useWebCollapsiblePagerPage()` exposes the selected
|
|
80
|
-
page's scroll owner, visible metrics, content registration and pending target
|
|
81
|
-
to descendants. These Web-only APIs require a DOM when mounted. Native callers
|
|
82
|
-
continue to use `CollapsiblePagerView`.
|
|
83
|
-
|
|
84
|
-
On iOS and Android, `nativeTabBar` renders the tab bar natively and
|
|
85
|
-
`onNativeTabPress` reports presses. By default, adjacent tab presses animate and
|
|
86
|
-
non-adjacent presses jump directly to the target without passing intermediate
|
|
87
|
-
pages. Set `nativeTabPressAnimationEnabled={true}` to always animate, or `false`
|
|
88
|
-
to always jump. Swipe gestures and imperative page commands are unchanged.
|
|
89
|
-
|
|
90
|
-
The `text` variant supports `controlled`, stable `selectedKey` and one per-key
|
|
91
|
-
`toolbar` map. Controlled presses report intent; the caller keeps page commands,
|
|
92
|
-
menus and routing. Label colors follow actual page movement while selected font
|
|
93
|
-
weight follows business selection. Toolbar artwork, label, action key and selected
|
|
94
|
-
background transfer together only when the final physical page and selection
|
|
95
|
-
agree. Motion keeps the old artwork with hit/AX disabled; two present icons replace
|
|
96
|
-
in place, and only presence changes fade for about 100 ms. Omitting `toolbar`
|
|
97
|
-
reserves zero width; `{}` reserves 44 logical units, and nonempty maps use their
|
|
98
|
-
largest `contentWidth + trailingInset`. Missing/failed content keeps that slot
|
|
99
|
-
without an active control. See [the contract](docs/SPEC.md#text-tabs-controlled-selection-and-per-tab-toolbar)
|
|
100
|
-
for ownership, cancellation, progress, fallback and current acceptance limits.
|
|
101
|
-
|
|
102
|
-
> **Behavior change:** earlier versions animated every native tab press when
|
|
103
|
-
> `nativeTabPressAnimationEnabled` was omitted. Pass
|
|
104
|
-
> `nativeTabPressAnimationEnabled={true}` to keep that behavior.
|
|
176
|
+
- For original behavior and full documentation, refer to the upstream repository.
|
|
105
177
|
|
|
106
178
|
Thank you again to Callstack and everyone who contributes to
|
|
107
179
|
`react-native-pager-view` 💙
|
|
108
180
|
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
The independent iOS/Android `NativeScroller` has passing native builds and
|
|
114
|
-
focused simulator checks. The complete acceptance matrix remains open; see
|
|
115
|
-
[docs/SPEC.md](docs/SPEC.md) for the verified cases and limits. It is a
|
|
116
|
-
non-virtualized vertical scroller with one internal React content View. Fabric/Yoga lays out React children and content padding; size
|
|
117
|
-
changes are sent to native through layout props, not a JavaScript scroll loop.
|
|
118
|
-
Shared Fabric native state tracks local scroll displacement and ancestor header
|
|
119
|
-
travel separately, without per-frame JavaScript coordination. Descendant hit
|
|
120
|
-
testing and `measureInWindow` use that state; device acceptance must compare the
|
|
121
|
-
reported coordinates with visible React content after scrolling and page return.
|
|
122
|
-
The automatic flexGrow minimum uses a native-reported usable content height,
|
|
123
|
-
with static pager reservations accounted for once. This internal size event is
|
|
124
|
-
not public API and does not run on scroll frames. Before it arrives the automatic
|
|
125
|
-
minimum is zero; a larger explicit numeric minHeight remains authoritative.
|
|
126
|
-
Refresh insets and content-dependent bottom fill do not change this minimum.
|
|
127
|
-
Web continues using its existing ScrollView implementation.
|
|
128
|
-
|
|
129
|
-
The supported ScrollView subset is `contentContainerStyle` (including padding,
|
|
130
|
-
height, numeric minHeight and flexGrow), `onContentSizeChange`, `scrollEnabled`,
|
|
131
|
-
`nestedScrollEnabled`, indicators, `bounces`, `alwaysBounceVertical`,
|
|
132
|
-
`contentInset`, keyboard dismissal/persist-tap modes, `scrollEventThrottle`, and
|
|
133
|
-
the scroll/drag/momentum callbacks. Standard View props remain available.
|
|
134
|
-
`decelerationRate` applies on iOS; Android uses AndroidX's native fling physics.
|
|
135
|
-
`bounces`/`alwaysBounceVertical` and refresh tint/title are iOS controls; Android
|
|
136
|
-
uses refresh colors/background/size and does not expose a bounce policy here.
|
|
137
|
-
Tap-to-dismiss uses RN 0.86's JavaScript TextInput registry to preserve taps on
|
|
138
|
-
another input and child-handled presses; keyboard behavior requires device checks.
|
|
139
|
-
Horizontal scrolling, sticky rows, snapping, zoom, automatic keyboard insets and
|
|
140
|
-
the full ScrollView responder API are not provided.
|
|
141
|
-
|
|
142
|
-
Pass a standard `<RefreshControl refreshing={value} onRefresh={callback} />` as
|
|
143
|
-
`refreshControl`. Its enabled, tint/colors, background, offset, title/title color
|
|
144
|
-
and size props map to the component's native refresh controller; the RN refresh
|
|
145
|
-
element is not mounted. Refreshing remains controlled even if the callback does
|
|
146
|
-
not change the value. Arbitrary custom refresh components are not supported.
|
|
147
|
-
|
|
148
|
-
`NativeScrollerRef` exposes `scrollTo`, `scrollToEnd`, `flashScrollIndicators`,
|
|
149
|
-
host measurement/focus methods, `getNativeScrollRef` and `getScrollableNode`.
|
|
150
|
-
`pagerScrollKey` remains the stable primary-scroller identity. Native command
|
|
151
|
-
events use the ScrollView event shape; UIKit/AndroidX continue owning gestures
|
|
152
|
-
and momentum. Animated commands whose clamped target differs from the current
|
|
153
|
-
position emit a momentum begin/end pair; a no-op emits no new pair. A new command,
|
|
154
|
-
new touch, content-root replacement or detach ends the previous active sequence.
|
|
155
|
-
The focused JS tests verify wrapper routing, not native scrolling,
|
|
156
|
-
Yoga rendering, keyboard interaction or refresh placement on a device.
|
|
157
|
-
|
|
158
|
-
The codegen type boundary uses React Native's public `CodegenTypes` namespace.
|
|
159
|
-
RN 0.86.2/0.88.0 declaration and parser checks preserve emitted JS, native schemas
|
|
160
|
-
and the existing NativeScroller method set; no private type import patch is needed.
|
|
181
|
+
## License
|
|
182
|
+
|
|
183
|
+
MIT. See [LICENSE](LICENSE).
|