@react-native-ohos/slider 5.0.1-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 (56) hide show
  1. package/LICENSE +9 -0
  2. package/README.OpenSource +11 -0
  3. package/README.md +13 -0
  4. package/dist/RNCSliderNativeComponent.js +1 -0
  5. package/dist/Slider.js +1 -0
  6. package/dist/components/StepNumber.js +1 -0
  7. package/dist/components/StepsIndicator.js +1 -0
  8. package/dist/components/TrackMark.js +1 -0
  9. package/dist/index.js +1 -0
  10. package/dist/utils/constants.js +1 -0
  11. package/dist/utils/styles.js +1 -0
  12. package/harmony/slider/.idea/misc.xml +6 -0
  13. package/harmony/slider/.idea/modules.xml +8 -0
  14. package/harmony/slider/.idea/slider.iml +8 -0
  15. package/harmony/slider/LICENSE +21 -0
  16. package/harmony/slider/OAT.xml +42 -0
  17. package/harmony/slider/README.OpenSource +11 -0
  18. package/harmony/slider/build-profile.json5 +8 -0
  19. package/harmony/slider/hvigorfile.ts +1 -0
  20. package/harmony/slider/index.ets +25 -0
  21. package/harmony/slider/obfuscation-rules.txt +18 -0
  22. package/harmony/slider/oh-package-lock.json5 +18 -0
  23. package/harmony/slider/oh-package.json5 +11 -0
  24. package/harmony/slider/src/main/cpp/CMakeLists.txt +7 -0
  25. package/harmony/slider/src/main/cpp/ComponentDescriptor.h +36 -0
  26. package/harmony/slider/src/main/cpp/EventEmitters.cpp +68 -0
  27. package/harmony/slider/src/main/cpp/EventEmitters.h +67 -0
  28. package/harmony/slider/src/main/cpp/Props.cpp +49 -0
  29. package/harmony/slider/src/main/cpp/Props.h +56 -0
  30. package/harmony/slider/src/main/cpp/ShadowNodes.cpp +33 -0
  31. package/harmony/slider/src/main/cpp/ShadowNodes.h +46 -0
  32. package/harmony/slider/src/main/cpp/SliderEventEmiRequestHandler.h +93 -0
  33. package/harmony/slider/src/main/cpp/SliderJSIBinder.h +67 -0
  34. package/harmony/slider/src/main/cpp/SliderNapiBinder.h +47 -0
  35. package/harmony/slider/src/main/cpp/SliderPackage.h +53 -0
  36. package/harmony/slider/src/main/ets/Logger.ets +64 -0
  37. package/harmony/slider/src/main/ets/Slider.ets +182 -0
  38. package/harmony/slider/src/main/ets/SliderDescriptorWrapper.ets +78 -0
  39. package/harmony/slider/src/main/module.json5 +9 -0
  40. package/harmony/slider/src/main/resources/base/element/color.json +8 -0
  41. package/harmony/slider/src/main/resources/base/element/string.json +16 -0
  42. package/harmony/slider/src/main/resources/base/media/icon.png +0 -0
  43. package/harmony/slider/src/main/resources/base/profile/main_pages.json +5 -0
  44. package/harmony/slider/src/main/resources/en_US/element/string.json +16 -0
  45. package/harmony/slider/src/main/resources/zh_CN/element/string.json +16 -0
  46. package/harmony/slider.har +0 -0
  47. package/package.json +98 -0
  48. package/src/RNCSliderNativeComponent.ts +47 -0
  49. package/src/Slider.tsx +350 -0
  50. package/src/components/StepNumber.tsx +17 -0
  51. package/src/components/StepsIndicator.tsx +83 -0
  52. package/src/components/TrackMark.tsx +50 -0
  53. package/src/index.ts +3 -0
  54. package/src/utils/constants.ts +11 -0
  55. package/src/utils/styles.ts +55 -0
  56. package/typings/index.d.ts +208 -0
