@react-native-ohos/react-native-pager-view 6.7.2-rc.1 → 7.0.3-rc.1

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.
Files changed (49) hide show
  1. package/README.OpenSource +10 -10
  2. package/README.md +1 -1
  3. package/harmony/pager_view/oh-package.json5 +1 -1
  4. package/harmony/pager_view/src/main/cpp/SwiperNode.cpp +3 -0
  5. package/harmony/pager_view/src/main/cpp/SwiperNode.h +2 -0
  6. package/harmony/pager_view/src/main/cpp/ViewPagerComponentInstance.cpp +4 -1
  7. package/harmony/pager_view.har +0 -0
  8. package/lib/commonjs/PagerView.js +88 -66
  9. package/lib/commonjs/PagerView.js.map +1 -1
  10. package/lib/commonjs/PagerViewNativeComponent.js +24 -0
  11. package/lib/commonjs/PagerViewNativeComponent.js.map +1 -1
  12. package/lib/commonjs/index.js +23 -0
  13. package/lib/commonjs/index.js.map +1 -1
  14. package/lib/commonjs/package.json +1 -0
  15. package/lib/commonjs/usePagerView.js +25 -4
  16. package/lib/commonjs/usePagerView.js.map +1 -1
  17. package/lib/commonjs/utils.js +36 -7
  18. package/lib/commonjs/utils.js.map +1 -1
  19. package/lib/module/PagerView.js +89 -67
  20. package/lib/module/PagerView.js.map +1 -1
  21. package/lib/module/PagerViewNativeComponent.js +26 -0
  22. package/lib/module/PagerViewNativeComponent.js.map +1 -1
  23. package/lib/module/index.js +26 -0
  24. package/lib/module/index.js.map +1 -1
  25. package/lib/module/usePagerView.js +27 -4
  26. package/lib/module/usePagerView.js.map +1 -1
  27. package/lib/module/utils.js +37 -7
  28. package/lib/module/utils.js.map +1 -1
  29. package/lib/typescript/PagerView.d.ts +24 -0
  30. package/lib/typescript/PagerView.d.ts.map +1 -0
  31. package/lib/typescript/PagerViewNativeComponent.d.ts +24 -0
  32. package/lib/typescript/PagerViewNativeComponent.d.ts.map +1 -0
  33. package/lib/typescript/index.d.ts +24 -0
  34. package/lib/typescript/index.d.ts.map +1 -0
  35. package/lib/typescript/usePagerView.d.ts +25 -1
  36. package/lib/typescript/usePagerView.d.ts.map +1 -0
  37. package/lib/typescript/utils.d.ts +24 -0
  38. package/lib/typescript/utils.d.ts.map +1 -0
  39. package/package.json +18 -18
  40. package/src/PagerView.tsx +23 -0
  41. package/src/PagerViewNativeComponent.ts +23 -0
  42. package/src/index.tsx +23 -0
  43. package/src/usePagerView.ts +23 -0
  44. package/src/utils.tsx +27 -1
  45. package/harmony/pager_view/LICENSE +0 -21
  46. package/harmony/pager_view/NOTICE +0 -33
  47. package/harmony/pager_view/OAT.xml +0 -38
  48. package/harmony/pager_view/README.OpenSource +0 -11
  49. package/harmony/pager_view/README.md +0 -236
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@react-native-ohos/react-native-pager-view",
3
- "version": "6.7.2-rc.1",
3
+ "version": "7.0.3-rc.1",
4
4
  "description": "React Native wrapper for Harmony ViewPager",
5
5
  "main": "lib/commonjs/index",
6
6
  "module": "lib/module/index",
@@ -36,33 +36,33 @@
36
36
  ],
37
37
  "repository": {
38
38
  "type": "git",
39
- "url": "https://github.com/react-native-oh-library/react-native-pager-view.git"
39
+ "url": "https://gitcode.com/openharmony-sig/rntpc_react-native-pager-view.git"
40
40
  },
