@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.
Files changed (67) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +15 -0
  3. package/harmony/pager_view/LICENSE +21 -0
  4. package/harmony/pager_view/NOTICE +33 -0
  5. package/harmony/pager_view/README.OpenSource +11 -0
  6. package/harmony/pager_view/build-profile.json5 +9 -0
  7. package/harmony/pager_view/consumer-rules.txt +0 -0
  8. package/harmony/pager_view/hvigorfile.ts +6 -0
  9. package/harmony/pager_view/index.ets +26 -0
  10. package/harmony/pager_view/obfuscation-rules.txt +18 -0
  11. package/harmony/pager_view/oh-package.json5 +14 -0
  12. package/harmony/pager_view/src/main/cpp/CMakeLists.txt +9 -0
  13. package/harmony/pager_view/src/main/cpp/RNCViewPagerTurbomodule.cpp +42 -0
  14. package/harmony/pager_view/src/main/cpp/RNCViewPagerTurbomodule.h +37 -0
  15. package/harmony/pager_view/src/main/cpp/SwiperNode.cpp +403 -0
  16. package/harmony/pager_view/src/main/cpp/SwiperNode.h +120 -0
  17. package/harmony/pager_view/src/main/cpp/ViewPagerComponentInstance.cpp +247 -0
  18. package/harmony/pager_view/src/main/cpp/ViewPagerComponentInstance.h +106 -0
  19. package/harmony/pager_view/src/main/cpp/ViewPagerPackage.h +64 -0
  20. package/harmony/pager_view/src/main/cpp/generated/RNOH/generated/BaseReactNativePagerViewPackage.h +70 -0
  21. package/harmony/pager_view/src/main/cpp/generated/RNOH/generated/components/BaseRNCViewPagerComponentInstance.h +16 -0
  22. package/harmony/pager_view/src/main/cpp/generated/RNOH/generated/components/RNCViewPagerJSIBinder.h +41 -0
  23. package/harmony/pager_view/src/main/cpp/generated/react/renderer/components/react_native_pager_view/ComponentDescriptors.h +22 -0
  24. package/harmony/pager_view/src/main/cpp/generated/react/renderer/components/react_native_pager_view/EventEmitters.cpp +43 -0
  25. package/harmony/pager_view/src/main/cpp/generated/react/renderer/components/react_native_pager_view/EventEmitters.h +47 -0
  26. package/harmony/pager_view/src/main/cpp/generated/react/renderer/components/react_native_pager_view/Props.cpp +38 -0
  27. package/harmony/pager_view/src/main/cpp/generated/react/renderer/components/react_native_pager_view/Props.h +139 -0
  28. package/harmony/pager_view/src/main/cpp/generated/react/renderer/components/react_native_pager_view/ShadowNodes.cpp +19 -0
  29. package/harmony/pager_view/src/main/cpp/generated/react/renderer/components/react_native_pager_view/ShadowNodes.h +34 -0
  30. package/harmony/pager_view/src/main/cpp/generated/react/renderer/components/react_native_pager_view/States.cpp +16 -0
  31. package/harmony/pager_view/src/main/cpp/generated/react/renderer/components/react_native_pager_view/States.h +38 -0
  32. package/harmony/pager_view/src/main/ets/Logger.ets +64 -0
  33. package/harmony/pager_view/src/main/ets/RNCViewPager.ets +281 -0
  34. package/harmony/pager_view/src/main/ets/RNCViewPagerManager.ets +58 -0
  35. package/harmony/pager_view/src/main/ets/ViewPagerModule.ts +34 -0
  36. package/harmony/pager_view/src/main/ets/ViewPagerPackage.ets +57 -0
  37. package/harmony/pager_view/src/main/module.json5 +7 -0
  38. package/harmony/pager_view/src/main/resources/base/element/string.json +8 -0
  39. package/harmony/pager_view/src/main/resources/en_US/element/string.json +8 -0
  40. package/harmony/pager_view/src/main/resources/zh_CN/element/string.json +8 -0
  41. package/harmony/pager_view/ts.ets +26 -0
  42. package/harmony/pager_view.har +0 -0
  43. package/lib/commonjs/PagerView.js +145 -0
  44. package/lib/commonjs/PagerView.js.map +1 -0
  45. package/lib/commonjs/PagerViewNativeComponent.js +14 -0
  46. package/lib/commonjs/PagerViewNativeComponent.js.map +1 -0
  47. package/lib/commonjs/index.js +9 -0
  48. package/lib/commonjs/index.js.map +1 -0
  49. package/lib/commonjs/utils.js +28 -0
  50. package/lib/commonjs/utils.js.map +1 -0
  51. package/lib/module/PagerView.js +138 -0
  52. package/lib/module/PagerView.js.map +1 -0
  53. package/lib/module/PagerViewNativeComponent.js +7 -0
  54. package/lib/module/PagerViewNativeComponent.js.map +1 -0
  55. package/lib/module/index.js +3 -0
  56. package/lib/module/index.js.map +1 -0
  57. package/lib/module/utils.js +20 -0
  58. package/lib/module/utils.js.map +1 -0
  59. package/lib/typescript/PagerView.d.ts +70 -0
  60. package/lib/typescript/PagerViewNativeComponent.d.ts +36 -0
  61. package/lib/typescript/index.d.ts +8 -0
  62. package/lib/typescript/utils.d.ts +2 -0
  63. package/package.json +142 -0
  64. package/src/PagerView.tsx +163 -0
  65. package/src/PagerViewNativeComponent.ts +67 -0
  66. package/src/index.tsx +26 -0
  67. package/src/utils.tsx +19 -0
