@react-native-ohos/react-native-pager-view 6.2.4-rc.4
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 +15 -0
- package/harmony/pager_view/LICENSE +21 -0
- package/harmony/pager_view/NOTICE +33 -0
- package/harmony/pager_view/README.OpenSource +11 -0
- package/harmony/pager_view/build-profile.json5 +9 -0
- package/harmony/pager_view/consumer-rules.txt +0 -0
- package/harmony/pager_view/hvigorfile.ts +6 -0
- package/harmony/pager_view/index.ets +26 -0
- package/harmony/pager_view/obfuscation-rules.txt +18 -0
- package/harmony/pager_view/oh-package.json5 +14 -0
- package/harmony/pager_view/src/main/cpp/CMakeLists.txt +9 -0
- package/harmony/pager_view/src/main/cpp/RNCViewPagerTurbomodule.cpp +42 -0
- package/harmony/pager_view/src/main/cpp/RNCViewPagerTurbomodule.h +37 -0
- package/harmony/pager_view/src/main/cpp/SwiperNode.cpp +403 -0
- package/harmony/pager_view/src/main/cpp/SwiperNode.h +120 -0
- package/harmony/pager_view/src/main/cpp/ViewPagerComponentInstance.cpp +247 -0
- package/harmony/pager_view/src/main/cpp/ViewPagerComponentInstance.h +106 -0
- package/harmony/pager_view/src/main/cpp/ViewPagerPackage.h +64 -0
- package/harmony/pager_view/src/main/cpp/generated/RNOH/generated/BaseReactNativePagerViewPackage.h +70 -0
- package/harmony/pager_view/src/main/cpp/generated/RNOH/generated/components/BaseRNCViewPagerComponentInstance.h +16 -0
- package/harmony/pager_view/src/main/cpp/generated/RNOH/generated/components/RNCViewPagerJSIBinder.h +41 -0
- package/harmony/pager_view/src/main/cpp/generated/react/renderer/components/react_native_pager_view/ComponentDescriptors.h +22 -0
- package/harmony/pager_view/src/main/cpp/generated/react/renderer/components/react_native_pager_view/EventEmitters.cpp +43 -0
- package/harmony/pager_view/src/main/cpp/generated/react/renderer/components/react_native_pager_view/EventEmitters.h +47 -0
- package/harmony/pager_view/src/main/cpp/generated/react/renderer/components/react_native_pager_view/Props.cpp +38 -0
- package/harmony/pager_view/src/main/cpp/generated/react/renderer/components/react_native_pager_view/Props.h +139 -0
- package/harmony/pager_view/src/main/cpp/generated/react/renderer/components/react_native_pager_view/ShadowNodes.cpp +19 -0
- package/harmony/pager_view/src/main/cpp/generated/react/renderer/components/react_native_pager_view/ShadowNodes.h +34 -0
- package/harmony/pager_view/src/main/cpp/generated/react/renderer/components/react_native_pager_view/States.cpp +16 -0
- package/harmony/pager_view/src/main/cpp/generated/react/renderer/components/react_native_pager_view/States.h +38 -0
- package/harmony/pager_view/src/main/ets/Logger.ets +64 -0
- package/harmony/pager_view/src/main/ets/RNCViewPager.ets +281 -0
- package/harmony/pager_view/src/main/ets/RNCViewPagerManager.ets +58 -0
- package/harmony/pager_view/src/main/ets/ViewPagerModule.ts +34 -0
- package/harmony/pager_view/src/main/ets/ViewPagerPackage.ets +57 -0
- package/harmony/pager_view/src/main/module.json5 +7 -0
- package/harmony/pager_view/src/main/resources/base/element/string.json +8 -0
- package/harmony/pager_view/src/main/resources/en_US/element/string.json +8 -0
- package/harmony/pager_view/src/main/resources/zh_CN/element/string.json +8 -0
- package/harmony/pager_view/ts.ets +26 -0
- package/harmony/pager_view.har +0 -0
- package/lib/commonjs/PagerView.js +145 -0
- package/lib/commonjs/PagerView.js.map +1 -0
- package/lib/commonjs/PagerViewNativeComponent.js +14 -0
- package/lib/commonjs/PagerViewNativeComponent.js.map +1 -0
- package/lib/commonjs/index.js +9 -0
- package/lib/commonjs/index.js.map +1 -0
- package/lib/commonjs/utils.js +28 -0
- package/lib/commonjs/utils.js.map +1 -0
- package/lib/module/PagerView.js +138 -0
- package/lib/module/PagerView.js.map +1 -0
- package/lib/module/PagerViewNativeComponent.js +7 -0
- package/lib/module/PagerViewNativeComponent.js.map +1 -0
- package/lib/module/index.js +3 -0
- package/lib/module/index.js.map +1 -0
- package/lib/module/utils.js +20 -0
- package/lib/module/utils.js.map +1 -0
- package/lib/typescript/PagerView.d.ts +70 -0
- package/lib/typescript/PagerViewNativeComponent.d.ts +36 -0
- package/lib/typescript/index.d.ts +8 -0
- package/lib/typescript/utils.d.ts +2 -0
- package/package.json +142 -0
- package/src/PagerView.tsx +163 -0
- package/src/PagerViewNativeComponent.ts +67 -0
- package/src/index.tsx +26 -0
- package/src/utils.tsx +19 -0
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import type { NativeProps as PagerViewProps } from './PagerViewNativeComponent';
|
|
3
|
+
import PagerViewView from './PagerViewNativeComponent';
|
|
4
|
+
/**
|
|
5
|
+
* Container that allows to flip left and right between child views. Each
|
|
6
|
+
* child view of the `PagerView` will be treated as a separate page
|
|
7
|
+
* and will be stretched to fill the `PagerView`.
|
|
8
|
+
*
|
|
9
|
+
* It is important all children are `<View>`s and not composite components.
|
|
10
|
+
* You can set style properties like `padding` or `backgroundColor` for each
|
|
11
|
+
* child. It is also important that each child have a `key` prop.
|
|
12
|
+
*
|
|
13
|
+
* Example:
|
|
14
|
+
*
|
|
15
|
+
* ```
|
|
16
|
+
* render: function() {
|
|
17
|
+
* return (
|
|
18
|
+
* <PagerView
|
|
19
|
+
* style={styles.PagerView}
|
|
20
|
+
* initialPage={0}>
|
|
21
|
+
* <View style={styles.pageStyle} key="1">
|
|
22
|
+
* <Text>First page</Text>
|
|
23
|
+
* </View>
|
|
24
|
+
* <View style={styles.pageStyle} key="2">
|
|
25
|
+
* <Text>Second page</Text>
|
|
26
|
+
* </View>
|
|
27
|
+
* </PagerView>
|
|
28
|
+
* );
|
|
29
|
+
* }
|
|
30
|
+
*
|
|
31
|
+
* ...
|
|
32
|
+
*
|
|
33
|
+
* var styles = {
|
|
34
|
+
* ...
|
|
35
|
+
* PagerView: {
|
|
36
|
+
* flex: 1
|
|
37
|
+
* },
|
|
38
|
+
* pageStyle: {
|
|
39
|
+
* alignItems: 'center',
|
|
40
|
+
* padding: 20,
|
|
41
|
+
* }
|
|
42
|
+
* }
|
|
43
|
+
* ```
|
|
44
|
+
*/
|
|
45
|
+
export declare class PagerView extends React.Component<PagerViewProps> {
|
|
46
|
+
private isScrolling;
|
|
47
|
+
pagerView: React.ElementRef<typeof PagerViewView> | null;
|
|
48
|
+
private _onPageScroll;
|
|
49
|
+
private _onPageScrollStateChanged;
|
|
50
|
+
private _onPageSelected;
|
|
51
|
+
/**
|
|
52
|
+
* A helper function to scroll to a specific page in the PagerView.
|
|
53
|
+
* The transition between pages will be animated.
|
|
54
|
+
*/
|
|
55
|
+
setPage: (selectedPage: number) => void;
|
|
56
|
+
/**
|
|
57
|
+
* A helper function to scroll to a specific page in the PagerView.
|
|
58
|
+
* The transition between pages will *not* be animated.
|
|
59
|
+
*/
|
|
60
|
+
setPageWithoutAnimation: (selectedPage: number) => void;
|
|
61
|
+
/**
|
|
62
|
+
* A helper function to enable/disable scroll imperatively
|
|
63
|
+
* The recommended way is using the scrollEnabled prop, however, there might be a case where a
|
|
64
|
+
* imperative solution is more useful (e.g. for not blocking an animation)
|
|
65
|
+
*/
|
|
66
|
+
setScrollEnabled: (scrollEnabled: boolean) => void;
|
|
67
|
+
private _onMoveShouldSetResponderCapture;
|
|
68
|
+
private get deducedLayoutDirection();
|
|
69
|
+
render(): JSX.Element;
|
|
70
|
+
}
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import type * as React from 'react';
|
|
2
|
+
import type { HostComponent, ViewProps } from 'react-native';
|
|
3
|
+
import type { DirectEventHandler, Double, Int32, WithDefault } from 'react-native/Libraries/Types/CodegenTypes';
|
|
4
|
+
export type OnPageScrollEventData = Readonly<{
|
|
5
|
+
position: Double;
|
|
6
|
+
offset: Double;
|
|
7
|
+
}>;
|
|
8
|
+
export type OnPageSelectedEventData = Readonly<{
|
|
9
|
+
position: Double;
|
|
10
|
+
}>;
|
|
11
|
+
export type OnPageScrollStateChangedEventData = Readonly<{
|
|
12
|
+
pageScrollState: 'idle' | 'dragging' | 'settling';
|
|
13
|
+
}>;
|
|
14
|
+
export interface NativeProps extends ViewProps {
|
|
15
|
+
scrollEnabled?: WithDefault<boolean, true>;
|
|
16
|
+
layoutDirection?: WithDefault<'ltr' | 'rtl', 'ltr'>;
|
|
17
|
+
initialPage?: Int32;
|
|
18
|
+
orientation?: WithDefault<'horizontal' | 'vertical', 'horizontal'>;
|
|
19
|
+
offscreenPageLimit?: Int32;
|
|
20
|
+
pageMargin?: Int32;
|
|
21
|
+
overScrollMode?: WithDefault<'auto' | 'always' | 'never', 'auto'>;
|
|
22
|
+
overdrag?: WithDefault<boolean, false>;
|
|
23
|
+
keyboardDismissMode?: WithDefault<'none' | 'on-drag', 'none'>;
|
|
24
|
+
onPageScroll?: DirectEventHandler<OnPageScrollEventData>;
|
|
25
|
+
onPageSelected?: DirectEventHandler<OnPageSelectedEventData>;
|
|
26
|
+
onPageScrollStateChanged?: DirectEventHandler<OnPageScrollStateChangedEventData>;
|
|
27
|
+
}
|
|
28
|
+
type PagerViewViewType = HostComponent<NativeProps>;
|
|
29
|
+
export interface NativeCommands {
|
|
30
|
+
setPage: (viewRef: React.ElementRef<PagerViewViewType>, selectedPage: Int32) => void;
|
|
31
|
+
setPageWithoutAnimation: (viewRef: React.ElementRef<PagerViewViewType>, selectedPage: Int32) => void;
|
|
32
|
+
setScrollEnabledImperatively: (viewRef: React.ElementRef<PagerViewViewType>, scrollEnabled: boolean) => void;
|
|
33
|
+
}
|
|
34
|
+
export declare const Commands: NativeCommands;
|
|
35
|
+
declare const _default: HostComponent<NativeProps>;
|
|
36
|
+
export default _default;
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import type * as ReactNative from 'react-native';
|
|
2
|
+
import { PagerView } from './PagerView';
|
|
3
|
+
export default PagerView;
|
|
4
|
+
import type { OnPageScrollEventData as PagerViewOnPageScrollEventData, OnPageSelectedEventData as PagerViewOnPageSelectedEventData, OnPageScrollStateChangedEventData as PageScrollStateChangedNativeEventData, NativeProps } from './PagerViewNativeComponent';
|
|
5
|
+
export type { PagerViewOnPageScrollEventData, PagerViewOnPageSelectedEventData, PageScrollStateChangedNativeEventData, NativeProps as PagerViewProps, };
|
|
6
|
+
export type PagerViewOnPageScrollEvent = ReactNative.NativeSyntheticEvent<PagerViewOnPageScrollEventData>;
|
|
7
|
+
export type PagerViewOnPageSelectedEvent = ReactNative.NativeSyntheticEvent<PagerViewOnPageSelectedEventData>;
|
|
8
|
+
export type PageScrollStateChangedNativeEvent = ReactNative.NativeSyntheticEvent<PageScrollStateChangedNativeEventData>;
|
package/package.json
ADDED
|
@@ -0,0 +1,142 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@react-native-ohos/react-native-pager-view",
|
|
3
|
+
"version": "6.2.4-rc.4",
|
|
4
|
+
"description": "React Native wrapper for Harmony ViewPager",
|
|
5
|
+
"main": "lib/commonjs/index",
|
|
6
|
+
"module": "lib/module/index",
|
|
7
|
+
"types": "lib/typescript/index.d.ts",
|
|
8
|
+
"react-native": "src/index",
|
|
9
|
+
"source": "src/index",
|
|
10
|
+
"harmony": {
|
|
11
|
+
"alias":"react-native-pager-view",
|
|
12
|
+
"autolinking": {
|
|
13
|
+
"etsPackageClassName": "ViewPagerPackage",
|
|
14
|
+
"cppPackageClassName": "ViewPagerPackage",
|
|
15
|
+
"cmakeLibraryTargetName": "rnoh_pager_view",
|
|
16
|
+
"ohPackageName": "@react-native-ohos/react-native-pager-view"
|
|
17
|
+
}
|
|
18
|
+
},
|
|
19
|
+
"files": [
|
|
20
|
+
"src",
|
|
21
|
+
"lib",
|
|
22
|
+
"harmony",
|
|
23
|
+
"!lib/typescript/example",
|
|
24
|
+
"!**/__tests__",
|
|
25
|
+
"!**/__fixtures__",
|
|
26
|
+
"!**/__mocks__",
|
|
27
|
+
"!harmony/oh_modules",
|
|
28
|
+
"!harmony/**/build",
|
|
29
|
+
"!harmony/**/oh_modules"
|
|
30
|
+
],
|
|
31
|
+
"scripts": {
|
|
32
|
+
"test": "jest",
|
|
33
|
+
"typescript": "tsc --noEmit",
|
|
34
|
+
"lint": "eslint \"**/*.{js,ts,tsx}\"",
|
|
35
|
+
"prepare": "bob build",
|
|
36
|
+
"release": "release-it",
|
|
37
|
+
"releaseNext": "release-it --npm.tag=newarch --preRelease=rc"
|
|
38
|
+
},
|
|
39
|
+
"keywords": [
|
|
40
|
+
"react-native",
|
|
41
|
+
"harmony"
|
|
42
|
+
],
|
|
43
|
+
"repository": {
|
|
44
|
+
"type": "git",
|
|
45
|
+
"url": "https://gitcode.com/openharmony-sig/rntpc_react-native-pager-view.git"
|
|
46
|
+
},
|
|
47
|
+
"author": "troZee <hello@callstack.com> (https://github.com/callstack)",
|
|
48
|
+
"license": "MIT",
|
|
49
|
+
"bugs": {
|
|
50
|
+
"url": "https://gitcode.com/openharmony-sig/rntpc_react-native-pager-view/issues"
|
|
51
|
+
},
|
|
52
|
+
"homepage": "https://gitcode.com/openharmony-sig/rntpc_react-native-pager-view#readme",
|
|
53
|
+
"publishConfig": {
|
|
54
|
+
"registry": "https://registry.npmjs.org/",
|
|
55
|
+
"access": "public"
|
|
56
|
+
},
|
|
57
|
+
"dependencies": {
|
|
58
|
+
"react-native-pager-view": "6.2.2 - 6.2.3"
|
|
59
|
+
},
|
|
60
|
+
"devDependencies": {
|
|
61
|
+
"@babel/eslint-parser": "^7.18.2",
|
|
62
|
+
"@react-native-community/eslint-config": "^3.0.2",
|
|
63
|
+
"@release-it/conventional-changelog": "^2.0.0",
|
|
64
|
+
"@types/jest": "^28.1.2",
|
|
65
|
+
"@types/react": "18.0.29",
|
|
66
|
+
"@types/react-native": "0.70.0",
|
|
67
|
+
"eslint": "^8.4.1",
|
|
68
|
+
"eslint-config-prettier": "^8.5.0",
|
|
69
|
+
"eslint-plugin-prettier": "^4.0.0",
|
|
70
|
+
"jest": "^28.1.1",
|
|
71
|
+
"pod-install": "^0.1.0",
|
|
72
|
+
"prettier": "^2.0.5",
|
|
73
|
+
"react": "18.1.0",
|
|
74
|
+
"react-native": "0.70.0",
|
|
75
|
+
"react-native-builder-bob": "^0.18.3",
|
|
76
|
+
"release-it": "^14.2.2",
|
|
77
|
+
"typescript": "^4.5.2",
|
|
78
|
+
"@react-native/eslint-config": "^0.72.2",
|
|
79
|
+
"@react-native/metro-config": "^0.72.11",
|
|
80
|
+
"@tsconfig/react-native": "^3.0.0",
|
|
81
|
+
"metro-react-native-babel-preset": "0.76.8"
|
|
82
|
+
},
|
|
83
|
+
"resolutions": {
|
|
84
|
+
"@types/react": "18.0.29"
|
|
85
|
+
},
|
|
86
|
+
"peerDependencies": {
|
|
87
|
+
"react": "*",
|
|
88
|
+
"react-native": "*"
|
|
89
|
+
},
|
|
90
|
+
"jest": {
|
|
91
|
+
"preset": "react-native",
|
|
92
|
+
"modulePathIgnorePatterns": [
|
|
93
|
+
"<rootDir>/example/node_modules",
|
|
94
|
+
"<rootDir>/lib/"
|
|
95
|
+
]
|
|
96
|
+
},
|
|
97
|
+
"eslintConfig": {
|
|
98
|
+
"root": true,
|
|
99
|
+
"parser": "@babel/eslint-parser",
|
|
100
|
+
"extends": [
|
|
101
|
+
"@react-native-community",
|
|
102
|
+
"prettier"
|
|
103
|
+
],
|
|
104
|
+
"rules": {
|
|
105
|
+
"prettier/prettier": [
|
|
106
|
+
"error",
|
|
107
|
+
{
|
|
108
|
+
"quoteProps": "consistent",
|
|
109
|
+
"singleQuote": true,
|
|
110
|
+
"tabWidth": 2,
|
|
111
|
+
"trailingComma": "es5",
|
|
112
|
+
"useTabs": false
|
|
113
|
+
}
|
|
114
|
+
]
|
|
115
|
+
}
|
|
116
|
+
},
|
|
117
|
+
"eslintIgnore": [
|
|
118
|
+
"node_modules/",
|
|
119
|
+
"lib/"
|
|
120
|
+
],
|
|
121
|
+
"prettier": {
|
|
122
|
+
"quoteProps": "consistent",
|
|
123
|
+
"singleQuote": true,
|
|
124
|
+
"tabWidth": 2,
|
|
125
|
+
"trailingComma": "es5",
|
|
126
|
+
"useTabs": false
|
|
127
|
+
},
|
|
128
|
+
"react-native-builder-bob": {
|
|
129
|
+
"source": "src",
|
|
130
|
+
"output": "lib",
|
|
131
|
+
"targets": [
|
|
132
|
+
"commonjs",
|
|
133
|
+
"module",
|
|
134
|
+
[
|
|
135
|
+
"typescript",
|
|
136
|
+
{
|
|
137
|
+
"project": "tsconfig.build.json"
|
|
138
|
+
}
|
|
139
|
+
]
|
|
140
|
+
]
|
|
141
|
+
}
|
|
142
|
+
}
|
|
@@ -0,0 +1,163 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import { Platform, Keyboard } from 'react-native';
|
|
3
|
+
import { I18nManager } from 'react-native';
|
|
4
|
+
import type {
|
|
5
|
+
OnPageScrollEventData,
|
|
6
|
+
OnPageScrollStateChangedEventData,
|
|
7
|
+
OnPageSelectedEventData,
|
|
8
|
+
} from './PagerViewNativeComponent';
|
|
9
|
+
import type * as ReactNative from 'react-native';
|
|
10
|
+
|
|
11
|
+
import type { NativeProps as PagerViewProps } from './PagerViewNativeComponent';
|
|
12
|
+
import { childrenWithOverriddenStyle } from './utils';
|
|
13
|
+
import PagerViewView, {
|
|
14
|
+
Commands as PagerViewCommands,
|
|
15
|
+
} from './PagerViewNativeComponent';
|
|
16
|
+
|
|
17
|
+
/**
|
|
18
|
+
* Container that allows to flip left and right between child views. Each
|
|
19
|
+
* child view of the `PagerView` will be treated as a separate page
|
|
20
|
+
* and will be stretched to fill the `PagerView`.
|
|
21
|
+
*
|
|
22
|
+
* It is important all children are `<View>`s and not composite components.
|
|
23
|
+
* You can set style properties like `padding` or `backgroundColor` for each
|
|
24
|
+
* child. It is also important that each child have a `key` prop.
|
|
25
|
+
*
|
|
26
|
+
* Example:
|
|
27
|
+
*
|
|
28
|
+
* ```
|
|
29
|
+
* render: function() {
|
|
30
|
+
* return (
|
|
31
|
+
* <PagerView
|
|
32
|
+
* style={styles.PagerView}
|
|
33
|
+
* initialPage={0}>
|
|
34
|
+
* <View style={styles.pageStyle} key="1">
|
|
35
|
+
* <Text>First page</Text>
|
|
36
|
+
* </View>
|
|
37
|
+
* <View style={styles.pageStyle} key="2">
|
|
38
|
+
* <Text>Second page</Text>
|
|
39
|
+
* </View>
|
|
40
|
+
* </PagerView>
|
|
41
|
+
* );
|
|
42
|
+
* }
|
|
43
|
+
*
|
|
44
|
+
* ...
|
|
45
|
+
*
|
|
46
|
+
* var styles = {
|
|
47
|
+
* ...
|
|
48
|
+
* PagerView: {
|
|
49
|
+
* flex: 1
|
|
50
|
+
* },
|
|
51
|
+
* pageStyle: {
|
|
52
|
+
* alignItems: 'center',
|
|
53
|
+
* padding: 20,
|
|
54
|
+
* }
|
|
55
|
+
* }
|
|
56
|
+
* ```
|
|
57
|
+
*/
|
|
58
|
+
|
|
59
|
+
export class PagerView extends React.Component<PagerViewProps> {
|
|
60
|
+
private isScrolling = false;
|
|
61
|
+
pagerView: React.ElementRef<typeof PagerViewView> | null = null;
|
|
62
|
+
|
|
63
|
+
private _onPageScroll = (
|
|
64
|
+
e: ReactNative.NativeSyntheticEvent<OnPageScrollEventData>
|
|
65
|
+
) => {
|
|
66
|
+
if (this.props.onPageScroll) {
|
|
67
|
+
this.props.onPageScroll(e);
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
// Not implemented on iOS yet
|
|
71
|
+
// @ts-ignore
|
|
72
|
+
if (Platform.OS === 'android' || Platform.OS === 'harmony') {
|
|
73
|
+
if (this.props.keyboardDismissMode === 'on-drag') {
|
|
74
|
+
Keyboard.dismiss();
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
};
|
|
78
|
+
|
|
79
|
+
private _onPageScrollStateChanged = (
|
|
80
|
+
e: ReactNative.NativeSyntheticEvent<OnPageScrollStateChangedEventData>
|
|
81
|
+
) => {
|
|
82
|
+
if (this.props.onPageScrollStateChanged) {
|
|
83
|
+
this.props.onPageScrollStateChanged(e);
|
|
84
|
+
}
|
|
85
|
+
this.isScrolling = e.nativeEvent.pageScrollState === 'dragging';
|
|
86
|
+
};
|
|
87
|
+
|
|
88
|
+
private _onPageSelected = (
|
|
89
|
+
e: ReactNative.NativeSyntheticEvent<OnPageSelectedEventData>
|
|
90
|
+
) => {
|
|
91
|
+
if (this.props.onPageSelected) {
|
|
92
|
+
this.props.onPageSelected(e);
|
|
93
|
+
}
|
|
94
|
+
};
|
|
95
|
+
|
|
96
|
+
/**
|
|
97
|
+
* A helper function to scroll to a specific page in the PagerView.
|
|
98
|
+
* The transition between pages will be animated.
|
|
99
|
+
*/
|
|
100
|
+
public setPage = (selectedPage: number) => {
|
|
101
|
+
if (this.pagerView) {
|
|
102
|
+
PagerViewCommands.setPage(this.pagerView, selectedPage);
|
|
103
|
+
}
|
|
104
|
+
};
|
|
105
|
+
|
|
106
|
+
/**
|
|
107
|
+
* A helper function to scroll to a specific page in the PagerView.
|
|
108
|
+
* The transition between pages will *not* be animated.
|
|
109
|
+
*/
|
|
110
|
+
public setPageWithoutAnimation = (selectedPage: number) => {
|
|
111
|
+
if (this.pagerView) {
|
|
112
|
+
PagerViewCommands.setPageWithoutAnimation(this.pagerView, selectedPage);
|
|
113
|
+
}
|
|
114
|
+
};
|
|
115
|
+
|
|
116
|
+
/**
|
|
117
|
+
* A helper function to enable/disable scroll imperatively
|
|
118
|
+
* The recommended way is using the scrollEnabled prop, however, there might be a case where a
|
|
119
|
+
* imperative solution is more useful (e.g. for not blocking an animation)
|
|
120
|
+
*/
|
|
121
|
+
public setScrollEnabled = (scrollEnabled: boolean) => {
|
|
122
|
+
if (this.pagerView) {
|
|
123
|
+
PagerViewCommands.setScrollEnabledImperatively(
|
|
124
|
+
this.pagerView,
|
|
125
|
+
scrollEnabled
|
|
126
|
+
);
|
|
127
|
+
}
|
|
128
|
+
};
|
|
129
|
+
|
|
130
|
+
private _onMoveShouldSetResponderCapture = () => {
|
|
131
|
+
return this.isScrolling;
|
|
132
|
+
};
|
|
133
|
+
|
|
134
|
+
private get deducedLayoutDirection() {
|
|
135
|
+
if (
|
|
136
|
+
!this.props.layoutDirection ||
|
|
137
|
+
//@ts-ignore fix it
|
|
138
|
+
this.props.layoutDirection === 'locale'
|
|
139
|
+
) {
|
|
140
|
+
return I18nManager.isRTL ? 'rtl' : 'ltr';
|
|
141
|
+
} else {
|
|
142
|
+
return this.props.layoutDirection;
|
|
143
|
+
}
|
|
144
|
+
}
|
|
145
|
+
|
|
146
|
+
render() {
|
|
147
|
+
return (
|
|
148
|
+
<PagerViewView
|
|
149
|
+
{...this.props}
|
|
150
|
+
ref={(ref) => {
|
|
151
|
+
this.pagerView = ref;
|
|
152
|
+
}}
|
|
153
|
+
style={this.props.style}
|
|
154
|
+
layoutDirection={this.deducedLayoutDirection}
|
|
155
|
+
onPageScroll={this._onPageScroll}
|
|
156
|
+
onPageScrollStateChanged={this._onPageScrollStateChanged}
|
|
157
|
+
onPageSelected={this._onPageSelected}
|
|
158
|
+
onMoveShouldSetResponderCapture={this._onMoveShouldSetResponderCapture}
|
|
159
|
+
children={childrenWithOverriddenStyle(this.props.children)}
|
|
160
|
+
/>
|
|
161
|
+
);
|
|
162
|
+
}
|
|
163
|
+
}
|
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
import type * as React from 'react';
|
|
2
|
+
import codegenNativeCommands from 'react-native/Libraries/Utilities/codegenNativeCommands';
|
|
3
|
+
import codegenNativeComponent from 'react-native/Libraries/Utilities/codegenNativeComponent';
|
|
4
|
+
import type { HostComponent, ViewProps } from 'react-native';
|
|
5
|
+
import type {
|
|
6
|
+
DirectEventHandler,
|
|
7
|
+
Double,
|
|
8
|
+
Int32,
|
|
9
|
+
WithDefault,
|
|
10
|
+
} from 'react-native/Libraries/Types/CodegenTypes';
|
|
11
|
+
|
|
12
|
+
export type OnPageScrollEventData = Readonly<{
|
|
13
|
+
position: Double;
|
|
14
|
+
offset: Double;
|
|
15
|
+
}>;
|
|
16
|
+
|
|
17
|
+
export type OnPageSelectedEventData = Readonly<{
|
|
18
|
+
position: Double;
|
|
19
|
+
}>;
|
|
20
|
+
|
|
21
|
+
export type OnPageScrollStateChangedEventData = Readonly<{
|
|
22
|
+
pageScrollState: 'idle' | 'dragging' | 'settling';
|
|
23
|
+
}>;
|
|
24
|
+
|
|
25
|
+
export interface NativeProps extends ViewProps {
|
|
26
|
+
scrollEnabled?: WithDefault<boolean, true>;
|
|
27
|
+
layoutDirection?: WithDefault<'ltr' | 'rtl', 'ltr'>;
|
|
28
|
+
initialPage?: Int32;
|
|
29
|
+
orientation?: WithDefault<'horizontal' | 'vertical', 'horizontal'>;
|
|
30
|
+
offscreenPageLimit?: Int32;
|
|
31
|
+
pageMargin?: Int32;
|
|
32
|
+
overScrollMode?: WithDefault<'auto' | 'always' | 'never', 'auto'>;
|
|
33
|
+
overdrag?: WithDefault<boolean, false>;
|
|
34
|
+
keyboardDismissMode?: WithDefault<'none' | 'on-drag', 'none'>;
|
|
35
|
+
onPageScroll?: DirectEventHandler<OnPageScrollEventData>;
|
|
36
|
+
onPageSelected?: DirectEventHandler<OnPageSelectedEventData>;
|
|
37
|
+
onPageScrollStateChanged?: DirectEventHandler<OnPageScrollStateChangedEventData>;
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
type PagerViewViewType = HostComponent<NativeProps>;
|
|
41
|
+
|
|
42
|
+
export interface NativeCommands {
|
|
43
|
+
setPage: (
|
|
44
|
+
viewRef: React.ElementRef<PagerViewViewType>,
|
|
45
|
+
selectedPage: Int32
|
|
46
|
+
) => void;
|
|
47
|
+
setPageWithoutAnimation: (
|
|
48
|
+
viewRef: React.ElementRef<PagerViewViewType>,
|
|
49
|
+
selectedPage: Int32
|
|
50
|
+
) => void;
|
|
51
|
+
setScrollEnabledImperatively: (
|
|
52
|
+
viewRef: React.ElementRef<PagerViewViewType>,
|
|
53
|
+
scrollEnabled: boolean
|
|
54
|
+
) => void;
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
export const Commands: NativeCommands = codegenNativeCommands<NativeCommands>({
|
|
58
|
+
supportedCommands: [
|
|
59
|
+
'setPage',
|
|
60
|
+
'setPageWithoutAnimation',
|
|
61
|
+
'setScrollEnabledImperatively',
|
|
62
|
+
],
|
|
63
|
+
});
|
|
64
|
+
|
|
65
|
+
export default codegenNativeComponent<NativeProps>(
|
|
66
|
+
'RNCViewPager'
|
|
67
|
+
) as HostComponent<NativeProps>;
|
package/src/index.tsx
ADDED
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import type * as ReactNative from 'react-native';
|
|
2
|
+
import { PagerView } from './PagerView';
|
|
3
|
+
export default PagerView;
|
|
4
|
+
|
|
5
|
+
import type {
|
|
6
|
+
OnPageScrollEventData as PagerViewOnPageScrollEventData,
|
|
7
|
+
OnPageSelectedEventData as PagerViewOnPageSelectedEventData,
|
|
8
|
+
OnPageScrollStateChangedEventData as PageScrollStateChangedNativeEventData,
|
|
9
|
+
NativeProps,
|
|
10
|
+
} from './PagerViewNativeComponent';
|
|
11
|
+
|
|
12
|
+
export type {
|
|
13
|
+
PagerViewOnPageScrollEventData,
|
|
14
|
+
PagerViewOnPageSelectedEventData,
|
|
15
|
+
PageScrollStateChangedNativeEventData,
|
|
16
|
+
NativeProps as PagerViewProps,
|
|
17
|
+
};
|
|
18
|
+
|
|
19
|
+
export type PagerViewOnPageScrollEvent =
|
|
20
|
+
ReactNative.NativeSyntheticEvent<PagerViewOnPageScrollEventData>;
|
|
21
|
+
|
|
22
|
+
export type PagerViewOnPageSelectedEvent =
|
|
23
|
+
ReactNative.NativeSyntheticEvent<PagerViewOnPageSelectedEventData>;
|
|
24
|
+
|
|
25
|
+
export type PageScrollStateChangedNativeEvent =
|
|
26
|
+
ReactNative.NativeSyntheticEvent<PageScrollStateChangedNativeEventData>;
|
package/src/utils.tsx
ADDED
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import React, { Children, ReactNode } from 'react';
|
|
2
|
+
import { StyleSheet, View } from 'react-native';
|
|
3
|
+
|
|
4
|
+
export const childrenWithOverriddenStyle = (children?: ReactNode) => {
|
|
5
|
+
return Children.map(children, (child) => {
|
|
6
|
+
const element = child as React.ReactElement;
|
|
7
|
+
return (
|
|
8
|
+
// Add a wrapper to ensure layout is calculated correctly
|
|
9
|
+
<View style={StyleSheet.absoluteFill} collapsable={false}>
|
|
10
|
+
{/* @ts-ignore */}
|
|
11
|
+
{React.cloneElement(element, {
|
|
12
|
+
...element.props,
|
|
13
|
+
// Override styles so that each page will fill the parent.
|
|
14
|
+
style: [element.props.style, StyleSheet.absoluteFill],
|
|
15
|
+
})}
|
|
16
|
+
</View>
|
|
17
|
+
);
|
|
18
|
+
});
|
|
19
|
+
};
|