@@ -0,0 +1,46 @@
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
+ #pragma once
25
+
26
+ #include <react/renderer/components/view/ConcreteViewShadowNode.h>
27
+ #include <react/renderer/components/view/ViewShadowNode.h>
28
+ #include <jsi/jsi.h>
29
+ #include "EventEmitters.h"
30
+ #include "Props.h"
31
+
32
+ namespace facebook {
33
+ namespace react {
34
+
35
+ JSI_EXPORT extern const char RNCSliderComponentName[];
36
+
37
+ /*
38
+ * `ShadowNode` for <RNCSlider> component.
39
+ */
40
+ using RNCSliderShadowNode = ConcreteViewShadowNode<
41
+ RNCSliderComponentName,
42
+ RNCSliderProps,
43
+ RNCSliderEventEmitter>;
44
+
45
+ } // namespace react
46
+ } // namespace facebook
@@ -0,0 +1,93 @@
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
+ #pragma once
26
+
27
+ #include "RNOH/ArkJS.h"
28
+ #include "RNOH/EventEmitRequestHandler.h"
29
+ #include "EventEmitters.h"
30
+
31
+
32
+ using namespace facebook;
33
+ namespace rnoh {
34
+
35
+ enum SliderEventType {
36
+ VALUE_CHANGE = 0,
37
+ SLIDING_START = 1,
38
+ SLIDING_COMPLETE = 2
39
+ };
40
+
41
+ SliderEventType getSliderEventType(ArkJS &arkJs, napi_value eventObject) {
42
+ auto eventType = arkJs.getString(arkJs.getObjectProperty(eventObject, "type"));
43
+ if (eventType == "SliderValueChange") {
44
+ return SliderEventType::VALUE_CHANGE;
45
+ } else if (eventType == "SliderSlidingStart") {
46
+ return SliderEventType::SLIDING_START;
47
+ } else if (eventType == "SliderSlidingComplete") {
48
+ return SliderEventType::SLIDING_COMPLETE;
49
+ } else {
50
+ throw std::runtime_error("Unknown Slider event type");
51
+ };
52
+ };
53
+
54
+ class SliderEventEmitRequestHandler : public EventEmitRequestHandler {
55
+ public:
56
+ void handleEvent(EventEmitRequestHandler::Context const &ctx) override {
57
+ if (ctx.eventName != "RNCSlider") {
58
+ return;
59
+ }
60
+ ArkJS arkJs(ctx.env);
61
+ auto eventEmitter = ctx.shadowViewRegistry->getEventEmitter<react::RNCSliderEventEmitter>(ctx.tag);
62
+ if (eventEmitter == nullptr) {
63
+ return;
64
+ }
65
+ auto eventType = getSliderEventType(arkJs, ctx.payload);
66
+ switch (eventType)
67
+ {
68
+ case SliderEventType::VALUE_CHANGE: {
69
+ facebook::react::Float value = arkJs.getDouble(arkJs.getObjectProperty(ctx.payload, "value"));
70
+ react::RNCSliderEventEmitter::OnChange event1 = {value};
71
+ eventEmitter->onChange(event1);
72
+ react::RNCSliderEventEmitter::OnRNCSliderValueChange event2 = {value};
73
+ eventEmitter->onRNCSliderValueChange(event2);
74
+ break;
75
+ }
76
+ case SliderEventType::SLIDING_START: {
77
+ facebook::react::Float value = arkJs.getDouble(arkJs.getObjectProperty(ctx.payload, "value"));
78
+ react::RNCSliderEventEmitter::OnRNCSliderSlidingStart event = {value};
79
+ eventEmitter->onRNCSliderSlidingStart(event);
80
+ break;
81
+ }
82
+ case SliderEventType::SLIDING_COMPLETE: {
83
+ facebook::react::Float value = arkJs.getDouble(arkJs.getObjectProperty(ctx.payload, "value"));
84
+ react::RNCSliderEventEmitter::OnRNCSliderSlidingComplete event = {value};
85
+ eventEmitter->onRNCSliderSlidingComplete(event);
86
+ break;
87
+ }
88
+ default:
89
+ break;
90
+ }
91
+ };
92
+ };
93
+ } // namespace rnoh
@@ -0,0 +1,67 @@
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
+ #pragma once
26
+
27
+ #include "RNOHCorePackage/ComponentBinders/ViewComponentJSIBinder.h"
28
+
29
+ namespace rnoh {
30
+
31
+ class SliderJSIBinder : public ViewComponentJSIBinder {
32
+ facebook::jsi::Object createNativeProps(facebook::jsi::Runtime &rt) override {
33
+ auto object = ViewComponentJSIBinder::createNativeProps(rt);
34
+ object.setProperty(rt, "disabled", "boolean");
35
+ object.setProperty(rt, "inverted", "boolean");
36
+ object.setProperty(rt, "vertical", "boolean");
37
+ object.setProperty(rt, "tapToSeek", "boolean");
38
+ object.setProperty(rt, "maximumTrackTintColor", "Color");
39
+ object.setProperty(rt, "minimumTrackTintColor", "Color");
40
+ object.setProperty(rt, "thumbTintColor", "Color");
41
+ object.setProperty(rt, "testID", "string");
42
+ object.setProperty(rt, "thumbImage", "object");
43
+ object.setProperty(rt, "maximumValue", "float");
44
+ object.setProperty(rt, "minimumValue", "float");
45
+ object.setProperty(rt, "step", "float");
46
+ object.setProperty(rt, "value", "float");
47
+ object.setProperty(rt, "lowerLimit", "float");
48
+ object.setProperty(rt, "upperLimit", "float");
49
+ return object;
50
+ }
51
+
52
+ facebook::jsi::Object createBubblingEventTypes(facebook::jsi::Runtime &rt) override {
53
+ facebook::jsi::Object events(rt);
54
+ events.setProperty(rt, "topChange", createDirectEvent(rt, "onChange"));
55
+ events.setProperty(rt, "topRNCSliderValueChange", createDirectEvent(rt, "onRNCSliderValueChange"));
56
+ return events;
57
+ }
58
+
59
+ facebook::jsi::Object createDirectEventTypes(facebook::jsi::Runtime &rt) override {
60
+ facebook::jsi::Object events(rt);
61
+ events.setProperty(rt, "topRNCSliderSlidingStart", createDirectEvent(rt, "onRNCSliderSlidingStart"));
62
+ events.setProperty(rt, "topRNCSliderSlidingComplete", createDirectEvent(rt, "onRNCSliderSlidingComplete"));
63
+ return events;
64
+ }
65
+
66
+ };
67
+ } // namespace rnoh
@@ -0,0 +1,47 @@
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
+ #pragma once
25
+
26
+ #include "RNOHCorePackage/ComponentBinders/ViewComponentNapiBinder.h"
27
+ #include "Props.h"
28
+
29
+ namespace rnoh {
30
+
31
+ class SliderNapiBinder : public ViewComponentNapiBinder {
32
+ public:
33
+ napi_value createProps(napi_env env, facebook::react::ShadowView const shadowView) override {
34
+ napi_value napiViewProps = ViewComponentNapiBinder::createProps(env, shadowView);
35
+ if (auto props = std::dynamic_pointer_cast<const facebook::react::RNCSliderProps>(shadowView.props)) {
36
+ return ArkJS(env)
37
+ .getObjectBuilder(napiViewProps)
38
+ .addProperty("maximumTrackTintColor", props->maximumTrackTintColor)
39
+ .addProperty("minimumTrackTintColor", props->minimumTrackTintColor)
40
+ .addProperty("thumbTintColor", props->thumbTintColor)
41
+ .addProperty("thumbImage", props->thumbImage.uri)
42
+ .build();
43
+ }
44
+ return napiViewProps;
45
+ };
46
+ };
47
+ } //namespace rnoh
@@ -0,0 +1,53 @@
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
+ #include "RNOH/Package.h"
26
+ #include "ComponentDescriptor.h"
27
+ #include "SliderJSIBinder.h"
28
+ #include "SliderNapiBinder.h"
29
+ #include "SliderEventEmiRequestHandler.h"
30
+
31
+ namespace rnoh {
32
+
33
+ class SliderPackage : public Package {
34
+ public:
35
+ SliderPackage(Package::Context ctx): Package(ctx) {}
36
+
37
+ std::vector<facebook::react::ComponentDescriptorProvider> createComponentDescriptorProviders() override {
38
+ return {facebook::react::concreteComponentDescriptorProvider<facebook::react::RNCSliderComponentDescriptor>()};
39
+ }
40
+
41
+ ComponentNapiBinderByString createComponentNapiBinderByName() override {
42
+ return {{"RNCSlider", std::make_shared<SliderNapiBinder>()}};
43
+ }
44
+
45
+ ComponentJSIBinderByString createComponentJSIBinderByName() override {
46
+ return {{"RNCSlider", std::make_shared<SliderJSIBinder>()}};
47
+ }
48
+
49
+ EventEmitRequestHandlers createEventEmitRequestHandlers() override {
50
+ return {std::make_shared<SliderEventEmitRequestHandler>()};
51
+ }
52
+ };
53
+ } // namespace rnoh
@@ -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('RNCSlider', 0xFF00, false)
@@ -0,0 +1,182 @@
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
+ ColorSegments,
31
+ ViewRawProps,
32
+ } from '@rnoh/react-native-openharmony'
33
+ import { SliderDescriptorWrapper } from './SliderDescriptorWrapper'
34
+ import Logger from './Logger'
35
+
36
+ const TAG: string = "[RNOH] RNCSlider"
37
+
38
+ export const SLIDER_TYPE: string = "RNCSlider"
39
+
40
+ const DEFAULT_LIMIT_VALUE = -9007199254740991;
41
+ const DEFAULT_MAX_VALUE = 9007199254740991;
42
+
43
+ export interface SliderProps extends ViewBaseProps {
44
+ thumbImage?: string
45
+ maximumTrackTintColor?: ColorSegments
46
+ minimumTrackTintColor?: ColorSegments
47
+ thumbTintColor?: ColorSegments
48
+ }
49
+
50
+ export interface SliderSate {}
51
+
52
+ export interface SliderRawProps extends ViewRawProps {
53
+ disabled?: boolean
54
+ inverted?: boolean
55
+ vertical?: boolean
56
+ tapToSeek?: boolean
57
+ testID?: string
58
+ maximumValue?: number
59
+ minimumValue?: number
60
+ step?: number
61
+ value?: number
62
+ lowerLimit?: number
63
+ upperLimit?: number
64
+ }
65
+
66
+ export type SliderDescriptor = Descriptor<"RNCSlider", SliderProps, SliderSate, SliderRawProps>
67
+
68
+ @Component
69
+ export struct RNCSlider {
70
+ ctx!: RNOHContext
71
+ tag: number = 0
72
+ @State descriptor: SliderDescriptor = {} as SliderDescriptor
73
+ @State private descriptorWrapper: SliderDescriptorWrapper | undefined = undefined
74
+ private unregisterDescriptorChangesListener?: ()=> void = undefined
75
+ @State SliderValue: number = 0
76
+ private lowerLimit = 0
77
+ private upperLimit = 0
78
+
79
+ aboutToAppear() {
80
+ this.descriptor = this.ctx.descriptorRegistry.getDescriptor<SliderDescriptor>(this.tag);
81
+ this.descriptorWrapper = new SliderDescriptorWrapper(this.descriptor);
82
+ this.unregisterDescriptorChangesListener = this.ctx.descriptorRegistry.subscribeToDescriptorChanges(this.tag,
83
+ (newDescriptor) => {
84
+ this.descriptor = (newDescriptor as SliderDescriptor)
85
+ this.descriptorWrapper = new SliderDescriptorWrapper(this.descriptor);
86
+ let value = this.descriptorWrapper.value;
87
+ if (value < this.lowerLimit) {
88
+ value = this.lowerLimit;
89
+ } else if (value > this.upperLimit) {
90
+ value = this.upperLimit;
91
+ }
92
+ this.SliderValue = this.descriptor.rawProps.value ? value : this.SliderValue;
93
+ }
94
+ );
95
+ this.SliderValue = this.descriptorWrapper.value;
96
+ this.upperLimit = this.descriptorWrapper.upperLimit;
97
+ this.lowerLimit = this.descriptorWrapper.lowerLimit;
98
+ Logger.info(TAG, `descriptor props: ${JSON.stringify(this.descriptor.rawProps)}`)
99
+ }
100
+
101
+ aboutToDisappear() {
102
+ this.unregisterDescriptorChangesListener?.()
103
+ }
104
+
105
+ onSliderChange(value: number, mode: SliderChangeMode) {
106
+ Logger.debug(TAG, `onSliderChange: ${value}, ${mode}`)
107
+ if (value < this.lowerLimit) {
108
+ value = this.lowerLimit;
109
+ } else if (value > this.upperLimit) {
110
+ value = this.upperLimit;
111
+ }
112
+ this.SliderValue = value
113
+ if (mode === 0) {
114
+ this.ctx.rnInstance.emitComponentEvent(
115
+ this.descriptor.tag,
116
+ SLIDER_TYPE,
117
+ {
118
+ type: "SliderSlidingStart",
119
+ value: value,
120
+ // fromUser: true
121
+ }
122
+ );
123
+ } else if (mode === 1) {
124
+ this.ctx.rnInstance.emitComponentEvent(
125
+ this.descriptor.tag,
126
+ SLIDER_TYPE,
127
+ {
128
+ type: "SliderValueChange",
129
+ value: value,
130
+ // fromUser: true
131
+ }
132
+ );
133
+ } else if (mode === 2) {
134
+ this.ctx.rnInstance.emitComponentEvent(
135
+ this.descriptor.tag,
136
+ SLIDER_TYPE,
137
+ {
138
+ type: "SliderSlidingComplete",
139
+ value: value,
140
+ // fromUser: true
141
+ }
142
+ );
143
+ } else if (mode === 3) {
144
+ this.ctx.rnInstance.emitComponentEvent(
145
+ this.descriptor.tag,
146
+ SLIDER_TYPE,
147
+ {
148
+ type: "SliderValueChange",
149
+ value: value,
150
+ // fromUser: true
151
+ }
152
+ );
153
+ }
154
+ }
155
+
156
+ build() {
157
+ RNViewBase({ ctx: this.ctx, tag: this.tag }) {
158
+ Slider({
159
+ value: this.SliderValue,
160
+ step: this.descriptor.rawProps.step,
161
+ min: this.descriptorWrapper?.minimumValue,
162
+ max: this.descriptorWrapper?.maximumValue,
163
+ direction: (this.descriptorWrapper?.direction),
164
+ reverse: (this.descriptorWrapper?.reverse),
165
+ style: SliderStyle.OutSet
166
+ })
167
+ .width("100%")
168
+ .height("100%")
169
+ .enabled(this.descriptorWrapper?.enabled)
170
+ .blockColor(this.descriptorWrapper?.blockColor)
171
+ .trackColor(this.descriptorWrapper?.trackColor)
172
+ .selectedColor(this.descriptorWrapper?.selectedColor)
173
+ .showSteps(false)
174
+ .blockStyle(this.descriptorWrapper?.BlockStyle)
175
+ .onChange((value: number, mode: SliderChangeMode) => this.onSliderChange(value, mode))
176
+ .slideRange({
177
+ from: this.lowerLimit === DEFAULT_LIMIT_VALUE ? this.descriptorWrapper?.minimumValue : this.lowerLimit,
178
+ to: this.upperLimit === DEFAULT_MAX_VALUE ? this.descriptorWrapper?.maximumValue : this.upperLimit
179
+ })
180
+ }
181
+ }
182
+ }
@@ -0,0 +1,78 @@
1
+ import { convertColorValueToRGBA, Descriptor, convertColorSegmentsToString, ViewDescriptorWrapperBase, ViewBaseProps,
2
+ ColorSegments } from '@rnoh/react-native-openharmony';
3
+ import { SliderProps, SliderSate, SliderRawProps } from './Slider'
4
+
5
+ const LIMIT_MIN_VALUE = Number.MIN_VALUE;
6
+ const LIMIT_MAX_VALUE = Number.MAX_VALUE;
7
+
8
+ export class SliderDescriptorWrapper extends ViewDescriptorWrapperBase<string, SliderProps, SliderSate, SliderRawProps> {
9
+ constructor(descriptor: Descriptor<string, SliderProps, SliderSate, SliderRawProps>) {
10
+ super(descriptor)
11
+ }
12
+
13
+ public get source(): Resource {
14
+ if (this.descriptor.props.thumbImage?.startsWith("asset://")) {
15
+ return $rawfile(this.descriptor.props.thumbImage?.replace("asset://", "assets/"));
16
+ }
17
+ if (this.descriptor.props.thumbImage?.startsWith("file://assets/src/assets/")) {
18
+ return $rawfile(this.descriptor.props.thumbImage?.replace("file://assets/src/assets/", "assets/"));
19
+ }
20
+ return $rawfile(this.descriptor.props.thumbImage);
21
+ }
22
+
23
+ public get BlockStyle(): SliderBlockStyle {
24
+ if (this.descriptor.props.thumbImage) {
25
+ return {
26
+ type: SliderBlockType.IMAGE,
27
+ image: this.source
28
+ };
29
+ }
30
+ return { type: SliderBlockType.DEFAULT };
31
+ }
32
+
33
+ public get value(): number {
34
+ return this.rawProps.value ?? 0
35
+ }
36
+
37
+ public get maximumValue(): number {
38
+ return this.rawProps.maximumValue ?? LIMIT_MAX_VALUE
39
+ }
40
+
41
+ public get minimumValue(): number {
42
+ return this.rawProps.minimumValue ?? LIMIT_MIN_VALUE
43
+ }
44
+
45
+ public get upperLimit(): number {
46
+ return this.rawProps.upperLimit ?? this.maximumValue
47
+ }
48
+
49
+ public get lowerLimit(): number {
50
+ return this.rawProps.lowerLimit ?? this.minimumValue;
51
+ }
52
+
53
+
54
+ public get direction(): Axis {
55
+ return this.rawProps.vertical ? Axis.Vertical : Axis.Horizontal;
56
+ }
57
+
58
+ public get reverse(): boolean {
59
+ return this.rawProps.inverted ? true : false;
60
+ }
61
+
62
+ public get enabled(): boolean {
63
+ return this.rawProps.disabled ? false : true;
64
+ }
65
+
66
+ public get blockColor(): string | undefined {
67
+ return convertColorSegmentsToString(this.descriptor.props.thumbTintColor);
68
+ }
69
+
70
+ public get trackColor(): string | undefined {
71
+ return convertColorSegmentsToString(this.descriptor.props.maximumTrackTintColor);
72
+ }
73
+
74
+ public get selectedColor(): string | undefined {
75
+ return convertColorSegmentsToString(this.descriptor.props.minimumTrackTintColor);
76
+ }
77
+
78
+ }
@@ -0,0 +1,9 @@
1
+ {
2
+ "module": {
3
+ "name": "slider",
4
+ "type": "har",
5
+ "deviceTypes": [
6
+ 'default'
7
+ ],
8
+ },
9
+ }
@@ -0,0 +1,8 @@
1
+ {
2
+ "color": [
3
+ {
4
+ "name": "start_window_background",
5
+ "value": "#FFFFFF"
6
+ }
7
+ ]
8
+ }
@@ -0,0 +1,16 @@
1
+ {
2
+ "string": [
3
+ {
4
+ "name": "module_desc",
5
+ "value": "module description"
6
+ },
7
+ {
8
+ "name": "EntryAbility_desc",
9
+ "value": "description"
10
+ },
11
+ {
12
+ "name": "EntryAbility_label",
13
+ "value": "label"
14
+ }
15
+ ]
16
+ }
@@ -0,0 +1,5 @@
1
+ {
2
+ "src": [
3
+ "pages/Index"
4
+ ]
5
+ }