@react-native-ohos/slider 4.4.4-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 (43) hide show
  1. package/.eslintrc.json +20 -0
  2. package/.flowconfig +66 -0
  3. package/babel.config.json +3 -0
  4. package/dist/RNCSliderNativeComponent.js +1 -0
  5. package/dist/Slider.js +1 -0
  6. package/dist/index.js +1 -0
  7. package/harmony/slider/LICENSE +21 -0
  8. package/harmony/slider/README.OpenSource +11 -0
  9. package/harmony/slider/build-profile.json5 +8 -0
  10. package/harmony/slider/hvigorfile.ts +1 -0
  11. package/harmony/slider/index.ets +26 -0
  12. package/harmony/slider/obfuscation-rules.txt +18 -0
  13. package/harmony/slider/oh-package.json5 +11 -0
  14. package/harmony/slider/src/main/cpp/CMakeLists.txt +7 -0
  15. package/harmony/slider/src/main/cpp/ComponentDescriptor.h +38 -0
  16. package/harmony/slider/src/main/cpp/EventEmitters.cpp +68 -0
  17. package/harmony/slider/src/main/cpp/EventEmitters.h +61 -0
  18. package/harmony/slider/src/main/cpp/Props.cpp +45 -0
  19. package/harmony/slider/src/main/cpp/Props.h +51 -0
  20. package/harmony/slider/src/main/cpp/ShadowNodes.cpp +33 -0
  21. package/harmony/slider/src/main/cpp/ShadowNodes.h +46 -0
  22. package/harmony/slider/src/main/cpp/SliderEventEmiRequestHandler.h +96 -0
  23. package/harmony/slider/src/main/cpp/SliderJSIBinder.h +71 -0
  24. package/harmony/slider/src/main/cpp/SliderNapiBinder.h +51 -0
  25. package/harmony/slider/src/main/cpp/SliderPackage.h +59 -0
  26. package/harmony/slider/src/main/ets/Logger.ets +64 -0
  27. package/harmony/slider/src/main/ets/Slider.ets +182 -0
  28. package/harmony/slider/src/main/ets/SliderDescriptorWrapper.ets +78 -0
  29. package/harmony/slider/src/main/ets/SliderPackage.ets +34 -0
  30. package/harmony/slider/src/main/module.json5 +9 -0
  31. package/harmony/slider/src/main/resources/base/element/color.json +8 -0
  32. package/harmony/slider/src/main/resources/base/element/string.json +16 -0
  33. package/harmony/slider/src/main/resources/base/media/icon.png +0 -0
  34. package/harmony/slider/src/main/resources/base/profile/main_pages.json +5 -0
  35. package/harmony/slider/src/main/resources/en_US/element/string.json +16 -0
  36. package/harmony/slider/src/main/resources/zh_CN/element/string.json +16 -0
  37. package/harmony/slider.har +0 -0
  38. package/package.json +78 -0
  39. package/src/RNCSliderNativeComponent.ts +46 -0
  40. package/src/Slider.tsx +295 -0
  41. package/src/index.ts +3 -0
  42. package/tsconfig.json +22 -0
  43. package/typings/index.d.ts +180 -0
