@onekeyfe/react-native-pager-view 1.1.35
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/LICENSE +21 -0
- package/README.md +306 -0
- package/android/Android.mk +45 -0
- package/android/build.gradle +237 -0
- package/android/debug.keystore +0 -0
- package/android/gradle.properties +5 -0
- package/android/registration.cpp +18 -0
- package/android/src/main/AndroidManifest.xml +4 -0
- package/android/src/main/java/com/reactnativepagerview/NestedScrollableHost.kt +148 -0
- package/android/src/main/java/com/reactnativepagerview/PagerViewViewManager.kt +222 -0
- package/android/src/main/java/com/reactnativepagerview/PagerViewViewManagerImpl.kt +228 -0
- package/android/src/main/java/com/reactnativepagerview/PagerViewViewPackage.kt +17 -0
- package/android/src/main/java/com/reactnativepagerview/ViewPagerAdapter.kt +121 -0
- package/android/src/main/java/com/reactnativepagerview/ViewPagerViewHolder.kt +21 -0
- package/android/src/main/java/com/reactnativepagerview/event/PageScrollEvent.kt +47 -0
- package/android/src/main/java/com/reactnativepagerview/event/PageScrollStateChangedEvent.kt +34 -0
- package/android/src/main/java/com/reactnativepagerview/event/PageSelectedEvent.kt +38 -0
- package/ios/PagerView.xcodeproj/project.pbxproj +274 -0
- package/ios/RCTOnPageScrollEvent.h +14 -0
- package/ios/RCTOnPageScrollEvent.m +60 -0
- package/ios/RNCPagerViewComponentView.h +11 -0
- package/ios/RNCPagerViewComponentView.mm +704 -0
- package/lib/module/PagerView.js +136 -0
- package/lib/module/PagerView.js.map +1 -0
- package/lib/module/PagerViewNativeComponent.ts +82 -0
- package/lib/module/codegen-types.d.js +2 -0
- package/lib/module/codegen-types.d.js.map +1 -0
- package/lib/module/index.js +6 -0
- package/lib/module/index.js.map +1 -0
- package/lib/module/package.json +1 -0
- package/lib/module/usePagerView.js +106 -0
- package/lib/module/usePagerView.js.map +1 -0
- package/lib/module/utils.js +27 -0
- package/lib/module/utils.js.map +1 -0
- package/lib/typescript/package.json +1 -0
- package/lib/typescript/src/PagerView.d.ts +70 -0
- package/lib/typescript/src/PagerView.d.ts.map +1 -0
- package/lib/typescript/src/PagerViewNativeComponent.d.ts +51 -0
- package/lib/typescript/src/PagerViewNativeComponent.d.ts.map +1 -0
- package/lib/typescript/src/index.d.ts +10 -0
- package/lib/typescript/src/index.d.ts.map +1 -0
- package/lib/typescript/src/usePagerView.d.ts +38 -0
- package/lib/typescript/src/usePagerView.d.ts.map +1 -0
- package/lib/typescript/src/utils.d.ts +3 -0
- package/lib/typescript/src/utils.d.ts.map +1 -0
- package/package.json +101 -0
- package/react-native-pager-view.podspec +20 -0
- package/src/PagerView.tsx +170 -0
- package/src/PagerViewNativeComponent.ts +82 -0
- package/src/codegen-types.d.ts +28 -0
- package/src/index.tsx +27 -0
- package/src/usePagerView.ts +148 -0
- package/src/utils.tsx +22 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2021 Callstack
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,306 @@
|
|
|
1
|
+
|
|
2
|
+
<a href="https://www.callstack.com/open-source?utm_campaign=generic&utm_source=github&utm_medium=referral&utm_content=react-native-pager-view" align="center">
|
|
3
|
+
<picture>
|
|
4
|
+
<img alt="React Native PagerView" src="https://github.com/user-attachments/assets/1f0f7b9f-5723-4a9c-b0f1-99ed472f3122">
|
|
5
|
+
</picture>
|
|
6
|
+
</a>
|
|
7
|
+
|
|
8
|
+
# react-native-pager-view
|
|
9
|
+
|
|
10
|
+
[](https://badge.fury.io/js/react-native-pager-view)
|
|
11
|
+
[](https://github.com/facebook/react-native/issues/23313)
|
|
12
|
+
[](https://github.com/callstack/react-native-pager-view/blob/master/LICENSE)
|
|
13
|
+
|
|
14
|
+
[](https://github.com/callstack/react-native-pager-view/actions/workflows/main.yml)
|
|
15
|
+
[](https://github.com/callstack/react-native-pager-view/actions/workflows/ios.yml)
|
|
16
|
+
[](https://github.com/callstack/react-native-pager-view/actions/workflows/android.yml)
|
|
17
|
+
|
|
18
|
+
This component allows the user to swipe left and right through pages of data. Under the hood it is using the native [Android ViewPager](https://developer.android.com/jetpack/androidx/releases/viewpager2) and the [iOS UIPageViewController](https://developer.apple.com/documentation/uikit/uipageviewcontroller) implementations. [See it in action!](https://github.com/callstack/react-native-pager-view#preview)
|
|
19
|
+
|
|
20
|
+
<br/>
|
|
21
|
+
<p align="center">
|
|
22
|
+
<img src="img/vp-carousel.gif" alt="ViewPager" width="300">
|
|
23
|
+
</p>
|
|
24
|
+
|
|
25
|
+
<br/>
|
|
26
|
+
|
|
27
|
+
## Migration
|
|
28
|
+
|
|
29
|
+
> [!WARNING]
|
|
30
|
+
> From version **7.x** only new architecture is supported.
|
|
31
|
+
|
|
32
|
+
In version **6.x** support for `transitionStyle` property has been dropped. More information [here](https://github.com/callstack/react-native-pager-view/blob/master/MIGRATION.md).
|
|
33
|
+
|
|
34
|
+
`"@react-native-community/viewpager"` library has been changed to `react-native-pager-view`. Here you can find more information, how to migrate pager view to the latest [version](https://github.com/callstack/react-native-pager-view/blob/master/MIGRATION.md)
|
|
35
|
+
|
|
36
|
+
## Getting started
|
|
37
|
+
Bun:
|
|
38
|
+
|
|
39
|
+
`bun add react-native-pager-view`
|
|
40
|
+
|
|
41
|
+
Yarn:
|
|
42
|
+
|
|
43
|
+
`yarn add react-native-pager-view`
|
|
44
|
+
|
|
45
|
+
## Linking
|
|
46
|
+
|
|
47
|
+
### >= 0.60
|
|
48
|
+
|
|
49
|
+
Autolinking will just do the job.
|
|
50
|
+
|
|
51
|
+
### < 0.60
|
|
52
|
+
|
|
53
|
+
#### Mostly automatic
|
|
54
|
+
|
|
55
|
+
`react-native link react-native-pager-view`
|
|
56
|
+
|
|
57
|
+
#### Manual linking
|
|
58
|
+
|
|
59
|
+
<details>
|
|
60
|
+
<summary>Manually link the library on iOS</summary>
|
|
61
|
+
</br>
|
|
62
|
+
|
|
63
|
+
Follow the [instructions in the React Native documentation](https://facebook.github.io/react-native/img/linking-libraries-ios#manual-linking) to manually link the framework or link using [Cocoapods](https://cocoapods.org) by adding this to your `Podfile`:
|
|
64
|
+
|
|
65
|
+
```ruby
|
|
66
|
+
pod 'react-native-pager-view', :path => '../node_modules/react-native-pager-view'
|
|
67
|
+
```
|
|
68
|
+
|
|
69
|
+
</details>
|
|
70
|
+
|
|
71
|
+
<details>
|
|
72
|
+
<summary>Manually link the library on Android</summary>
|
|
73
|
+
</br>
|
|
74
|
+
Make the following changes:
|
|
75
|
+
|
|
76
|
+
#### `android/settings.gradle`
|
|
77
|
+
|
|
78
|
+
```groovy
|
|
79
|
+
include ':react-native-pager-view'
|
|
80
|
+
project(':react-native-pager-view').projectDir = new File(rootProject.projectDir, '../node_modules/react-native-pager-view/android')
|
|
81
|
+
```
|
|
82
|
+
|
|
83
|
+
#### `android/app/build.gradle`
|
|
84
|
+
|
|
85
|
+
```groovy
|
|
86
|
+
dependencies {
|
|
87
|
+
...
|
|
88
|
+
implementation project(':react-native-pager-view')
|
|
89
|
+
}
|
|
90
|
+
```
|
|
91
|
+
|
|
92
|
+
#### `android/app/src/main/.../MainApplication.java`
|
|
93
|
+
|
|
94
|
+
On top, where imports are:
|
|
95
|
+
|
|
96
|
+
Add `import com.reactnativepagerview.PagerViewPackage;`
|
|
97
|
+
|
|
98
|
+
Add the `PagerViewPackage` class to your list of exported packages.
|
|
99
|
+
|
|
100
|
+
```java
|
|
101
|
+
@Override
|
|
102
|
+
protected List<ReactPackage> getPackages() {
|
|
103
|
+
return Arrays.<ReactPackage>asList(
|
|
104
|
+
new MainReactPackage(),
|
|
105
|
+
new PagerViewPackage()
|
|
106
|
+
);
|
|
107
|
+
}
|
|
108
|
+
```
|
|
109
|
+
|
|
110
|
+
</details>
|
|
111
|
+
|
|
112
|
+
## Usage
|
|
113
|
+
|
|
114
|
+
```js
|
|
115
|
+
import React from 'react';
|
|
116
|
+
import { StyleSheet, View, Text } from 'react-native';
|
|
117
|
+
import PagerView from 'react-native-pager-view';
|
|
118
|
+
|
|
119
|
+
const MyPager = () => {
|
|
120
|
+
return (
|
|
121
|
+
<PagerView style={styles.pagerView} initialPage={0}>
|
|
122
|
+
<View key="1">
|
|
123
|
+
<Text>First page</Text>
|
|
124
|
+
</View>
|
|
125
|
+
<View key="2">
|
|
126
|
+
<Text>Second page</Text>
|
|
127
|
+
</View>
|
|
128
|
+
</PagerView>
|
|
129
|
+
);
|
|
130
|
+
};
|
|
131
|
+
|
|
132
|
+
const styles = StyleSheet.create({
|
|
133
|
+
pagerView: {
|
|
134
|
+
flex: 1,
|
|
135
|
+
},
|
|
136
|
+
});
|
|
137
|
+
```
|
|
138
|
+
|
|
139
|
+
**Attention:** Note that you can only use `View` components as children of `PagerView` (cf. folder _/example_)
|
|
140
|
+
. For Android if `View` has own children, set prop `collapsable` to false <https://reactnative.dev/docs/view#collapsable-android>, otherwise react-native might remove those children views and and its children will be rendered as separate pages
|
|
141
|
+
|
|
142
|
+
## Advanced usage
|
|
143
|
+
|
|
144
|
+
For advanced usage please take a look into our [example project](https://github.com/callstack/react-native-pager-view/blob/master/example/src/BasicPagerViewExample.tsx)
|
|
145
|
+
|
|
146
|
+
## API
|
|
147
|
+
|
|
148
|
+
| Prop | Description | Platform |
|
|
149
|
+
| -------------------------------------------------------------------- | :-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------: | :------: |
|
|
150
|
+
| `initialPage` | Index of initial page that should be selected | both |
|
|
151
|
+
| `scrollEnabled: boolean` | Should pager view scroll, when scroll enabled | both |
|
|
152
|
+
| `onPageScroll: (e: PageScrollEvent) => void` | Executed when transitioning between pages (either because the animation for the requested page has changed or when the user is swiping/dragging between pages) | both |
|
|
153
|
+
| `onPageScrollStateChanged: (e: PageScrollStateChangedEvent) => void` | Function called when the page scrolling state has changed | both |
|
|
154
|
+
| `onPageSelected: (e: PageSelectedEvent) => void` | This callback will be called once the ViewPager finishes navigating to the selected page | both |
|
|
155
|
+
| `pageMargin: number` | Blank space to be shown between pages | both |
|
|
156
|
+
| `keyboardDismissMode: ('none' / 'on-drag')` | Determines whether the keyboard gets dismissed in response to a drag | both |
|
|
157
|
+
| `orientation: Orientation` | Set `horizontal` or `vertical` scrolling orientation (it does **not** work dynamically) | both |
|
|
158
|
+
| `overScrollMode: OverScrollMode` | Used to override default value of overScroll mode. Can be `auto`, `always` or `never`. Defaults to `auto` | Android |
|
|
159
|
+
| `offscreenPageLimit: number` | Set the number of pages that should be retained to either side of the currently visible page(s). Pages beyond this limit will be recreated from the adapter when needed. Defaults to RecyclerView's caching strategy. The given value must either be larger than 0. | Android |
|
|
160
|
+
| `overdrag: boolean` | Allows for overscrolling after reaching the end or very beginning or pages. Defaults to `false` | iOS |
|
|
161
|
+
| `layoutDirection: ('ltr' / 'rtl' / 'locale')` | Specifies layout direction. Use `ltr` or `rtl` to set explicitly or `locale` to deduce from the default language script of a locale. Defaults to `locale` | both |
|
|
162
|
+
|
|
163
|
+
| Method | Description | Platform |
|
|
164
|
+
| ------------------------------------------ | :--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------: | :------: |
|
|
165
|
+
| `setPage(index: number)` | Function to scroll to a specific page in the PagerView. Invalid index is ignored. | both |
|
|
166
|
+
| `setPageWithoutAnimation(index: number)` | Function to scroll to a specific page in the PagerView. Invalid index is ignored. | both |
|
|
167
|
+
| `setScrollEnabled(scrollEnabled: boolean)` | A helper function to enable/disable scroll imperatively. The recommended way is using the scrollEnabled prop, however, there might be a case where a imperative solution is more useful (e.g. for not blocking an animation) | both |
|
|
168
|
+
|
|
169
|
+
## Contributing
|
|
170
|
+
|
|
171
|
+
See the [contributing guide](CONTRIBUTING.md) to learn how to contribute to the repository and the development workflow.
|
|
172
|
+
|
|
173
|
+
## Known Issues
|
|
174
|
+
|
|
175
|
+
- `flex:1` does not work for child views, please use `width: '100%', height: '100%'` [instead](https://github.com/callstack/react-native-pager-view/issues/186#issuecomment-675320732)
|
|
176
|
+
|
|
177
|
+
- [iOS]: In case of `UIViewControllerHierarchyInconsistency` error, please use below fix:
|
|
178
|
+
|
|
179
|
+
```
|
|
180
|
+
requestAnimationFrame(() => refPagerView.current?.setPage(index));
|
|
181
|
+
```
|
|
182
|
+
|
|
183
|
+
## Preview
|
|
184
|
+
|
|
185
|
+
### Android
|
|
186
|
+
|
|
187
|
+
| horizontal | vertical |
|
|
188
|
+
| :---------------------------------------------------------------: | :------------------------------------------------------------------------: |
|
|
189
|
+
| <img src="img/android-viewpager.gif" alt="ViewPager" width="325"> | <img src="img/android-viewpager-vertical.gif" alt="ViewPager" width="325"> |
|
|
190
|
+
|
|
191
|
+
### iOS
|
|
192
|
+
|
|
193
|
+
| horizontal | vertical |
|
|
194
|
+
| :------------------------------------------------------------------: | :--------------------------------------------------------------------: |
|
|
195
|
+
| <img src="img/ios-viewpager-scroll.gif" alt="ViewPager" width="325"> | <img src="img/ios-viewpager-vertical.gif" alt="ViewPager" width="325"> |
|
|
196
|
+
|
|
197
|
+
## Reanimated onPageScroll handler
|
|
198
|
+
|
|
199
|
+
An example can be found [here](https://github.com/callstack/react-native-pager-view/blob/master/example/src/ReanimatedOnPageScrollExample.tsx)
|
|
200
|
+
|
|
201
|
+
#### Instructions
|
|
202
|
+
|
|
203
|
+
To attach reanimated handler with `onPageScroll` follow the below steps.
|
|
204
|
+
|
|
205
|
+
```jsx
|
|
206
|
+
// 1. Define the handler
|
|
207
|
+
function usePageScrollHandler(handlers, dependencies) {
|
|
208
|
+
const { context, doDependenciesDiffer } = useHandler(handlers, dependencies);
|
|
209
|
+
const subscribeForEvents = ['onPageScroll'];
|
|
210
|
+
|
|
211
|
+
return useEvent(
|
|
212
|
+
(event) => {
|
|
213
|
+
'worklet';
|
|
214
|
+
const { onPageScroll } = handlers;
|
|
215
|
+
if (onPageScroll && event.eventName.endsWith('onPageScroll')) {
|
|
216
|
+
onPageScroll(event, context);
|
|
217
|
+
}
|
|
218
|
+
},
|
|
219
|
+
subscribeForEvents,
|
|
220
|
+
doDependenciesDiffer
|
|
221
|
+
);
|
|
222
|
+
}
|
|
223
|
+
|
|
224
|
+
// 2. Attach the event handler
|
|
225
|
+
import PagerView from 'react-native-pager-view';
|
|
226
|
+
import Animated from 'react-native-reanimated';
|
|
227
|
+
const AnimatedPagerView = Animated.createAnimatedComponent(PagerView);
|
|
228
|
+
|
|
229
|
+
const pageScrollHandler = usePageScrollHandler({
|
|
230
|
+
onPageScroll: (e) => {
|
|
231
|
+
'worklet';
|
|
232
|
+
offset.value = e.offset;
|
|
233
|
+
console.log(e.offset, e.position);
|
|
234
|
+
},
|
|
235
|
+
});
|
|
236
|
+
|
|
237
|
+
<AnimatedPagerView onPageScroll={pageScrollHandler} />;
|
|
238
|
+
```
|
|
239
|
+
|
|
240
|
+
## usePagerView Hook Usage
|
|
241
|
+
The `usePagerView` hook is a convenient way to manage the state and control the behavior of the `<PagerView />` component. It provides functions and variables to interact with the pager, such as navigating between pages and enabling/disabling scrolling.
|
|
242
|
+
|
|
243
|
+
Below is an example of how to use the usePager hook:
|
|
244
|
+
|
|
245
|
+
```jsx
|
|
246
|
+
export function PagerHookExample() {
|
|
247
|
+
const { AnimatedPagerView, ref, ...rest } = usePagerView({ pagesAmount: 10 });
|
|
248
|
+
|
|
249
|
+
return (
|
|
250
|
+
<SafeAreaView style={styles.container}>
|
|
251
|
+
<AnimatedPagerView
|
|
252
|
+
testID="pager-view"
|
|
253
|
+
ref={ref}
|
|
254
|
+
style={styles.PagerView}
|
|
255
|
+
initialPage={0}
|
|
256
|
+
layoutDirection="ltr"
|
|
257
|
+
overdrag={rest.overdragEnabled}
|
|
258
|
+
scrollEnabled={rest.scrollEnabled}
|
|
259
|
+
onPageScroll={rest.onPageScroll}
|
|
260
|
+
onPageSelected={rest.onPageSelected}
|
|
261
|
+
onPageScrollStateChanged={rest.onPageScrollStateChanged}
|
|
262
|
+
pageMargin={10}
|
|
263
|
+
orientation="horizontal"
|
|
264
|
+
>
|
|
265
|
+
{useMemo(
|
|
266
|
+
() =>
|
|
267
|
+
rest.pages.map((_, index) => (
|
|
268
|
+
<View
|
|
269
|
+
testID="pager-view-content"
|
|
270
|
+
key={index}
|
|
271
|
+
style={{
|
|
272
|
+
flex: 1,
|
|
273
|
+
backgroundColor: '#fdc08e',
|
|
274
|
+
alignItems: 'center',
|
|
275
|
+
padding: 20,
|
|
276
|
+
}}
|
|
277
|
+
collapsable={false}
|
|
278
|
+
>
|
|
279
|
+
<LikeCount />
|
|
280
|
+
<Text testID={`pageNumber${index}`}>
|
|
281
|
+
{`page number ${index}`}
|
|
282
|
+
</Text>
|
|
283
|
+
</View>
|
|
284
|
+
)),
|
|
285
|
+
[rest.pages]
|
|
286
|
+
)}
|
|
287
|
+
</AnimatedPagerView>
|
|
288
|
+
<NavigationPanel {...rest} />
|
|
289
|
+
</SafeAreaView>
|
|
290
|
+
);
|
|
291
|
+
}
|
|
292
|
+
```
|
|
293
|
+
### How the Example Works:
|
|
294
|
+
|
|
295
|
+
- **Pager View Setup**: The `AnimatedPagerView` component wraps `PagerView` in React Native's animation capabilities. It accepts multiple props from the `usePager` hook, such as `overdragEnabled`, `scrollEnabled`, `onPageScroll`, `onPageSelected`, and others to manage pager behavior.
|
|
296
|
+
|
|
297
|
+
- **Rendering Pages**: The pages are dynamically generated using the `rest.pages` array (initialized by `usePager`). The `useMemo` hook ensures the pages are only recomputed when necessary for performance reasons.
|
|
298
|
+
|
|
299
|
+
### Conclusion
|
|
300
|
+
|
|
301
|
+
The `usePager` hook makes it easy to handle pagination with dynamic views. This example demonstrates how to set up a simple paginated interface where users can scroll through pages, interact with page elements, and control the pager with external navigation.
|
|
302
|
+
|
|
303
|
+
|
|
304
|
+
## License
|
|
305
|
+
|
|
306
|
+
MIT
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
THIS_DIR := $(call my-dir)
|
|
2
|
+
|
|
3
|
+
include $(REACT_ANDROID_DIR)/Android-prebuilt.mk
|
|
4
|
+
|
|
5
|
+
include ${GENERATED_SRC_DIR}/codegen/jni/Android.mk
|
|
6
|
+
|
|
7
|
+
include $(CLEAR_VARS)
|
|
8
|
+
|
|
9
|
+
LOCAL_PATH := $(THIS_DIR)
|
|
10
|
+
|
|
11
|
+
# Define the library name here.
|
|
12
|
+
LOCAL_MODULE := ${CODEGEN_MODULE_NAME}_registration
|
|
13
|
+
|
|
14
|
+
LOCAL_SRC_FILES := $(wildcard $(LOCAL_PATH)/*.cpp)
|
|
15
|
+
|
|
16
|
+
LOCAL_SHARED_LIBRARIES := \
|
|
17
|
+
libfabricjni \
|
|
18
|
+
libfbjni \
|
|
19
|
+
libglog \
|
|
20
|
+
libjsi \
|
|
21
|
+
libreact_codegen_rncore \
|
|
22
|
+
libreact_codegen_${CODEGEN_MODULE_NAME} \
|
|
23
|
+
libreact_debug \
|
|
24
|
+
libreact_nativemodule_core \
|
|
25
|
+
libreact_render_componentregistry \
|
|
26
|
+
libreact_render_core \
|
|
27
|
+
libreact_render_debug \
|
|
28
|
+
libreact_render_graphics \
|
|
29
|
+
librrc_view \
|
|
30
|
+
libruntimeexecutor \
|
|
31
|
+
libturbomodulejsijni \
|
|
32
|
+
libyoga
|
|
33
|
+
|
|
34
|
+
ifneq ($(filter $(call modules-get-list),folly_runtime),)
|
|
35
|
+
LOCAL_SHARED_LIBRARIES += libfolly_runtime # since react-native@0.69
|
|
36
|
+
else
|
|
37
|
+
LOCAL_SHARED_LIBRARIES += libfolly_futures libfolly_json # react-native@0.68
|
|
38
|
+
endif
|
|
39
|
+
|
|
40
|
+
LOCAL_CFLAGS := \
|
|
41
|
+
-DLOG_TAG=\"ReactNative\" \
|
|
42
|
+
-DCODEGEN_COMPONENT_DESCRIPTOR_H="<react/renderer/components/${CODEGEN_MODULE_NAME}/ComponentDescriptors.h>"
|
|
43
|
+
LOCAL_CFLAGS += -fexceptions -frtti -std=c++17 -Wall
|
|
44
|
+
|
|
45
|
+
include $(BUILD_SHARED_LIBRARY)
|
|
@@ -0,0 +1,237 @@
|
|
|
1
|
+
buildscript {
|
|
2
|
+
// Buildscript is evaluated before everything else so we can't use getExtOrDefault
|
|
3
|
+
def kotlin_version = rootProject.ext.has('kotlinVersion') ? rootProject.ext.get('kotlinVersion') : project.properties['PagerView_kotlinVersion']
|
|
4
|
+
|
|
5
|
+
repositories {
|
|
6
|
+
google()
|
|
7
|
+
mavenCentral()
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
dependencies {
|
|
11
|
+
classpath "com.android.tools.build:gradle:8.7.2"
|
|
12
|
+
// noinspection DifferentKotlinGradleVersion
|
|
13
|
+
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
|
|
14
|
+
}
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
def isNewArchitectureEnabled() {
|
|
18
|
+
return rootProject.hasProperty("newArchEnabled") && rootProject.getProperty("newArchEnabled") == "true"
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
apply plugin: 'com.android.library'
|
|
22
|
+
apply plugin: 'kotlin-android'
|
|
23
|
+
|
|
24
|
+
|
|
25
|
+
if (isNewArchitectureEnabled()) {
|
|
26
|
+
apply plugin: 'com.facebook.react'
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
def getExtOrDefault(name) {
|
|
30
|
+
return rootProject.ext.has(name) ? rootProject.ext.get(name) : project.properties['PagerView_' + name]
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
def getExtOrIntegerDefault(name) {
|
|
34
|
+
return rootProject.ext.has(name) ? rootProject.ext.get(name) : (project.properties['PagerView_' + name]).toInteger()
|
|
35
|
+
}
|
|
36
|
+
def agpVersion = com.android.Version.ANDROID_GRADLE_PLUGIN_VERSION.tokenize('.')[0].toInteger()
|
|
37
|
+
def shouldUseNameSpace = agpVersion >= 8
|
|
38
|
+
def PACKAGE_PROP = "package=\"com.reactnativepagerview\""
|
|
39
|
+
def manifestOutFile = file("${projectDir}/src/main/AndroidManifest.xml")
|
|
40
|
+
def manifestContent = manifestOutFile.getText()
|
|
41
|
+
if(shouldUseNameSpace){
|
|
42
|
+
manifestContent = manifestContent.replaceAll(
|
|
43
|
+
PACKAGE_PROP,
|
|
44
|
+
''
|
|
45
|
+
)
|
|
46
|
+
} else {
|
|
47
|
+
if(!manifestContent.contains("$PACKAGE_PROP")){
|
|
48
|
+
manifestContent = manifestContent.replace(
|
|
49
|
+
'<manifest',
|
|
50
|
+
"<manifest $PACKAGE_PROP "
|
|
51
|
+
)
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
manifestContent = manifestContent.replaceAll(" ", " ")
|
|
55
|
+
manifestOutFile.write(manifestContent)
|
|
56
|
+
|
|
57
|
+
import groovy.json.JsonSlurper
|
|
58
|
+
|
|
59
|
+
// https://github.com/callstack/react-native-builder-bob/discussions/359
|
|
60
|
+
def registrationCompat = {
|
|
61
|
+
def reactAndroidProject = rootProject.allprojects.find { it.name == 'ReactAndroid' }
|
|
62
|
+
if (reactAndroidProject == null) return false
|
|
63
|
+
|
|
64
|
+
def reactNativeManifest = file("${reactAndroidProject.projectDir}/../package.json")
|
|
65
|
+
def reactNativeVersion = new JsonSlurper().parseText(reactNativeManifest.text).version as String
|
|
66
|
+
// Fabric was introduced at react-native@0.68, full CMake support were introduced at react-native@0.71
|
|
67
|
+
// Use Android.mk for compatibility with react-native@0.68/0.69
|
|
68
|
+
reactNativeVersion.matches('(0.68.*|0.69.*)')
|
|
69
|
+
}()
|
|
70
|
+
|
|
71
|
+
def codegenViewLibraryName = "RNCViewPager"
|
|
72
|
+
def codegenViewModuleName = {
|
|
73
|
+
// Autolink for Fabric uses codegenConfig.name in package.json since react-native@0.70
|
|
74
|
+
// Use codegenViewLibraryName for compatibility with react-native@0.68/0.69
|
|
75
|
+
def libraryManifestJson = new JsonSlurper().parseText(file("$projectDir/../package.json").text)
|
|
76
|
+
registrationCompat ? codegenViewLibraryName : libraryManifestJson.codegenConfig.name
|
|
77
|
+
}()
|
|
78
|
+
|
|
79
|
+
def appProject = rootProject.allprojects.find { it.plugins.hasPlugin('com.android.application') }
|
|
80
|
+
|
|
81
|
+
android {
|
|
82
|
+
compileSdkVersion getExtOrIntegerDefault('compileSdkVersion')
|
|
83
|
+
if (shouldUseNameSpace){
|
|
84
|
+
namespace = "com.reactnativepagerview"
|
|
85
|
+
buildFeatures {
|
|
86
|
+
buildConfig true
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
defaultConfig {
|
|
90
|
+
minSdkVersion getExtOrIntegerDefault('minSdkVersion')
|
|
91
|
+
targetSdkVersion getExtOrIntegerDefault('targetSdkVersion')
|
|
92
|
+
buildConfigField "boolean", "IS_NEW_ARCHITECTURE_ENABLED", isNewArchitectureEnabled().toString()
|
|
93
|
+
|
|
94
|
+
buildConfigField "String", "CODEGEN_MODULE_REGISTRATION", (isNewArchitectureEnabled() && registrationCompat ? "\"${codegenViewModuleName}_registration\"" : "null")
|
|
95
|
+
|
|
96
|
+
if (isNewArchitectureEnabled() && registrationCompat) {
|
|
97
|
+
def reactAndroidProject = project(':ReactAndroid')
|
|
98
|
+
externalNativeBuild {
|
|
99
|
+
ndkBuild {
|
|
100
|
+
arguments "APP_PLATFORM=android-21",
|
|
101
|
+
"APP_STL=c++_shared",
|
|
102
|
+
"NDK_TOOLCHAIN_VERSION=clang",
|
|
103
|
+
"GENERATED_SRC_DIR=$buildDir/generated/source", // for react_codegen_* in this library's codegen/jni
|
|
104
|
+
"PROJECT_BUILD_DIR=${appProject.buildDir}", // for REACT_NDK_EXPORT_DIR in ReactAndroid's Android-prebuilt.mk
|
|
105
|
+
"REACT_ANDROID_DIR=${reactAndroidProject.projectDir}",
|
|
106
|
+
"REACT_ANDROID_BUILD_DIR=${reactAndroidProject.buildDir}",
|
|
107
|
+
"CODEGEN_MODULE_NAME=$codegenViewModuleName"
|
|
108
|
+
cFlags "-Wall", "-Werror", "-fexceptions", "-frtti", "-DWITH_INSPECTOR=1"
|
|
109
|
+
cppFlags "-std=c++17"
|
|
110
|
+
targets "${codegenViewModuleName}_registration"
|
|
111
|
+
}
|
|
112
|
+
}
|
|
113
|
+
}
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
if (isNewArchitectureEnabled() && registrationCompat) {
|
|
117
|
+
// We configure the NDK build only if you decide to opt-in for the New Architecture.
|
|
118
|
+
externalNativeBuild {
|
|
119
|
+
ndkBuild {
|
|
120
|
+
path "Android.mk"
|
|
121
|
+
}
|
|
122
|
+
}
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
buildTypes {
|
|
126
|
+
release {
|
|
127
|
+
minifyEnabled false
|
|
128
|
+
}
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
lintOptions {
|
|
132
|
+
disable 'GradleCompatible'
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
compileOptions {
|
|
136
|
+
sourceCompatibility JavaVersion.VERSION_1_8
|
|
137
|
+
targetCompatibility JavaVersion.VERSION_1_8
|
|
138
|
+
}
|
|
139
|
+
sourceSets {
|
|
140
|
+
main {
|
|
141
|
+
if (isNewArchitectureEnabled()) {
|
|
142
|
+
java.srcDirs += [
|
|
143
|
+
"src/fabric/java",
|
|
144
|
+
"${project.buildDir}/generated/source/codegen/java"
|
|
145
|
+
]
|
|
146
|
+
} else {
|
|
147
|
+
java.srcDirs += ["src/paper/java"]
|
|
148
|
+
}
|
|
149
|
+
}
|
|
150
|
+
}
|
|
151
|
+
}
|
|
152
|
+
|
|
153
|
+
repositories {
|
|
154
|
+
mavenCentral()
|
|
155
|
+
google()
|
|
156
|
+
|
|
157
|
+
def found = false
|
|
158
|
+
def defaultDir = null
|
|
159
|
+
def androidSourcesName = 'React Native sources'
|
|
160
|
+
|
|
161
|
+
if (rootProject.ext.has('reactNativeAndroidRoot')) {
|
|
162
|
+
defaultDir = rootProject.ext.get('reactNativeAndroidRoot')
|
|
163
|
+
} else {
|
|
164
|
+
defaultDir = new File(
|
|
165
|
+
projectDir,
|
|
166
|
+
'/../../../node_modules/react-native/android'
|
|
167
|
+
)
|
|
168
|
+
}
|
|
169
|
+
|
|
170
|
+
if (defaultDir.exists()) {
|
|
171
|
+
maven {
|
|
172
|
+
url defaultDir.toString()
|
|
173
|
+
name androidSourcesName
|
|
174
|
+
}
|
|
175
|
+
|
|
176
|
+
logger.info(":${project.name}:reactNativeAndroidRoot ${defaultDir.canonicalPath}")
|
|
177
|
+
found = true
|
|
178
|
+
} else {
|
|
179
|
+
def parentDir = rootProject.projectDir
|
|
180
|
+
|
|
181
|
+
1.upto(5, {
|
|
182
|
+
if (found) return true
|
|
183
|
+
parentDir = parentDir.parentFile
|
|
184
|
+
|
|
185
|
+
def androidSourcesDir = new File(
|
|
186
|
+
parentDir,
|
|
187
|
+
'node_modules/react-native'
|
|
188
|
+
)
|
|
189
|
+
|
|
190
|
+
def androidPrebuiltBinaryDir = new File(
|
|
191
|
+
parentDir,
|
|
192
|
+
'node_modules/react-native/android'
|
|
193
|
+
)
|
|
194
|
+
|
|
195
|
+
if (androidPrebuiltBinaryDir.exists()) {
|
|
196
|
+
maven {
|
|
197
|
+
url androidPrebuiltBinaryDir.toString()
|
|
198
|
+
name androidSourcesName
|
|
199
|
+
}
|
|
200
|
+
|
|
201
|
+
logger.info(":${project.name}:reactNativeAndroidRoot ${androidPrebuiltBinaryDir.canonicalPath}")
|
|
202
|
+
found = true
|
|
203
|
+
} else if (androidSourcesDir.exists()) {
|
|
204
|
+
maven {
|
|
205
|
+
url androidSourcesDir.toString()
|
|
206
|
+
name androidSourcesName
|
|
207
|
+
}
|
|
208
|
+
|
|
209
|
+
logger.info(":${project.name}:reactNativeAndroidRoot ${androidSourcesDir.canonicalPath}")
|
|
210
|
+
found = true
|
|
211
|
+
}
|
|
212
|
+
})
|
|
213
|
+
}
|
|
214
|
+
|
|
215
|
+
if (!found) {
|
|
216
|
+
throw new GradleException(
|
|
217
|
+
"${project.name}: unable to locate React Native android sources. " +
|
|
218
|
+
"Ensure you have you installed React Native as a dependency in your project and try again."
|
|
219
|
+
)
|
|
220
|
+
}
|
|
221
|
+
}
|
|
222
|
+
|
|
223
|
+
def kotlin_version = getExtOrDefault('kotlinVersion')
|
|
224
|
+
|
|
225
|
+
dependencies {
|
|
226
|
+
implementation "com.facebook.react:react-android"
|
|
227
|
+
implementation "org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version"
|
|
228
|
+
implementation 'androidx.viewpager2:viewpager2:1.1.0'
|
|
229
|
+
}
|
|
230
|
+
|
|
231
|
+
if (isNewArchitectureEnabled()) {
|
|
232
|
+
react {
|
|
233
|
+
jsRootDir = file("../src")
|
|
234
|
+
libraryName = codegenViewLibraryName
|
|
235
|
+
codegenJavaPackageName = "com.reactnativepagerview"
|
|
236
|
+
}
|
|
237
|
+
}
|
|
Binary file
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
#include <CoreComponentsRegistry.h>
|
|
2
|
+
#include CODEGEN_COMPONENT_DESCRIPTOR_H
|
|
3
|
+
|
|
4
|
+
namespace facebook {
|
|
5
|
+
namespace react {
|
|
6
|
+
|
|
7
|
+
void registerProviders() {
|
|
8
|
+
auto providerRegistry = CoreComponentsRegistry::sharedProviderRegistry();
|
|
9
|
+
providerRegistry->add(concreteComponentDescriptorProvider<RNCViewPagerComponentDescriptor>());
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
}
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
JNIEXPORT jint JNICALL JNI_OnLoad(JavaVM *vm, void *) {
|
|
16
|
+
facebook::react::registerProviders();
|
|
17
|
+
return JNI_VERSION_1_6;
|
|
18
|
+
}
|