@@ -0,0 +1,38 @@
1
+
2
+ /**
3
+ * This code was generated by [react-native-codegen](https://www.npmjs.com/package/react-native-codegen).
4
+ *
5
+ * Do not edit this file as changes may cause incorrect behavior and will be lost
6
+ * once the code is regenerated.
7
+ *
8
+ * @generated by codegen project: GeneratePropsCpp.js
9
+ */
10
+
11
+ #include <react/renderer/components/react_native_pager_view/Props.h>
12
+ #include <react/renderer/core/PropsParserContext.h>
13
+ #include <react/renderer/core/propsConversions.h>
14
+
15
+ namespace facebook {
16
+ namespace react {
17
+
18
+ RNCViewPagerProps::RNCViewPagerProps(
19
+ const PropsParserContext &context,
20
+ const RNCViewPagerProps &sourceProps,
21
+ const RawProps &rawProps): ViewProps(context, sourceProps, rawProps),
22
+ scrollEnabled(convertRawProp(context, rawProps, "scrollEnabled", sourceProps.scrollEnabled, {true})),
23
+ layoutDirection(convertRawProp(context, rawProps,
24
+ "layoutDirection", sourceProps.layoutDirection, {RNCViewPagerLayoutDirection::Ltr})),
25
+ initialPage(convertRawProp(context, rawProps, "initialPage", sourceProps.initialPage, {0})),
26
+ orientation(convertRawProp(context,
27
+ rawProps, "orientation", sourceProps.orientation, {RNCViewPagerOrientation::Horizontal})),
28
+ offscreenPageLimit(convertRawProp(context, rawProps, "offscreenPageLimit", sourceProps.offscreenPageLimit, {0})),
29
+ pageMargin(convertRawProp(context, rawProps, "pageMargin", sourceProps.pageMargin, {0})),
30
+ overScrollMode(convertRawProp(context,
31
+ rawProps, "overScrollMode", sourceProps.overScrollMode, {RNCViewPagerOverScrollMode::Auto})),
32
+ overdrag(convertRawProp(context, rawProps, "overdrag", sourceProps.overdrag, {false})),
33
+ keyboardDismissMode(convertRawProp(context,
34
+ rawProps, "keyboardDismissMode", sourceProps.keyboardDismissMode, {RNCViewPagerKeyboardDismissMode::None}))
35
+ {}
36
+
37
+ } // namespace react
38
+ } // namespace facebook
@@ -0,0 +1,139 @@
1
+
2
+ /**
3
+ * This code was generated by [react-native-codegen](https://www.npmjs.com/package/react-native-codegen).
4
+ *
5
+ * Do not edit this file as changes may cause incorrect behavior and will be lost
6
+ * once the code is regenerated.
7
+ *
8
+ * @generated by codegen project: GeneratePropsH.js
9
+ */
10
+ #pragma once
11
+
12
+ #include <react/renderer/components/view/ViewProps.h>
13
+ #include <react/renderer/core/PropsParserContext.h>
14
+
15
+ namespace facebook {
16
+ namespace react {
17
+
18
+ enum class RNCViewPagerLayoutDirection { Ltr, Rtl };
19
+
20
+ static inline void fromRawValue(const PropsParserContext& context,
21
+ const RawValue &value, RNCViewPagerLayoutDirection &result)
22
+ {
23
+ auto string = (std::string)value;
24
+ if (string == "ltr") {
25
+ result = RNCViewPagerLayoutDirection::Ltr;
26
+ return;
27
+ }
28
+ if (string == "rtl") {
29
+ result = RNCViewPagerLayoutDirection::Rtl;
30
+ return;
31
+ }
32
+ abort();
33
+ }
34
+
35
+ static inline std::string toString(const RNCViewPagerLayoutDirection &value)
36
+ {
37
+ switch (value) {
38
+ case RNCViewPagerLayoutDirection::Ltr: return "ltr";
39
+ case RNCViewPagerLayoutDirection::Rtl: return "rtl";
40
+ }
41
+ }
42
+ enum class RNCViewPagerOrientation { Horizontal, Vertical };
43
+
44
+ static inline void fromRawValue(const PropsParserContext& context,
45
+ const RawValue &value, RNCViewPagerOrientation &result)
46
+ {
47
+ auto string = (std::string)value;
48
+ if (string == "horizontal") {
49
+ result = RNCViewPagerOrientation::Horizontal;
50
+ return;
51
+ }
52
+ if (string == "vertical") {
53
+ result = RNCViewPagerOrientation::Vertical;
54
+ return;
55
+ }
56
+ abort();
57
+ }
58
+
59
+ static inline std::string toString(const RNCViewPagerOrientation &value)
60
+ {
61
+ switch (value) {
62
+ case RNCViewPagerOrientation::Horizontal: return "horizontal";
63
+ case RNCViewPagerOrientation::Vertical: return "vertical";
64
+ }
65
+ }
66
+ enum class RNCViewPagerOverScrollMode { Auto, Always, Never };
67
+
68
+ static inline void fromRawValue(const PropsParserContext& context,
69
+ const RawValue &value, RNCViewPagerOverScrollMode &result)
70
+ {
71
+ auto string = (std::string)value;
72
+ if (string == "auto") {
73
+ result = RNCViewPagerOverScrollMode::Auto;
74
+ return;
75
+ }
76
+ if (string == "always") {
77
+ result = RNCViewPagerOverScrollMode::Always;
78
+ return;
79
+ }
80
+ if (string == "never") {
81
+ result = RNCViewPagerOverScrollMode::Never;
82
+ return;
83
+ }
84
+ abort();
85
+ }
86
+
87
+ static inline std::string toString(const RNCViewPagerOverScrollMode &value)
88
+ {
89
+ switch (value) {
90
+ case RNCViewPagerOverScrollMode::Auto: return "auto";
91
+ case RNCViewPagerOverScrollMode::Always: return "always";
92
+ case RNCViewPagerOverScrollMode::Never: return "never";
93
+ }
94
+ }
95
+ enum class RNCViewPagerKeyboardDismissMode { None, OnDrag };
96
+
97
+ static inline void fromRawValue(const PropsParserContext& context,
98
+ const RawValue &value, RNCViewPagerKeyboardDismissMode &result)
99
+ {
100
+ auto string = (std::string)value;
101
+ if (string == "none") {
102
+ result = RNCViewPagerKeyboardDismissMode::None;
103
+ return;
104
+ }
105
+ if (string == "on-drag") {
106
+ result = RNCViewPagerKeyboardDismissMode::OnDrag;
107
+ return;
108
+ }
109
+ abort();
110
+ }
111
+
112
+ static inline std::string toString(const RNCViewPagerKeyboardDismissMode &value)
113
+ {
114
+ switch (value) {
115
+ case RNCViewPagerKeyboardDismissMode::None: return "none";
116
+ case RNCViewPagerKeyboardDismissMode::OnDrag: return "on-drag";
117
+ }
118
+ }
119
+
120
+ class RNCViewPagerProps final : public ViewProps {
121
+ public:
122
+ RNCViewPagerProps() = default;
123
+ RNCViewPagerProps(const PropsParserContext& context,
124
+ const RNCViewPagerProps &sourceProps, const RawProps &rawProps);
125
+
126
+ #pragma mark - Props
127
+ bool scrollEnabled{true};
128
+ RNCViewPagerLayoutDirection layoutDirection{RNCViewPagerLayoutDirection::Ltr};
129
+ int initialPage{0};
130
+ RNCViewPagerOrientation orientation{RNCViewPagerOrientation::Horizontal};
131
+ int offscreenPageLimit{0};
132
+ int pageMargin{0};
133
+ RNCViewPagerOverScrollMode overScrollMode{RNCViewPagerOverScrollMode::Auto};
134
+ bool overdrag{false};
135
+ RNCViewPagerKeyboardDismissMode keyboardDismissMode{RNCViewPagerKeyboardDismissMode::None};
136
+ };
137
+
138
+ } // namespace react
139
+ } // namespace facebook
@@ -0,0 +1,19 @@
1
+
2
+ /**
3
+ * This code was generated by [react-native-codegen](https://www.npmjs.com/package/react-native-codegen).
4
+ *
5
+ * Do not edit this file as changes may cause incorrect behavior and will be lost
6
+ * once the code is regenerated.
7
+ *
8
+ * @generated by codegen project: GenerateShadowNodeCpp.js
9
+ */
10
+
11
+ #include <react/renderer/components/react_native_pager_view/ShadowNodes.h>
12
+
13
+ namespace facebook {
14
+ namespace react {
15
+
16
+ extern const char RNCViewPagerComponentName[] = "RNCViewPager";
17
+
18
+ } // namespace react
19
+ } // namespace facebook
@@ -0,0 +1,34 @@
1
+
2
+ /**
3
+ * This code was generated by [react-native-codegen](https://www.npmjs.com/package/react-native-codegen).
4
+ *
5
+ * Do not edit this file as changes may cause incorrect behavior and will be lost
6
+ * once the code is regenerated.
7
+ *
8
+ * @generated by codegen project: GenerateShadowNodeH.js
9
+ */
10
+
11
+ #pragma once
12
+
13
+ #include <react/renderer/components/react_native_pager_view/EventEmitters.h>
14
+ #include <react/renderer/components/react_native_pager_view/Props.h>
15
+ #include <react/renderer/components/react_native_pager_view/States.h>
16
+ #include <react/renderer/components/view/ConcreteViewShadowNode.h>
17
+ #include <jsi/jsi.h>
18
+
19
+ namespace facebook {
20
+ namespace react {
21
+
22
+ JSI_EXPORT extern const char RNCViewPagerComponentName[];
23
+
24
+ /*
25
+ * `ShadowNode` for <RNCViewPager> component.
26
+ */
27
+ using RNCViewPagerShadowNode = ConcreteViewShadowNode<
28
+ RNCViewPagerComponentName,
29
+ RNCViewPagerProps,
30
+ RNCViewPagerEventEmitter,
31
+ RNCViewPagerState>;
32
+
33
+ } // namespace react
34
+ } // namespace facebook
@@ -0,0 +1,16 @@
1
+
2
+ /**
3
+ * This code was generated by [react-native-codegen](https://www.npmjs.com/package/react-native-codegen).
4
+ *
5
+ * Do not edit this file as changes may cause incorrect behavior and will be lost
6
+ * once the code is regenerated.
7
+ *
8
+ * @generated by codegen project: GenerateStateCpp.js
9
+ */
10
+ #include <react/renderer/components/react_native_pager_view/States.h>
11
+
12
+ namespace facebook {
13
+ namespace react {
14
+
15
+ } // namespace react
16
+ } // namespace facebook
@@ -0,0 +1,38 @@
1
+ /**
2
+ * This code was generated by [react-native-codegen](https://www.npmjs.com/package/react-native-codegen).
3
+ *
4
+ * Do not edit this file as changes may cause incorrect behavior and will be lost
5
+ * once the code is regenerated.
6
+ *
7
+ * @generated by codegen project: GenerateStateH.js
8
+ */
9
+ #pragma once
10
+
11
+ #ifdef ANDROID
12
+ #include <folly/dynamic.h>
13
+ #include <react/renderer/mapbuffer/MapBuffer.h>
14
+ #include <react/renderer/mapbuffer/MapBufferBuilder.h>
15
+ #endif
16
+
17
+ namespace facebook {
18
+ namespace react {
19
+
20
+ class RNCViewPagerState {
21
+ public:
22
+ RNCViewPagerState() = default;
23
+
24
+ #ifdef ANDROID
25
+ RNCViewPagerState(RNCViewPagerState const &previousState, folly::dynamic data){};
26
+ folly::dynamic getDynamic() const
27
+ {
28
+ return {};
29
+ };
30
+ MapBuffer getMapBuffer() const
31
+ {
32
+ return MapBufferBuilder::EMPTY();
33
+ };
34
+ #endif
35
+ };
36
+
37
+ } // namespace react
38
+ } // namespace facebook
@@ -0,0 +1,64 @@
1
+ /**
2
+ * MIT License
3
+ *
4
+ * Copyright (C) 2023 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
+ */
24
+
25
+ import hilog from '@ohos.hilog';
26
+
27
+ class Logger {
28
+ private domain : number;
29
+ private prefix : string;
30
+ private format : string = '%{public}s, %{public}s';
31
+ private isDebug : boolean;
32
+
33
+ /**
34
+ * constructor.
35
+ *
36
+ * @param Prefix Identifies the log tag.
37
+ * @param domain Domain Indicates the service domain, which is a hexadecimal integer ranging from 0x0 to 0xFFFFF.
38
+ */
39
+ constructor(prefix: string = 'MyApp', domain: number = 0xFF00, isDebug = false) {
40
+ this.prefix = prefix;
41
+ this.domain = domain;
42
+ this.isDebug = isDebug;
43
+ }
44
+
45
+ debug(...args: string[]): void {
46
+ if (this.isDebug) {
47
+ hilog.debug(this.domain, this.prefix, this.format, args);
48
+ }
49
+ }
50
+
51
+ info(...args: string[]): void {
52
+ hilog.info(this.domain, this.prefix, this.format, args);
53
+ }
54
+
55
+ warn(...args: string[]) : void {
56
+ hilog.warn(this.domain, this.prefix, this.format, args);
57
+ }
58
+
59
+ error(...args: string[]) : void {
60
+ hilog.error(this.domain, this.prefix, this.format, args);
61
+ }
62
+ }
63
+
64
+ export default new Logger('RNCViewPager', 0xFF00, false)
@@ -0,0 +1,281 @@
1
+ /**
2
+ * MIT License
3
+ *
4
+ * Copyright (C) 2023 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
+ */
24
+
25
+ import {
26
+ Descriptor,
27
+ RNOHContext,
28
+ ViewBaseProps,
29
+ RNViewBase,
30
+ ComponentBuilderContext,
31
+ RNComponentFactory,
32
+ Tag,
33
+ RNOHComponentCommand
34
+ } from '@rnoh/react-native-openharmony'
35
+ import inputMethod from '@ohos.inputMethod';
36
+ import { RNCViewPagerManager } from './RNCViewPagerManager';
37
+ import Logger from './Logger';
38
+
39
+ export const PAGER_VIEW_TYPE: string = "RNCViewPager";
40
+
41
+ const TAG: string = "[RNOH] RNCViewPager";
42
+
43
+ export interface ViewPagerProps extends ViewBaseProps {
44
+ initialPage: number
45
+ layoutDirection: string
46
+ orientation: string
47
+ pageMargin: number
48
+ offscreenPageLimit: number
49
+ scrollEnabled: boolean
50
+ overScrollMode: string
51
+ overdrag: boolean
52
+ keyboardDismissMode: string
53
+ }
54
+
55
+ export type ViewPagerDescriptor = Descriptor<"RNCViewPager", ViewPagerProps>
56
+
57
+ export type ViewPagerState = 'idle' | 'dragging' | 'settling'
58
+
59
+
60
+ @Component
61
+ export struct RNCViewPager {
62
+ ctx!: RNOHContext
63
+ tag: number = 0
64
+ @BuilderParam buildCustomComponent: (ComponentBuilderContext: ComponentBuilderContext) => void
65
+ @State descriptor: ViewPagerDescriptor = {} as ViewPagerDescriptor
66
+ @State pageIndex: number = 0
67
+ @State pageScrollEnabled: boolean = true
68
+ @State isNativeLock: boolean = false
69
+ private defaultDuration: number = 100
70
+ @State AnimationDuration: number = this.defaultDuration
71
+ private inputMethodController = inputMethod.getInputMethodController();
72
+ private componentManager!: RNCViewPagerManager
73
+ private swiperController: SwiperController = new SwiperController()
74
+ private unregisterDescriptorChangesListener?: () => void = undefined
75
+ private cleanupCommandCallback?: () => void = undefined
76
+ private unregisterComponentManager?: () => void = undefined
77
+ private currentState: ViewPagerState = 'idle'
78
+
79
+ aboutToAppear() {
80
+ this.descriptor = this.ctx.descriptorRegistry.getDescriptor<ViewPagerDescriptor>(this.tag)
81
+ Logger.info(TAG, `props:${JSON.stringify(this.descriptor.props)}`)
82
+ this.unregisterDescriptorChangesListener = this.ctx.descriptorRegistry.subscribeToDescriptorChanges(this.tag,
83
+ (newDescriptor) => {
84
+ this.descriptor = (newDescriptor as ViewPagerDescriptor)
85
+ }
86
+ )
87
+ this.pageIndex = this.descriptor.props.initialPage
88
+ this.pageScrollEnabled = this.descriptor.props.scrollEnabled
89
+ this.cleanupCommandCallback = this.ctx.componentCommandReceiver.registerCommandCallback(
90
+ this.tag,
91
+ (command, args: (boolean | number)[]) => {
92
+ if (command === 'setPage') {
93
+ Logger.debug(TAG, `setPage command, selectedPage: ${args[0]}`)
94
+ this.pageIndex = args[0] as number
95
+ } else if (command === 'setPageWithoutAnimation') {
96
+ Logger.debug(TAG, `setPageWithoutAnimation command, selectedPage: ${args[0]}`)
97
+ this.AnimationDuration = 0
98
+ this.pageIndex = args[0] as number
99
+ } else if (command === 'setScrollEnabledImperatively') {
100
+ Logger.debug(TAG, `setScrollEnabledImperatively command, scrollEnabled: ${args[0]}`)
101
+ this.pageScrollEnabled = Boolean(args[0])
102
+ if (!this.pageScrollEnabled) {
103
+ this.emitTouchEvent("idle")
104
+ }
105
+ } else if (command === RNOHComponentCommand.BLOCK_NATIVE_RESPONDER) {
106
+ Logger.debug(TAG, `BLOCK_NATIVE_RESPONDER command`)
107
+ this.isNativeLock = true
108
+ this.emitTouchEvent("idle")
109
+ } else if (command === RNOHComponentCommand.UNBLOCK_NATIVE_RESPONDER) {
110
+ Logger.debug(TAG, `UNBLOCK_NATIVE_RESPONDER command`)
111
+ this.isNativeLock = false
112
+ }
113
+ });
114
+
115
+ if (!this.componentManager) {
116
+ this.componentManager = new RNCViewPagerManager(this.tag, this.ctx, this.pageIndex)
117
+ }
118
+ this.unregisterComponentManager = this.ctx.componentManagerRegistry.registerComponentManager(this.tag, this.componentManager)
119
+ }
120
+
121
+ aboutToDisappear() {
122
+ this.cleanupCommandCallback?.();
123
+ this.unregisterDescriptorChangesListener?.()
124
+ this.unregisterComponentManager?.()
125
+ }
126
+
127
+ getEffectMode() {
128
+ if (this.descriptor.props.overdrag) {
129
+ return EdgeEffect.Spring;
130
+ } else {
131
+ if (this.descriptor.props.overScrollMode == "never") {
132
+ return EdgeEffect.None;
133
+ } else {
134
+ return EdgeEffect.Fade;
135
+ }
136
+ }
137
+ }
138
+
139
+ onChange(index: number) {
140
+ this.pageIndex = index;
141
+ this.componentManager.setPage(this.pageIndex)
142
+ Logger.debug(TAG, `onChange,${JSON.stringify({
143
+ type: "selected",
144
+ pageIndex: index
145
+ })}`)
146
+ this.ctx.rnInstance.emitComponentEvent(
147
+ this.descriptor.tag,
148
+ PAGER_VIEW_TYPE,
149
+ {
150
+ type: "selected",
151
+ pageIndex: index
152
+ }
153
+ );
154
+
155
+ this.ctx.rnInstance.emitComponentEvent(
156
+ this.descriptor.tag,
157
+ PAGER_VIEW_TYPE,
158
+ {
159
+ type: "scroll",
160
+ position: index,
161
+ offset: 0
162
+ }
163
+ );
164
+ }
165
+
166
+ onAnimationStart(index: number) {
167
+ Logger.debug(TAG, `onAnimationStart,index number:${index}`)
168
+ if (this.descriptor.props.keyboardDismissMode == "on-drag") {
169
+ this.inputMethodController.stopInputSession().then((result) => {
170
+ if (result) {
171
+ Logger.info(TAG, 'Success to stopInput.(promise)');
172
+ } else {
173
+ Logger.warn(TAG, 'Failed to stopInput.(promise)');
174
+ }
175
+ }).catch((err: string | Error) => {
176
+ Logger.error(TAG, 'stopInput promise err:' + JSON.stringify(err));
177
+ })
178
+ }
179
+ this.emitTouchEvent("settling");
180
+ }
181
+
182
+ onAnimationEnd(index: number) {
183
+ Logger.debug(TAG, `onAnimationEnd,index number:${index}`)
184
+ this.emitTouchEvent("idle");
185
+ this.AnimationDuration = this.defaultDuration
186
+
187
+ this.ctx.rnInstance.emitComponentEvent(
188
+ this.descriptor.tag,
189
+ PAGER_VIEW_TYPE,
190
+ {
191
+ type: "scroll",
192
+ position: index,
193
+ offset: 0
194
+ }
195
+ );
196
+ }
197
+
198
+ emitTouchEvent(event: ViewPagerState) {
199
+ if (this.currentState == event) {
200
+ return;
201
+ }
202
+ this.currentState = event
203
+ Logger.debug(TAG, `emitTouchEvent:${event}`)
204
+ this.ctx.rnInstance.emitComponentEvent(
205
+ this.descriptor.tag,
206
+ PAGER_VIEW_TYPE,
207
+ {
208
+ type: "scroll_state_changed",
209
+ pageScrollState: event
210
+ }
211
+ );
212
+ }
213
+
214
+ build() {
215
+ RNViewBase({ ctx: this.ctx, tag: this.tag, componentManager:this.componentManager}) {
216
+ Swiper(this.swiperController) {
217
+ ForEach(this.descriptor.childrenTags, (tag: Tag) => {
218
+ Stack() {
219
+ RNComponentFactory({ ctx: this.ctx, tag: tag, buildCustomComponent: this.buildCustomComponent })
220
+ }
221
+ .width("100%")
222
+ .height("100%")
223
+ }, (tag: Tag) => tag.toString())
224
+ }
225
+ .width("100%")
226
+ .height("100%")
227
+ .index(this.pageIndex)
228
+ .indicator(false)
229
+ .vertical(this.descriptor.props.orientation == "horizontal" ? false : true)
230
+ .direction(this.descriptor.props.layoutDirection == "ltr" ? Direction.Ltr : Direction.Rtl)
231
+ .itemSpace(this.descriptor.props.pageMargin)
232
+ .cachedCount(this.descriptor.props.offscreenPageLimit)
233
+ .disableSwipe(!this.pageScrollEnabled || this.isNativeLock)
234
+ .effectMode(this.getEffectMode())
235
+ .onChange((index: number) => this.onChange(index))
236
+ .onAnimationStart((index: number) => this.onAnimationStart(index))
237
+ .onAnimationEnd((index: number) => this.onAnimationEnd(index))
238
+ .duration(this.AnimationDuration)
239
+ .loop(false)
240
+ .onGestureSwipe((index: number, extraInfo: SwiperAnimationEvent) => {
241
+ Logger.debug(TAG, `onGestureSwipe,onGestureSwipe:${index},extraInfo:${JSON.stringify(extraInfo)}`)
242
+ if (!this.pageScrollEnabled || this.isNativeLock) {
243
+ return
244
+ }
245
+ //1216修改,规避起始边缘tab异常场景(双指右滑,选项卡异常),22是测试观察取的经验值
246
+ if (index == 0 && Math.abs(extraInfo.currentOffset) < 22) {
247
+ Logger.debug(TAG, `onGestureSwipe,ignore,limit offset:${index},extraInfo:${JSON.stringify(extraInfo)}`)
248
+ return
249
+ }
250
+ this.emitTouchEvent("dragging");
251
+
252
+ let offset = 0;
253
+ let finalIndex = index;
254
+ if (extraInfo.currentOffset < 0) {
255
+ offset = Math.abs(extraInfo.currentOffset / this.descriptor.layoutMetrics.frame.size.width);
256
+ } else {
257
+ finalIndex = (index - 1) > 0 ? (index - 1) : 0;
258
+ offset = 1 - Math.abs(extraInfo.currentOffset / this.descriptor.layoutMetrics.frame.size.width);
259
+ }
260
+
261
+ if (offset > 1) {
262
+ offset = offset - 1;
263
+ finalIndex = finalIndex + 1;
264
+ } else if (offset < 0 && finalIndex >= 1) {
265
+ offset = offset + 1;
266
+ finalIndex = finalIndex - 1;
267
+ }
268
+
269
+ this.ctx.rnInstance.emitComponentEvent(
270
+ this.descriptor.tag,
271
+ PAGER_VIEW_TYPE,
272
+ {
273
+ type: "scroll",
274
+ position: finalIndex,
275
+ offset: offset
276
+ }
277
+ );
278
+ })
279
+ }
280
+ }
281
+ }
@@ -0,0 +1,58 @@
1
+ /**
2
+ * MIT License
3
+ *
4
+ * Copyright (C) 2023 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
+ */
24
+
25
+ import { RNOHContext,RNViewManager,Tag } from '@rnoh/react-native-openharmony';
26
+ import {ViewPagerDescriptor} from './RNCViewPager';
27
+ import Logger from './Logger';
28
+
29
+ const TAG: string = "[RNOH] RNCViewPagerManager";
30
+
31
+ export class RNCViewPagerManager extends RNViewManager{
32
+ protected page:number = 0;
33
+
34
+ constructor(
35
+ tag:Tag,
36
+ ctx:RNOHContext,
37
+ page:number
38
+ ) {
39
+ super(tag,ctx);
40
+ this.page = page
41
+ }
42
+
43
+ setPage(page:number){
44
+ this.page = page
45
+ }
46
+
47
+ public getActiveChildrenTags(): Tag[]{
48
+ const descriptor = (this.descriptorRegistry.getDescriptor(this.tag)) as ViewPagerDescriptor;
49
+ let page = this.page
50
+ Logger.debug(TAG,`descriptor:${JSON.stringify(descriptor)}`)
51
+ Logger.debug(TAG,`page:${JSON.stringify(page)}`)
52
+ if (page < 0 || page >= descriptor.childrenTags.length) {
53
+ console.error(`RNOH in RNCViewPagerManager,descriptor.childrenTags out-of-bounds`)
54
+ page = 0
55
+ }
56
+ return [descriptor.childrenTags[page]];
57
+ }
58
+ }