@@ -0,0 +1,71 @@
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
+ #ifndef SLIDERJSIBINDER_H
25
+ #define SLIDERJSIBINDER_H
26
+ #pragma once
27
+
28
+ #include "RNOHCorePackage/ComponentBinders/ViewComponentJSIBinder.h"
29
+
30
+ namespace rnoh {
31
+
32
+ class SliderJSIBinder : public ViewComponentJSIBinder {
33
+ facebook::jsi::Object createNativeProps(facebook::jsi::Runtime &rt) override
34
+ {
35
+ auto object = ViewComponentJSIBinder::createNativeProps(rt);
36
+ object.setProperty(rt, "disabled", "boolean");
37
+ object.setProperty(rt, "inverted", "boolean");
38
+ object.setProperty(rt, "vertical", "boolean");
39
+ object.setProperty(rt, "tapToSeek", "boolean");
40
+ object.setProperty(rt, "maximumTrackTintColor", "Color");
41
+ object.setProperty(rt, "minimumTrackTintColor", "Color");
42
+ object.setProperty(rt, "thumbTintColor", "Color");
43
+ object.setProperty(rt, "testID", "string");
44
+ object.setProperty(rt, "thumbImage", "object");
45
+ object.setProperty(rt, "maximumValue", "float");
46
+ object.setProperty(rt, "minimumValue", "float");
47
+ object.setProperty(rt, "step", "float");
48
+ object.setProperty(rt, "value", "float");
49
+ object.setProperty(rt, "lowerLimit", "float");
50
+ object.setProperty(rt, "upperLimit", "float");
51
+ return object;
52
+ }
53
+
54
+ facebook::jsi::Object createBubblingEventTypes(facebook::jsi::Runtime &rt) override
55
+ {
56
+ facebook::jsi::Object events(rt);
57
+ events.setProperty(rt, "topChange", createBubblingCapturedEvent(rt, "onChange"));
58
+ events.setProperty(rt, "topRNCSliderValueChange", createBubblingCapturedEvent(rt, "onRNCSliderValueChange"));
59
+ return events;
60
+ }
61
+
62
+ facebook::jsi::Object createDirectEventTypes(facebook::jsi::Runtime &rt) override
63
+ {
64
+ facebook::jsi::Object events(rt);
65
+ events.setProperty(rt, "topRNCSliderSlidingStart", createDirectEvent(rt, "onRNCSliderSlidingStart"));
66
+ events.setProperty(rt, "topRNCSliderSlidingComplete", createDirectEvent(rt, "onRNCSliderSlidingComplete"));
67
+ return events;
68
+ }
69
+ };
70
+ } // namespace rnoh
71
+ #endif
@@ -0,0 +1,51 @@
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
+ #ifndef SLIDERNAPIBINDER_H
25
+ #define SLIDERNAPIBINDER_H
26
+ #pragma once
27
+
28
+ #include "RNOHCorePackage/ComponentBinders/ViewComponentNapiBinder.h"
29
+ #include "Props.h"
30
+
31
+ namespace rnoh {
32
+
33
+ class SliderNapiBinder : public ViewComponentNapiBinder {
34
+ public:
35
+ napi_value createProps(napi_env env, facebook::react::ShadowView const shadowView) override
36
+ {
37
+ napi_value napiViewProps = ViewComponentNapiBinder::createProps(env, shadowView);
38
+ if (auto props = std::dynamic_pointer_cast<const facebook::react::RNCSliderProps>(shadowView.props)) {
39
+ return ArkJS(env)
40
+ .getObjectBuilder(napiViewProps)
41
+ .addProperty("maximumTrackTintColor", props->maximumTrackTintColor)
42
+ .addProperty("minimumTrackTintColor", props->minimumTrackTintColor)
43
+ .addProperty("thumbTintColor", props->thumbTintColor)
44
+ .addProperty("thumbImage", props->thumbImage.uri)
45
+ .build();
46
+ }
47
+ return napiViewProps;
48
+ };
49
+ };
50
+ } //namespace rnoh
51
+ #endif
@@ -0,0 +1,59 @@
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
+ #ifndef SLIDERPACKAGE_H
25
+ #define SLIDERPACKAGE_H
26
+ #include "RNOH/Package.h"
27
+ #include "ComponentDescriptor.h"
28
+ #include "SliderJSIBinder.h"
29
+ #include "SliderNapiBinder.h"
30
+ #include "SliderEventEmiRequestHandler.h"
31
+
32
+ namespace rnoh {
33
+
34
+ class SliderPackage : public Package {
35
+ public:
36
+ SliderPackage(Package::Context ctx): Package(ctx) {}
37
+
38
+ std::vector<facebook::react::ComponentDescriptorProvider> createComponentDescriptorProviders() override
39
+ {
40
+ return {facebook::react::concreteComponentDescriptorProvider<facebook::react::RNCSliderComponentDescriptor>()};
41
+ }
42
+
43
+ ComponentNapiBinderByString createComponentNapiBinderByName() override
44
+ {
45
+ return {{"RNCSlider", std::make_shared<SliderNapiBinder>()}};
46
+ }
47
+
48
+ ComponentJSIBinderByString createComponentJSIBinderByName() override
49
+ {
50
+ return {{"RNCSlider", std::make_shared<SliderJSIBinder>()}};
51
+ }
52
+
53
+ EventEmitRequestHandlers createEventEmitRequestHandlers() override
54
+ {
55
+ return {std::make_shared<SliderEventEmitRequestHandler>()};
56
+ }
57
+ };
58
+ } // namespace rnoh
59
+ #endif
@@ -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,34 @@
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
+ import { RNOHPackage, ComponentBuilderContext } from '@rnoh/react-native-openharmony';
25
+ import { RNCSlider } from './Slider';
26
+ @Builder
27
+ function buildSlider(ctx: ComponentBuilderContext) {
28
+ RNCSlider({ ctx: ctx.rnComponentContext, tag: ctx.tag, })
29
+ }
30
+ export class SliderPackage extends RNOHPackage {
31
+ createWrappedCustomRNComponentBuilderByComponentNameMap(): Map<string, WrappedBuilder<[ComponentBuilderContext]>> {
32
+ return new Map().set("RNCSlider", wrapBuilder(buildSlider))
33
+ }
34
+ }
@@ -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
+ }
@@ -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,16 @@
1
+ {
2
+ "string": [
3
+ {
4
+ "name": "module_desc",
5
+ "value": "模块描述"
6
+ },
7
+ {
8
+ "name": "EntryAbility_desc",
9
+ "value": "description"
10
+ },
11
+ {
12
+ "name": "EntryAbility_label",
13
+ "value": "label"
14
+ }
15
+ ]
16
+ }
Binary file