41
41
  "author": "troZee <hello@callstack.com> (https://github.com/callstack)",
42
42
  "license": "MIT",
43
43
  "bugs": {
44
- "url": "https://github.com/callstack/react-native-pager-view/issues"
44
+ "url": "https://gitcode.com/openharmony-sig/rntpc_react-native-pager-view/issues"
45
45
  },
46
- "homepage": "https://github.com/callstack/react-native-pager-view#readme",
46
+ "homepage": "https://gitcode.com/openharmony-sig/rntpc_react-native-pager-view/tree/br_rnoh0.77#readme",
47
47
  "publishConfig": {
48
48
  "registry": "https://registry.npmjs.org/",
49
49
  "access": "public"
50
50
  },
51
51
  "dependencies": {
52
- "react-native-pager-view": "6.7.1"
52
+ "react-native-pager-view": "7.0.2"
53
53
  },
54
54
  "devDependencies": {
55
55
  "@babel/eslint-parser": "^7.20.0",
56
- "@react-native/babel-preset": "0.76.3",
57
- "@react-native/eslint-config": "0.76.3",
58
- "@react-native/metro-config": "0.76.3",
59
- "@react-native/typescript-config": "0.76.3",
60
- "@react-native-community/cli": "15.0.1",
61
- "@react-native-community/cli-platform-android": "15.0.1",
62
- "@react-native-community/cli-platform-ios": "15.0.1",
56
+ "@react-native/babel-preset": "0.82.1",
57
+ "@react-native/eslint-config": "0.82.1",
58
+ "@react-native/metro-config": "0.82.1",
59
+ "@react-native/typescript-config": "0.82.1",
60
+ "@react-native-community/cli": "20.0.0",
61
+ "@react-native-community/cli-platform-android": "20.0.0",
62
+ "@react-native-community/cli-platform-ios": "20.0.0",
63
63
  "@release-it/conventional-changelog": "^2.0.0",
64
- "@types/jest": "^29.5.12",
65
- "@types/react": "^18.2.6",
64
+ "@types/jest": "^29.5.13",
65
+ "@types/react": "^19.0.0",
66
66
  "eslint": "^8.19.0",
67
67
  "eslint-config-prettier": "^8.5.0",
68
68
  "eslint-plugin-ft-flow": "^3.0.1",
@@ -70,10 +70,10 @@
70
70
  "eslint-plugin-prettier": "^4.0.0",
71
71
  "jest": "^29.6.3",
72
72
  "metro-react-native-babel-preset": "^0.77.0",
73
- "prettier": "^2.4.1",
74
- "react": "18.3.1",
75
- "react-native": "0.77.1",
76
- "react-native-builder-bob": "^0.18.3",
73
+ "prettier": "^2.8.0",
74
+ "react": "19.1.1",
75
+ "react-native": "0.82.1",
76
+ "react-native-builder-bob": "^0.40.5",
77
77
  "release-it": "^14.2.2",
78
78
  "typescript": "5.0.4"
79
79
  },
package/src/PagerView.tsx CHANGED
@@ -1,3 +1,26 @@
1
+ /**
2
+ * MIT License
3
+ *
4
+ * Copyright (C) 2025 Huawei Device Co., Ltd.
5
+ *
6
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
7
+ * of this software and associated documentation files (the "Software"), to deal
8
+ * in the Software without restriction, including without limitation the rights
9
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10
+ * copies of the Software, and to permit persons to whom the Software is
11
+ * furnished to do so, subject to the following conditions:
12
+ *
13
+ * The above copyright notice and this permission notice shall be included in all
14
+ * copies or substantial portions of the Software.
15
+ *
16
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22
+ * SOFTWARE.
23
+ */
1
24
  import React from 'react';
2
25
  import { Platform, Keyboard } from 'react-native';
3
26
  import { I18nManager } from 'react-native';
