@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,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
package/package.json ADDED
@@ -0,0 +1,98 @@
1
+ {
2
+ "name": "@react-native-ohos/slider",
3
+ "version": "5.0.1-rc.1",
4
+ "license": "MIT",
5
+ "author": "react-native-community",
6
+ "homepage": "https://github.com/callstack/react-native-slider#readme",
7
+ "description": "React Native component used to select a single value from a range of values.",
8
+ "harmony": {
9
+ "alias": "@react-native-community/slider"
10
+ },
11
+ "files": [
12
+ "dist",
13
+ "src",
14
+ "typings",
15
+ "harmony"
16
+ ],
17
+ "publishConfig": {
18
+ "registry": "https://npm.pkg.github.com"
19
+ },
20
+ "main": "dist/Slider.js",
21
+ "types": "typings/index.d.ts",
22
+ "keywords": [
23
+ "react-native",
24
+ "react native",
25
+ "slider"
26
+ ],
27
+ "scripts": {
28
+ "prepare": "babel --extensions \".ts,.tsx\" --out-dir dist src",
29
+ "lint": "npx eslint src",
30
+ "test": "npx jest src"
31
+ },
32
+ "dependencies": {
33
+ "@react-native-community/slider": "5.0.0"
34
+ },
35
+ "devDependencies": {
36
+ "@babel/cli": "^7.8.4",
37
+ "@babel/core": "^7.25.2",
38
+ "@babel/preset-flow": "^7.9.0",
39
+ "@babel/preset-typescript": "^7.18.6",
40
+ "@babel/runtime": "^7.25.0",
41
+ "@react-native-community/cli": "15.0.1",
42
+ "@react-native-community/cli-platform-android": "15.0.1",
43
+ "@react-native-community/cli-platform-ios": "15.0.1",
44
+ "@react-native-community/eslint-config": "^3.2.0",
45
+ "@react-native/babel-preset": "0.76.3",
46
+ "@react-native/eslint-config": "0.76.3",
47
+ "@react-native/metro-config": "0.76.3",
48
+ "@react-native/typescript-config": "0.76.3",
49
+ "@types/jest": "^28.1.8",
50
+ "@types/react": "^18.2.6",
51
+ "@types/react-test-renderer": "^18.0.0",
52
+ "babel-jest": "^29.7.0",
53
+ "babel-plugin-module-resolver": "5.0.0",
54
+ "copyfiles": "^2.4.1",
55
+ "eslint": "^8.19.0",
56
+ "eslint-plugin-prettier": "4.2.1",
57
+ "eslint-plugin-react": "^7.30.1",
58
+ "eslint-plugin-react-native": "^4.0.0",
59
+ "flow-bin": "^0.163.0",
60
+ "jest": "^29.5.0",
61
+ "prettier": "2.8.8",
62
+ "react": "^18.3.1",
63
+ "react-native": "^0.77.1",
64
+ "react-native-windows": "^0.76.2",
65
+ "react-test-renderer": "^18.3.1",
66
+ "typescript": "^5.0.4"
67
+ },
68
+ "repository": {
69
+ "type": "git",
70
+ "url": "https://github.com/react-native-oh-library/react-native-slider.git"
71
+ },
72
+ "jest": {
73
+ "preset": "react-native",
74
+ "verbose": true,
75
+ "modulePathIgnorePatterns": [
76
+ "/e2e/"
77
+ ]
78
+ },
79
+ "prettier": {
80
+ "singleQuote": true,
81
+ "trailingComma": "all",
82
+ "bracketSpacing": false,
83
+ "jsxBracketSameLine": true
84
+ },
85
+ "codegenConfig": {
86
+ "name": "RNCSlider",
87
+ "type": "components",
88
+ "jsSrcsDir": "src",
89
+ "android": {
90
+ "javaPackageName": "com.reactnativecommunity.slider"
91
+ },
92
+ "ios": {
93
+ "componentProvider": {
94
+ "RNCSlider": "RNCSliderComponentView"
95
+ }
96
+ }
97
+ }
98
+ }
@@ -0,0 +1,47 @@
1
+ import type {ColorValue, HostComponent, ViewProps} from 'react-native';
2
+ import codegenNativeComponent from 'react-native/Libraries/Utilities/codegenNativeComponent';
3
+ //@ts-ignore
4
+ import type {ImageSource} from 'react-native/Libraries/Image/ImageSource';
5
+ import type {
6
+ Float,
7
+ WithDefault,
8
+ DirectEventHandler,
9
+ BubblingEventHandler,
10
+ Double,
11
+ } from 'react-native/Libraries/Types/CodegenTypes';
12
+
13
+ type Event = Readonly<{
14
+ value: Float;
15
+ fromUser?: boolean;
16
+ }>;
17
+
18
+ export interface NativeProps extends ViewProps {
19
+ accessibilityUnits?: string;
20
+ accessibilityIncrements?: ReadonlyArray<string>;
21
+ disabled?: WithDefault<boolean, false>;
22
+ inverted?: WithDefault<boolean, false>;
23
+ vertical?: WithDefault<boolean, false>;
24
+ tapToSeek?: WithDefault<boolean, false>;
25
+ maximumTrackImage?: ImageSource;
26
+ maximumTrackTintColor?: ColorValue;
27
+ maximumValue?: Double;
28
+ minimumTrackImage?: ImageSource;
29
+ minimumTrackTintColor?: ColorValue;
30
+ minimumValue?: Double;
31
+ onChange?: BubblingEventHandler<Event>;
32
+ onRNCSliderSlidingStart?: DirectEventHandler<Event>;
33
+ onRNCSliderSlidingComplete?: DirectEventHandler<Event>;
34
+ onRNCSliderValueChange?: BubblingEventHandler<Event>;
35
+ step?: Double;
36
+ testID?: string;
37
+ thumbImage?: ImageSource;
38
+ thumbTintColor?: ColorValue;
39
+ trackImage?: ImageSource;
40
+ value?: Float;
41
+ lowerLimit?: Float;
42
+ upperLimit?: Float;
43
+ }
44
+
45
+ export default codegenNativeComponent<NativeProps>('RNCSlider', {
46
+ interfaceOnly: true,
47
+ }) as HostComponent<NativeProps>;
package/src/Slider.tsx ADDED
@@ -0,0 +1,350 @@
1
+ import React, {useEffect, useState} from 'react';
2
+ import {
3
+ Image,
4
+ Platform,
5
+ AccessibilityActionEvent,
6
+ ViewProps,
7
+ ViewStyle,
8
+ ColorValue,
9
+ NativeSyntheticEvent,
10
+ StyleProp,
11
+ View,
12
+ } from 'react-native';
13
+ import RCTSliderNativeComponent from './index';
14
+ //@ts-ignore
15
+ import type {ImageSource} from 'react-native/Libraries/Image/ImageSource';
16
+
17
+ import type {FC, Ref} from 'react';
18
+ import {MarkerProps} from './components/TrackMark';
19
+ import {StepsIndicator} from './components/StepsIndicator';
20
+ import {styles} from './utils/styles';
21
+ import {constants} from './utils/constants';
22
+
23
+ type Event = NativeSyntheticEvent<
24
+ Readonly<{
25
+ value: number;
26
+ /**
27
+ * Android Only.
28
+ */
29
+ fromUser?: boolean;
30
+ }>
31
+ >;
32
+
33
+ type WindowsProps = Readonly<{
34
+ /**
35
+ * If true the slider will be inverted.
36
+ * Default value is false.
37
+ */
38
+ vertical?: boolean;
39
+ }>;
40
+
41
+ type IOSProps = Readonly<{
42
+ /**
43
+ * Assigns a single image for the track. Only static images are supported.
44
+ * The center pixel of the image will be stretched to fill the track.
45
+ */
46
+ trackImage?: ImageSource;
47
+
48
+ /**
49
+ * Assigns a minimum track image. Only static images are supported. The
50
+ * rightmost pixel of the image will be stretched to fill the track.
51
+ */
52
+ minimumTrackImage?: ImageSource;
53
+
54
+ /**
55
+ * Assigns a maximum track image. Only static images are supported. The
56
+ * leftmost pixel of the image will be stretched to fill the track.
57
+ */
58
+ maximumTrackImage?: ImageSource;
59
+
60
+ /**
61
+ * Permits tapping on the slider track to set the thumb position.
62
+ * Defaults to false on iOS. No effect on Android or Windows.
63
+ */
64
+ tapToSeek?: boolean;
65
+ }>;
66
+
67
+ type Props = ViewProps &
68
+ IOSProps &
69
+ WindowsProps &
70
+ Readonly<{
71
+ /**
72
+ * Used to style and layout the `Slider`. See `StyleSheet.js` and
73
+ * `DeprecatedViewStylePropTypes.js` for more info.
74
+ */
75
+ style?: StyleProp<ViewStyle>;
76
+
77
+ /**
78
+ * Write-only property representing the value of the slider.
79
+ * Can be used to programmatically control the position of the thumb.
80
+ * Entered once at the beginning still acts as an initial value.
81
+ * The value should be between minimumValue and maximumValue,
82
+ * which default to 0 and 1 respectively.
83
+ * Default value is 0.
84
+ *
85
+ * This is not a controlled component, you don't need to update the
86
+ * value during dragging.
87
+ */
88
+ value?: number;
89
+
90
+ /**
91
+ * Step value of the slider. The value should be
92
+ * between 0 and (maximumValue - minimumValue).
93
+ * Default value is 0.
94
+ */
95
+ step?: number;
96
+
97
+ /**
98
+ * Initial minimum value of the slider. Default value is 0.
99
+ */
100
+ minimumValue?: number;
101
+
102
+ /**
103
+ * Initial maximum value of the slider. Default value is 1.
104
+ */
105
+ maximumValue?: number;
106
+
107
+ /**
108
+ * The lower limit value of the slider. The user won't be able to slide below this limit.
109
+ */
110
+ lowerLimit?: number;
111
+
112
+ /**
113
+ * The upper limit value of the slider. The user won't be able to slide above this limit.
114
+ */
115
+ upperLimit?: number;
116
+
117
+ /**
118
+ * The color used for the track to the left of the button.
119
+ * Overrides the default blue gradient image on iOS.
120
+ */
121
+ minimumTrackTintColor?: ColorValue;
122
+
123
+ /**
124
+ * The color used for the track to the right of the button.
125
+ * Overrides the default blue gradient image on iOS.
126
+ */
127
+ maximumTrackTintColor?: ColorValue;
128
+ /**
129
+ * The color used to tint the default thumb images on iOS, or the
130
+ * color of the foreground switch grip on Android.
131
+ */
132
+ thumbTintColor?: ColorValue;
133
+
134
+ /**
135
+ * If true the user won't be able to move the slider.
136
+ * Default value is false.
137
+ */
138
+ disabled?: boolean;
139
+
140
+ /**
141
+ * Callback continuously called while the user is dragging the slider.
142
+ */
143
+ onValueChange?: (_value: number) => void;
144
+
145
+ /**
146
+ * Callback that is called when the user touches the slider,
147
+ * regardless if the value has changed. The current value is passed
148
+ * as an argument to the callback handler.
149
+ */
150
+ onSlidingStart?: (_value: number) => void;
151
+
152
+ /**
153
+ * Callback that is called when the user releases the slider,
154
+ * regardless if the value has changed. The current value is passed
155
+ * as an argument to the callback handler.
156
+ */
157
+ onSlidingComplete?: (_value: number) => void;
158
+
159
+ /**
160
+ * Used to locate this view in UI automation tests.
161
+ */
162
+ testID?: string;
163
+
164
+ /**
165
+ * Sets an image for the thumb. Only static images are supported.
166
+ */
167
+ thumbImage?: ImageSource;
168
+
169
+ /**
170
+ * If true the slider will be inverted.
171
+ * Default value is false.
172
+ */
173
+ inverted?: boolean;
174
+
175
+ /**
176
+ * Component to be rendered for each step indicator.
177
+ */
178
+ StepMarker?: FC<MarkerProps>;
179
+
180
+ /**
181
+ *
182
+ */
183
+ renderStepNumber?: boolean;
184
+
185
+ /**
186
+ * A string of one or more words to be announced by the screen reader.
187
+ * Otherwise, it will announce the value as a percentage.
188
+ * Requires passing a value to `accessibilityIncrements` to work correctly.
189
+ * Should be a plural word, as singular units will be handled.
190
+ */
191
+ accessibilityUnits?: string;
192
+
193
+ /**
194
+ * An array of values that represent the different increments displayed
195
+ * by the slider. All the values passed into this prop must be strings.
196
+ * Requires passing a value to `accessibilityUnits` to work correctly.
197
+ * The number of elements must be the same as `maximumValue`.
198
+ */
199
+ accessibilityIncrements?: Array<string>;
200
+ }>;
201
+
202
+ const SliderComponent = (
203
+ {
204
+ onValueChange,
205
+ onSlidingStart,
206
+ onSlidingComplete,
207
+ onAccessibilityAction,
208
+ value = constants.SLIDER_DEFAULT_INITIAL_VALUE,
209
+ minimumValue = 0,
210
+ maximumValue = 1,
211
+ step = 0,
212
+ inverted = false,
213
+ tapToSeek = false,
214
+ lowerLimit = Platform.select({
215
+ web: minimumValue,
216
+ default: constants.LIMIT_MIN_VALUE,
217
+ }),
218
+ upperLimit = Platform.select({
219
+ web: maximumValue,
220
+ default: constants.LIMIT_MAX_VALUE,
221
+ }),
222
+ ...props
223
+ }: Props,
224
+ forwardedRef?: Ref<typeof RCTSliderNativeComponent>,
225
+ ) => {
226
+ const [currentValue, setCurrentValue] = useState(
227
+ value ?? minimumValue ?? constants.SLIDER_DEFAULT_INITIAL_VALUE,
228
+ );
229
+ const [width, setWidth] = useState(0);
230
+
231
+ const stepResolution = step ? step : constants.DEFAULT_STEP_RESOLUTION;
232
+
233
+ const defaultStep = (maximumValue - minimumValue) / stepResolution;
234
+ const stepLength = step || defaultStep;
235
+
236
+ const options = Array.from(
237
+ {
238
+ length: (step ? defaultStep : stepResolution) + 1,
239
+ },
240
+ (_, index) => minimumValue + index * stepLength,
241
+ );
242
+
243
+ const defaultStyle =
244
+ Platform.OS === 'ios' || Platform.OS === 'harmony' ? styles.defaultSlideriOS : styles.defaultSlider;
245
+ const sliderStyle = {zIndex: 1, width: width};
246
+ const style = [defaultStyle, props.style];
247
+
248
+ const onValueChangeEvent = (event: Event) => {
249
+ onValueChange && onValueChange(event.nativeEvent.value);
250
+ setCurrentValue(event.nativeEvent.value);
251
+ };
252
+
253
+ const _disabled =
254
+ typeof props.disabled === 'boolean'
255
+ ? props.disabled
256
+ : props.accessibilityState?.disabled === true;
257
+
258
+ const _accessibilityState =
259
+ typeof props.disabled === 'boolean'
260
+ ? {...props.accessibilityState, disabled: props.disabled}
261
+ : props.accessibilityState;
262
+
263
+ const onSlidingStartEvent = onSlidingStart
264
+ ? (event: Event) => {
265
+ onSlidingStart(event.nativeEvent.value);
266
+ }
267
+ : null;
268
+ const onSlidingCompleteEvent = onSlidingComplete
269
+ ? (event: Event) => {
270
+ onSlidingComplete(event.nativeEvent.value);
271
+ }
272
+ : null;
273
+ const onAccessibilityActionEvent = onAccessibilityAction
274
+ ? (event: AccessibilityActionEvent) => {
275
+ onAccessibilityAction(event);
276
+ }
277
+ : null;
278
+
279
+ const passedValue = Number.isNaN(value) || !value ? undefined : value;
280
+
281
+ useEffect(() => {
282
+ if (lowerLimit >= upperLimit) {
283
+ console.warn(
284
+ 'Invalid configuration: lower limit is supposed to be smaller than upper limit',
285
+ );
286
+ }
287
+ }, [lowerLimit, upperLimit]);
288
+
289
+ return (
290
+ <View
291
+ onLayout={(event) => {
292
+ setWidth(event.nativeEvent.layout.width);
293
+ }}
294
+ style={[style, {justifyContent: 'center'}]}>
295
+ {props.StepMarker || !!props.renderStepNumber ? (
296
+ <StepsIndicator
297
+ options={options}
298
+ sliderWidth={width}
299
+ currentValue={currentValue}
300
+ renderStepNumber={props.renderStepNumber}
301
+ thumbImage={props.thumbImage}
302
+ StepMarker={props.StepMarker}
303
+ isLTR={inverted}
304
+ />
305
+ ) : null}
306
+ <RCTSliderNativeComponent
307
+ {...props}
308
+ minimumValue={minimumValue}
309
+ maximumValue={maximumValue}
310
+ step={step}
311
+ inverted={inverted}
312
+ tapToSeek={tapToSeek}
313
+ value={passedValue}
314
+ lowerLimit={lowerLimit}
315
+ upperLimit={upperLimit}
316
+ accessibilityState={_accessibilityState}
317
+ thumbImage={
318
+ Platform.OS === 'web'
319
+ ? props.thumbImage
320
+ : props.StepMarker
321
+ ? undefined
322
+ : Image.resolveAssetSource(props.thumbImage)
323
+ }
324
+ ref={forwardedRef}
325
+ style={[
326
+ sliderStyle,
327
+ defaultStyle,
328
+ {alignContent: 'center', alignItems: 'center'},
329
+ ]}
330
+ onChange={onValueChangeEvent}
331
+ onRNCSliderSlidingStart={onSlidingStartEvent}
332
+ onRNCSliderSlidingComplete={onSlidingCompleteEvent}
333
+ onRNCSliderValueChange={onValueChangeEvent}
334
+ disabled={_disabled}
335
+ onStartShouldSetResponder={() => true}
336
+ onResponderTerminationRequest={() => false}
337
+ onRNCSliderAccessibilityAction={onAccessibilityActionEvent}
338
+ thumbTintColor={
339
+ props.thumbImage && !!props.StepMarker
340
+ ? 'transparent'
341
+ : props.thumbTintColor
342
+ }
343
+ />
344
+ </View>
345
+ );
346
+ };
347
+
348
+ const SliderWithRef = React.forwardRef(SliderComponent);
349
+
350
+ export default SliderWithRef;
@@ -0,0 +1,17 @@
1
+ import React from 'react';
2
+ import {StyleProp, Text, TextStyle, View} from 'react-native';
3
+ import {styles} from '../utils/styles';
4
+
5
+ export const StepNumber = ({
6
+ i,
7
+ style,
8
+ }: {
9
+ i: number;
10
+ style: StyleProp<TextStyle>;
11
+ }) => {
12
+ return (
13
+ <View style={styles.stepNumber}>
14
+ <Text style={style}>{i}</Text>
15
+ </View>
16
+ );
17
+ };
@@ -0,0 +1,83 @@
1
+ import React, {FC, Fragment, useCallback, useMemo} from 'react';
2
+ import {View} from 'react-native';
3
+ import {StepNumber} from './StepNumber';
4
+ import {MarkerProps, SliderTrackMark} from './TrackMark';
5
+ //@ts-ignore
6
+ import type {ImageSource} from 'react-native/Libraries/Image/ImageSource';
7
+ import {styles} from '../utils/styles';
8
+ import {constants} from '../utils/constants';
9
+
10
+ export const StepsIndicator = ({
11
+ options,
12
+ sliderWidth,
13
+ currentValue,
14
+ StepMarker,
15
+ renderStepNumber,
16
+ thumbImage,
17
+ isLTR,
18
+ }: {
19
+ options: number[];
20
+ sliderWidth: number;
21
+ currentValue: number;
22
+ StepMarker?: FC<MarkerProps>;
23
+ renderStepNumber?: boolean;
24
+ thumbImage?: ImageSource;
25
+ isLTR?: boolean;
26
+ }) => {
27
+ const stepNumberFontStyle = useMemo(() => {
28
+ return {
29
+ fontSize:
30
+ options.length > 9
31
+ ? constants.STEP_NUMBER_TEXT_FONT_SMALL
32
+ : constants.STEP_NUMBER_TEXT_FONT_BIG,
33
+ };
34
+ }, [options.length]);
35
+ const values = isLTR ? options.reverse() : options;
36
+
37
+ const renderStepIndicator = useCallback(
38
+ (i: number, index: number) => {
39
+ return (
40
+ <Fragment key={index}>
41
+ <View style={styles.stepIndicatorElement} key={`${index}-View`}>
42
+ <SliderTrackMark
43
+ key={`${index}-SliderTrackMark`}
44
+ isTrue={currentValue === i}
45
+ index={i}
46
+ thumbImage={thumbImage}
47
+ StepMarker={StepMarker}
48
+ currentValue={currentValue}
49
+ min={options[0]}
50
+ max={options[options.length - 1]}
51
+ />
52
+ {renderStepNumber ? (
53
+ <StepNumber
54
+ i={i}
55
+ style={stepNumberFontStyle}
56
+ key={`${index}th-step`}
57
+ />
58
+ ) : null}
59
+ </View>
60
+ </Fragment>
61
+ );
62
+ },
63
+ [
64
+ currentValue,
65
+ StepMarker,
66
+ options,
67
+ thumbImage,
68
+ renderStepNumber,
69
+ stepNumberFontStyle,
70
+ ],
71
+ );
72
+
73
+ return (
74
+ <View
75
+ pointerEvents="none"
76
+ style={[
77
+ styles.stepsIndicator,
78
+ {marginHorizontal: sliderWidth * constants.MARGIN_HORIZONTAL_PADDING},
79
+ ]}>
80
+ {values.map((i, index) => renderStepIndicator(i, index))}
81
+ </View>
82
+ );
83
+ };
@@ -0,0 +1,50 @@
1
+ import React, {FC} from 'react';
2
+ import {Image, ImageURISource, View} from 'react-native';
3
+ import {styles} from '../utils/styles';
4
+
5
+ export type MarkerProps = {
6
+ stepMarked: boolean;
7
+ currentValue: number;
8
+ index: number;
9
+ min: number;
10
+ max: number;
11
+ };
12
+
13
+ export type TrackMarksProps = {
14
+ isTrue: boolean;
15
+ index: number;
16
+ thumbImage?: ImageURISource;
17
+ StepMarker?: FC<MarkerProps>;
18
+ currentValue: number;
19
+ min: number;
20
+ max: number;
21
+ };
22
+
23
+ export const SliderTrackMark = ({
24
+ isTrue,
25
+ index,
26
+ thumbImage,
27
+ StepMarker,
28
+ currentValue,
29
+ min,
30
+ max,
31
+ }: TrackMarksProps) => {
32
+ return (
33
+ <View style={styles.trackMarkContainer}>
34
+ {StepMarker ? (
35
+ <StepMarker
36
+ stepMarked={isTrue}
37
+ index={index}
38
+ currentValue={currentValue}
39
+ min={min}
40
+ max={max}
41
+ />
42
+ ) : null}
43
+ {thumbImage && isTrue ? (
44
+ <View style={styles.thumbImageContainer}>
45
+ <Image source={thumbImage} style={styles.thumbImage} />
46
+ </View>
47
+ ) : null}
48
+ </View>
49
+ );
50
+ };
package/src/index.ts ADDED
@@ -0,0 +1,3 @@
1
+ const RNCSlider = require('./RNCSliderNativeComponent').default;
2
+
3
+ export default RNCSlider;
@@ -0,0 +1,11 @@
1
+ import {Platform} from 'react-native';
2
+
3
+ export const constants = {
4
+ SLIDER_DEFAULT_INITIAL_VALUE: 0,
5
+ MARGIN_HORIZONTAL_PADDING: 0.05,
6
+ STEP_NUMBER_TEXT_FONT_SMALL: 8,
7
+ STEP_NUMBER_TEXT_FONT_BIG: 12,
8
+ LIMIT_MIN_VALUE: Number.MIN_SAFE_INTEGER,
9
+ LIMIT_MAX_VALUE: Number.MAX_SAFE_INTEGER,
10
+ DEFAULT_STEP_RESOLUTION: Platform.OS === 'android' ? 128 : 1000,
11
+ };