@@ -1,3 +1,26 @@
1
+ /**
2
+ * MIT License
3
+ *
4
+ * Copyright (C) 2025 Huawei Device Co., Ltd.
5
+ *
6
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
7
+ * of this software and associated documentation files (the "Software"), to deal
8
+ * in the Software without restriction, including without limitation the rights
9
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10
+ * copies of the Software, and to permit persons to whom the Software is
11
+ * furnished to do so, subject to the following conditions:
12
+ *
13
+ * The above copyright notice and this permission notice shall be included in all
14
+ * copies or substantial portions of the Software.
15
+ *
16
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22
+ * SOFTWARE.
23
+ */
1
24
  import type * as React from 'react';
2
25
  import type { HostComponent, ViewProps } from 'react-native';
3
26
  import codegenNativeCommands from 'react-native/Libraries/Utilities/codegenNativeCommands';
package/src/index.tsx CHANGED
@@ -1,3 +1,26 @@
1
+ /**
2
+ * MIT License
3
+ *
4
+ * Copyright (C) 2025 Huawei Device Co., Ltd.
5
+ *
6
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
7
+ * of this software and associated documentation files (the "Software"), to deal
8
+ * in the Software without restriction, including without limitation the rights
9
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10
+ * copies of the Software, and to permit persons to whom the Software is
11
+ * furnished to do so, subject to the following conditions:
12
+ *
13
+ * The above copyright notice and this permission notice shall be included in all
14
+ * copies or substantial portions of the Software.
15
+ *
16
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22
+ * SOFTWARE.
23
+ */
1
24
  import type * as ReactNative from 'react-native';
2
25
  import { PagerView } from './PagerView';
3
26
  export default PagerView;
@@ -1,3 +1,26 @@
1
+ /**
2
+ * MIT License
3
+ *
4
+ * Copyright (C) 2025 Huawei Device Co., Ltd.
5
+ *
6
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
7
+ * of this software and associated documentation files (the "Software"), to deal
8
+ * in the Software without restriction, including without limitation the rights
9
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10
+ * copies of the Software, and to permit persons to whom the Software is
11
+ * furnished to do so, subject to the following conditions:
12
+ *
13
+ * The above copyright notice and this permission notice shall be included in all
14
+ * copies or substantial portions of the Software.
15
+ *
16
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22
+ * SOFTWARE.
23
+ */
1
24
  import type * as ReactNative from 'react-native';
2
25
  import type {
3
26
  OnPageScrollEventData as PagerViewOnPageScrollEventData,
package/src/utils.tsx CHANGED
@@ -1,9 +1,35 @@
1
+ /**
2
+ * MIT License
3
+ *
4
+ * Copyright (C) 2025 Huawei Device Co., Ltd.
5
+ *
6
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
7
+ * of this software and associated documentation files (the "Software"), to deal
8
+ * in the Software without restriction, including without limitation the rights
9
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10
+ * copies of the Software, and to permit persons to whom the Software is
11
+ * furnished to do so, subject to the following conditions:
12
+ *
13
+ * The above copyright notice and this permission notice shall be included in all
14
+ * copies or substantial portions of the Software.
15
+ *
16
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22
+ * SOFTWARE.
23
+ */
1
24
  import React, { Children, ReactNode } from 'react';
2
25
  import { StyleSheet, View } from 'react-native';
3
26
 
4
27
  export const childrenWithOverriddenStyle = (children?: ReactNode) => {
5
28
  return Children.map(children, (child) => {
6
- const element = child as React.ReactElement;
29
+ if (child == null || !React.isValidElement(child)) {
30
+ return null;
31
+ }
32
+ const element = child as React.ReactElement<any>;
7
33
  return (
8
34
  // Add a wrapper to ensure layout is calculated correctly
9
35
  <View style={StyleSheet.absoluteFill} collapsable={false}>
@@ -1,21 +0,0 @@
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.
@@ -1,33 +0,0 @@
1
- OPEN SOURCE SOFTWARE NOTICE
2
-
3
- Please note we provide an open source software notice for the third party open source software along with this software and/or this software component (in the following just “this SOFTWARE”). The open source software licenses are granted by the respective right holders.
4
-
5
- Warranty Disclaimer
6
- THE OPEN SOURCE SOFTWARE IN THIS PRODUCT IS DISTRIBUTED IN THE HOPE THAT IT WILL BE USEFUL, BUT WITHOUT ANY WARRANTY, WITHOUT EVEN THE IMPLIED WARRANTY OF MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE. SEE THE APPLICABLE LICENSES FOR MORE DETAILS.
7
-
8
- Copyright Notice and License Texts
9
-
10
- ----------------------------------------------------------------------
11
- Software: react-native-pager-view V6.7.1
12
-
13
- MIT License
14
-
15
- Copyright (c) 2021 Callstack
16
-
17
- Permission is hereby granted, free of charge, to any person obtaining a copy
18
- of this software and associated documentation files (the "Software"), to deal
19
- in the Software without restriction, including without limitation the rights
20
- to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
21
- copies of the Software, and to permit persons to whom the Software is
22
- furnished to do so, subject to the following conditions:
23
-
24
- The above copyright notice and this permission notice shall be included in all
25
- copies or substantial portions of the Software.
26
-
27
- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
28
- IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
29
- FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
30
- AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
31
- LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
32
- OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
33
- SOFTWARE.
@@ -1,38 +0,0 @@
1
- <?xml version="1.0" encoding="UTF-8"?>
2
- <configuration>
3
- <oatconfig>
4
- <licensefile>LICENSE</licensefile>
5
- <filefilterlist>
6
- <filefilter name="copyrightPolicyFilter" desc="Filters for compatibility,license header policies">
7
- <filteritem type="filename" name="hvigorfile.ts" desc="hvigor构建脚本,DevEco Studio自动生成,不需要添加版权头"/>
8
- <filteritem type="filename" name="*.json5" desc="hvigor工程配置文件,DevEco Studio自动生成,不需要添加版权头"/>
9
- <filteritem type="filename" name="*.proto" desc="资源文件,不需要添加版权头"/>
10
- <filteritem type="filename" name="*.json" desc="资源文件,不需要添加版权头"/>
11
- <filteritem type="filepath" name="hvigorw" desc="工程模板,不修改版权头,以防有修改版权风险"/>
12
- <filteritem type="filepath" name="hvigorw.bat" desc="工程模板,不修改版权头,以防有修改版权风险"/>
13
- <filteritem type="filepath" name="hvigor/hvigor-wrapper.js" desc="工程模板,不修改版权头,以防有修改版权风险"/>
14
- <filteritem type="filename" name="LICENSE" desc="工程文件,不修改版权头"/>
15
- </filefilter>
16
- <filefilter name="defaultPolicyFilter" desc="Filters for compatibility,license header policies">
17
- <filteritem type="filename" name="hvigorfile.ts" desc="hvigor构建脚本,DevEco Studio自动生成,不需要添加许可证头"/>
18
- <filteritem type="filename" name="*.json5" desc="hvigor工程配置文件,DevEco Studio自动生成,不需要添加许可证头"/>
19
- <filteritem type="filename" name="LICENSE" desc="原三方库证书文件无需更改,因此添加过滤"/>
20
- <filteritem type="filename" name="*.proto" desc="资源文件,不需要添加许可证头"/>
21
- <filteritem type="filename" name="*.json" desc="资源文件,不需要添加许可证头"/>
22
- <filteritem type="filepath" name="hvigorw" desc="工程模板,不修改版权头,以防有修改版权风险"/>
23
- <filteritem type="filepath" name="hvigorw.bat" desc="工程模板,不修改版权头,以防有修改版权风险"/>
24
- <filteritem type="filepath" name="hvigor/hvigor-wrapper.js" desc="工程模板,不修改版权头,以防有修改版权风险"/>
25
- </filefilter>
26
- <filefilter name="binaryFileTypePolicyFilter" desc="Filters for resources files policies">
27
- <filteritem type="filename" name="icon.png" desc="应用图标"/>
28
- <filteritem type="filename" name="app_icon.png" desc="应用图标"/>
29
- <filteritem type="filename" name="warn.png" desc="页面展示图标"/>
30
- </filefilter>
31
- </filefilterlist>
32
- <policylist>
33
- <policy name="projectPolicy" desc="">
34
- <policyitem type="license" name="MIT" path="*.*" desc="license under the MIT"/>
35
- </policy>
36
- </policylist>
37
- </oatconfig>
38
- </configuration>
@@ -1,11 +0,0 @@
1
- [
2
- {
3
- "Name": "react-native-pager-view",
4
- "License": "MIT License",
5
- "License File": "https://github.com/callstack/react-native-pager-view/blob/master/LICENSE",
6
- "Version Number": "6.7.1",
7
- "Owner" : "troZee <hello@callstack.com>",
8
- "Upstream URL": "https://github.com/callstack/react-native-pager-view",
9
- "Description": "React Native wrapper for Android, iOS, Harmony ViewPager"
10
- }
11
- ]
@@ -1,236 +0,0 @@
1
- > 模板版本:v0.0.1
2
-
3
- <p align="center">
4
- <h1 align="center"> <code>react-native-pager-view</code> </h1>
5
- </p>
6
- <p align="center">
7
- <a href="https://github.com/callstack/react-native-pager-view">
8
- <img src="https://img.shields.io/badge/platforms-android%20|%20ios%20|%20harmony%20-lightgrey.svg" alt="Supported platforms" />
9
- </a>
10
- <a href="https://github.com/callstack/react-native-pager-view/blob/master/LICENSE">
11
- <img src="https://img.shields.io/badge/license-MIT-green.svg" alt="License" />
12
- </a>
13
- </p>
14
-
15
- ## 安装与使用
16
-
17
- **正在 npm 发布中,当前请先从仓库[Release](https://github.com/react-native-oh-library/react-native-pager-view/releases)中获取库 tgz,通过使用本地依赖来安装本库。**
18
-
19
- ```bash
20
- yarn add xxx
21
- ```
22
-
23
- 或者
24
-
25
- ```bash
26
- npm install xxx
27
- ```
28
-
29
- 下面的代码展示了这个库的基本使用场景:
30
-
31
- ```js
32
- import React from "react";
33
- import { StyleSheet, View, Text } from "react-native";
34
- import PagerView from "react-native-pager-view";
35
-
36
- const MyPager = () => {
37
- return (
38
- <PagerView style={styles.pagerView} initialPage={0}>
39
- <View key="1">
40
- <Text>First page</Text>
41
- </View>
42
- <View key="2">
43
- <Text>Second page</Text>
44
- </View>
45
- </PagerView>
46
- );
47
- };
48
-
49
- const styles = StyleSheet.create({
50
- pagerView: {
51
- flex: 1,
52
- },
53
- });
54
- ```
55
-
56
- ## Link
57
-
58
- 目前鸿蒙暂不支持 AutoLink,所以 Link 步骤需要手动配置。
59
-
60
- 首先需要使用 DevEco Studio 打开项目里的鸿蒙工程 `harmony`
61
-
62
- ### 引入原生端代码
63
-
64
- 目前有两种方法:
65
-
66
- 1. 通过 har 包引入(在 IDE 完善相关功能后该方法会被遗弃,目前首选此方法);
67
- 2. 直接链接源码。
68
-
69
- 方法一:通过 har 包引入
70
- 打开 `entry/oh-package.json5`,添加以下依赖
71
-
72
- ```json
73
- "dependencies": {
74
- "rnoh": "file:../rnoh",
75
- "rnoh-pager-view": "file:../../node_modules/react-native-pager-view/harmony/pager_view.har"
76
- }
77
- ```
78
-
79
- 点击右上角的 `sync` 按钮
80
-
81
- 或者在终端执行:
82
-
83
- ```bash
84
- cd entry
85
- ohpm install
86
- ```
87
-
88
- 方法二:直接链接源码
89
- 打开 `entry/oh-package.json5`,添加以下依赖
90
-
91
- ```json
92
- "dependencies": {
93
- "rnoh": "file:../rnoh",
94
- "rnoh-pager-view": "file:../../node_modules/react-native-pager-view/harmony/pager_view"
95
- }
96
- ```
97
-
98
- 打开终端,执行:
99
-
100
- ```bash
101
- cd entry
102
- ohpm install --no-link
103
- ```
104
-
105
- ### 配置 CMakeLists 和引入 ViewPagerPackage
106
-
107
- 打开 `entry/src/main/cpp/CMakeLists.txt`,添加:
108
-
109
- ```diff
110
- project(rnapp)
111
- cmake_minimum_required(VERSION 3.4.1)
112
- set(RNOH_APP_DIR "${CMAKE_CURRENT_SOURCE_DIR}")
113
- set(OH_MODULE_DIR "${CMAKE_CURRENT_SOURCE_DIR}/../../../oh_modules")
114
- set(RNOH_CPP_DIR "${CMAKE_CURRENT_SOURCE_DIR}/../../../../../../react-native-harmony/harmony/cpp")
115
-
116
- add_subdirectory("${RNOH_CPP_DIR}" ./rn)
117
-
118
- # RNOH_BEGIN: add_package_subdirectories
119
- add_subdirectory("../../../../sample_package/src/main/cpp" ./sample-package)
120
- + add_subdirectory("${OH_MODULE_DIR}/rnoh-pager-view/src/main/cpp" ./pager_view)
121
- # RNOH_END: add_package_subdirectories
122
-
123
- add_library(rnoh_app SHARED
124
- "./PackageProvider.cpp"
125
- "${RNOH_CPP_DIR}/RNOHAppNapiBridge.cpp"
126
- )
127
-
128
- target_link_libraries(rnoh_app PUBLIC rnoh)
129
-
130
- # RNOH_BEGIN: link_packages
131
- target_link_libraries(rnoh_app PUBLIC rnoh_sample_package)
132
- + target_link_libraries(rnoh_app PUBLIC rnoh_pager_view )
133
- # RNOH_END: link_packages
134
- ```
135
-
136
- 打开 `entry/src/main/cpp/PackageProvider.cpp`,添加:
137
-
138
- ```diff
139
- #include "RNOH/PackageProvider.h"
140
- #include "SamplePackage.h"
141
- + #include "ViewPagerPackage.h"
142
-
143
- using namespace rnoh;
144
-
145
- std::vector<std::shared_ptr<Package>> PackageProvider::getPackages(Package::Context ctx) {
146
- return {
147
- std::make_shared<SamplePackage>(ctx),
148
- + std::make_shared<ViewPagerPackage>(ctx)
149
- };
150
- }
151
- ```
152
-
153
- ### 在 ArkTs 侧引入 RNCViewPager 组件
154
-
155
- 打开 `entry/src/main/ets/pages/index.ets`,添加:
156
-
157
- ```diff
158
- import {
159
- RNApp,
160
- ComponentBuilderContext,
161
- RNAbility,
162
- AnyJSBundleProvider,
163
- MetroJSBundleProvider,
164
- ResourceJSBundleProvider,
165
- } from 'rnoh'
166
- import { SampleView, SAMPLE_VIEW_TYPE, PropsDisplayer } from "rnoh-sample-package"
167
- import { createRNPackages } from '../RNPackagesFactory'
168
- + import { RNCViewPager, PAGER_VIEW_TYPE } from "rnoh-pager-view"
169
-
170
- @Builder
171
- function CustomComponentBuilder(ctx: ComponentBuilderContext) {
172
- if (ctx.descriptor.type === SAMPLE_VIEW_TYPE) {
173
- SampleView({
174
- ctx: ctx.rnohContext,
175
- tag: ctx.descriptor.tag,
176
- buildCustomComponent: CustomComponentBuilder
177
- })
178
- }
179
- + else if (ctx.descriptor.type === PAGER_VIEW_TYPE) {
180
- + RNCViewPager({
181
- + ctx: ctx.rnohContext,
182
- + tag: ctx.descriptor.tag,
183
- + buildCustomComponent: CustomComponentBuilder
184
- + })
185
- + }
186
- ...
187
- }
188
- ...
189
- ```
190
-
191
- ### 运行
192
-
193
- 点击右上角的 `sync` 按钮
194
-
195
- 或者在终端执行:
196
-
197
- ```bash
198
- cd entry
199
- ohpm install
200
- ```
201
-
202
- 然后编译、运行即可。
203
-
204
- ## 兼容性
205
-
206
- 要使用此库,需要使用正确的 React-Native 和 RNOH 版本。另外,还需要使用配套的 DevEco Studio 和 手机 ROM。
207
-
208
- 请到三方库相应的 Releases 发布地址查看 Release 配套的版本信息:[@react-native-oh-tpl/react-native-pager-view Releases](https://github.com/react-native-oh-library/react-native-pager-view/releases)
209
-
210
- ## 属性
211
-
212
- | 名称 | 说明 | 类型 | 是否必填 | 原库平台 | 鸿蒙支持 |
213
- | ---------------------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | ------------------------------ | -------- | ------------ | -------------------------- |
214
- | initialPage | Index of initial page that should be selected | number | 是 | ios,android | yes |
215
- | scrollEnabled | Should pager view scroll, when scroll enabled | bool | 是 | ios,android | yes |
216
- | onPageScroll | Executed when transitioning between pages (ether because the animation for the requested page has changed or when the user is swiping/dragging between pages) | function | 否 | ios,android | yes |
217
- | onPageScrollStateChanged | Function called when the page scrolling state has changed | function | 否 | ios,android | yes |
218
- | onPageSelected | This callback will be called once the ViewPager finishes navigating to the selected page | function | 否 | ios,android | yes |
219
- | pageMargin | Blank space to be shown between pages | number (取值范围:0~屏幕宽度) | 否 | ios,android | 仅支持取 0-368(屏幕宽度) |
220
- | keyboardDismissMode | Determines whether the keyboard gets dismissed in response to a drag | one of 'none' ,'on-drag' | 否 | ios,droid | yes |
221
- | orientation | Set horizontal or vertical scrolling orientation (it does not work dynamically) | one of horizontal vertical | 否 | ios,android | yes |
222
- | overScrollMode | Used to override default value of overScroll mode. Can be auto, always or never. Defaults to auto | one of auto, always ,never | 否 | android | yes |
223
- | offscreenPageLimit | 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. | number | 否 | android | yes |
224
- | overdrag | Allows for overscrolling after reaching the end or very beginning or pages. Defaults to false | bool | 否 | ios | yes |
225
- | layoutDirection | 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 | string | 否 | android,ios | yes |
226
- | setPage(index: number) | Function to scroll to a specific page in the PagerView. Invalid index is ignored. | function | 否 | android,ios | yes |
227
- | setPageWithoutAnimation(index: number) | Function to scroll to a specific page in the PagerView. Invalid index is ignored. | function | 否 | android,ios | yes |
228
- | setScrollEnabled(scrollEnabled: boolean) | FA 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) | function | 否 | android,ios | yes |
229
-
230
- ## 遗留问题
231
-
232
- ## 其他
233
-
234
- ## 开源协议
235
-
236
- 本项目基于 [The MIT License (MIT)](https://github.com/react-native-oh-library/react-native-pager-view/blob/harmony/LICENSE) ,请自由地享受和参与开源。