@momo-kits/slider 0.81.1-beta.6 → 0.81.1-rc.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/Label.tsx CHANGED
@@ -25,7 +25,7 @@ const Label: ForwardRefRenderFunction<LabelRef, ViewProps> = (props, ref) => {
25
25
 
26
26
  return (
27
27
  <View {...props} style={[styles.label, Shadow.Light]}>
28
- <Text typography={'label_s'}>{value}</Text>
28
+ <Text typography={'label_s_medium'}>{value}</Text>
29
29
  </View>
30
30
  );
31
31
  };
package/hooks.tsx CHANGED
@@ -5,7 +5,7 @@ import React, {
5
5
  useRef,
6
6
  useState,
7
7
  } from 'react';
8
- import {Animated, I18nManager, ViewStyle} from 'react-native';
8
+ import {Animated} from 'react-native';
9
9
  import {clamp} from './helpers';
10
10
  import styles from './styles';
11
11
  import FollowerContainer, {LabelRef} from './Label';
@@ -29,7 +29,7 @@ export const useLowHigh = (
29
29
  highProp: number | undefined,
30
30
  min: number,
31
31
  max: number,
32
- step: number,
32
+ step: number
33
33
  ) => {
34
34
  const validLowProp = lowProp === undefined ? min : clamp(lowProp, min, max);
35
35
  const validHighProp =
@@ -66,7 +66,7 @@ export const useLowHigh = (
66
66
  */
67
67
  export const useWidthLayout = (
68
68
  widthRef: MutableRefObject<number>,
69
- callback?: (width: number) => void,
69
+ callback?: (width: number) => void
70
70
  ) => {
71
71
  return useCallback(
72
72
  ({nativeEvent}) => {
@@ -81,7 +81,7 @@ export const useWidthLayout = (
81
81
  }
82
82
  }
83
83
  },
84
- [callback, widthRef],
84
+ [callback, widthRef]
85
85
  );
86
86
  };
87
87
 
@@ -108,7 +108,7 @@ export const useThumbFollower = (
108
108
  isPressed: boolean,
109
109
  allowOverflow: boolean,
110
110
  disabledLow: boolean,
111
- disabledHigh: boolean,
111
+ disabledHigh: boolean
112
112
  ) => {
113
113
  const xRef = useRef(new Animated.Value(0));
114
114
  const widthRef = useRef(0);
@@ -129,17 +129,17 @@ export const useThumbFollower = (
129
129
  const {current: containerWidth} = containerWidthRef;
130
130
  const position = thumbPositionInView - width / 2;
131
131
  xRef.current.setValue(
132
- allowOverflow ? position : clamp(position, 0, containerWidth - width),
132
+ allowOverflow ? position : clamp(position, 0, containerWidth - width)
133
133
  );
134
134
  contentContainerRef.current?.setValue(value);
135
135
  },
136
- [widthRef, containerWidthRef, allowOverflow, disabledLow, disabledHigh], // Include dependencies here.
136
+ [widthRef, containerWidthRef, allowOverflow, disabledLow, disabledHigh] // Include dependencies here.
137
137
  );
138
138
 
139
139
  const handleLayout = useWidthLayout(widthRef, () => {
140
140
  update(
141
141
  gestureStateRef.current.lastPosition,
142
- gestureStateRef.current.lastValue,
142
+ gestureStateRef.current.lastValue
143
143
  );
144
144
  });
145
145
 
@@ -170,7 +170,7 @@ export const useSelectedRail = (
170
170
  inPropsRef: MutableRefObject<InProps>,
171
171
  containerWidthRef: MutableRefObject<number>,
172
172
  thumbWidth: number,
173
- disableRange: boolean,
173
+ disableRange: boolean
174
174
  ) => {
175
175
  const {current: left} = useRef(new Animated.Value(0));
176
176
  const {current: right} = useRef(new Animated.Value(0));
@@ -182,7 +182,7 @@ export const useSelectedRail = (
182
182
  const rightValue = (max - high) / fullScale;
183
183
  left.setValue(disableRange ? 0 : leftValue);
184
184
  right.setValue(
185
- disableRange ? containerWidth - thumbWidth - leftValue : rightValue,
185
+ disableRange ? containerWidth - thumbWidth - leftValue : rightValue
186
186
  );
187
187
  }, [inPropsRef, containerWidthRef, disableRange, thumbWidth, left, right]);
188
188
  const styles = useMemo(
@@ -191,7 +191,7 @@ export const useSelectedRail = (
191
191
  left: left,
192
192
  right: right,
193
193
  }),
194
- [left, right],
194
+ [left, right]
195
195
  );
196
196
  return [styles, update];
197
197
  };
package/index.tsx CHANGED
@@ -115,324 +115,333 @@ export interface SliderProps extends ViewProps {
115
115
  onSliderTouchEnd?: (low: number, high: number) => void;
116
116
  }
117
117
 
118
- const Slider: React.FC<SliderProps> = ({
119
- min,
120
- max,
121
- minRange = 0,
122
- step,
123
- low: lowProp,
124
- high: highProp,
125
- floatingLabel = false,
126
- allowLabelOverflow = false,
127
- disableRange = false,
128
- disabledHigh = false,
129
- disabledLow = false,
130
- onValueChanged,
131
- onSliderTouchStart,
132
- onSliderTouchEnd,
133
- ...restProps
134
- }) => {
135
- const {theme} = useContext(ApplicationContext);
136
-
137
- const {inPropsRef, inPropsRefPrev, setLow, setHigh} = useLowHigh(
138
- lowProp,
139
- disableRange ? max : highProp,
118
+ const Slider: React.FC<SliderProps> = memo(
119
+ ({
140
120
  min,
141
121
  max,
122
+ minRange = 0,
142
123
  step,
143
- );
144
- const lowThumbXRef = useRef(new Animated.Value(0));
145
- const highThumbXRef = useRef(new Animated.Value(0));
146
- const pointerX = useRef(new Animated.Value(0)).current;
147
- const {current: lowThumbX} = lowThumbXRef;
148
- const {current: highThumbX} = highThumbXRef;
149
-
150
- const gestureStateRef = useRef({isLow: true, lastValue: 0, lastPosition: 0});
151
- const [isPressed, setPressed] = useState(false);
152
-
153
- const containerWidthRef = useRef(0);
154
- const [thumbWidth, setThumbWidth] = useState(0);
155
-
156
- const [selectedRailStyle, updateSelectedRail] = useSelectedRail(
157
- inPropsRef,
158
- containerWidthRef,
159
- thumbWidth,
160
- disableRange,
161
- );
162
-
163
- const updateThumbs = useCallback(() => {
164
- const {current: containerWidth} = containerWidthRef;
165
- if (!thumbWidth || !containerWidth) {
166
- return;
167
- }
168
- const {low, high} = inPropsRef.current;
169
- if (!disableRange) {
170
- const {current: highThumbX} = highThumbXRef;
171
- const highPosition =
172
- ((high - min) / (max - min)) * (containerWidth - thumbWidth);
173
- highThumbX.setValue(highPosition);
174
- }
175
- const {current: lowThumbX} = lowThumbXRef;
176
- const lowPosition =
177
- ((low - min) / (max - min)) * (containerWidth - thumbWidth);
178
- lowThumbX.setValue(lowPosition);
179
- typeof updateSelectedRail === 'function' && updateSelectedRail();
180
- onValueChanged?.(low, high, false);
181
- }, [
182
- disableRange,
183
- inPropsRef,
184
- max,
185
- min,
124
+ low: lowProp,
125
+ high: highProp,
126
+ floatingLabel = false,
127
+ allowLabelOverflow = false,
128
+ disableRange = false,
129
+ disabledHigh = false,
130
+ disabledLow = false,
186
131
  onValueChanged,
187
- thumbWidth,
188
- updateSelectedRail,
189
- ]);
190
-
191
- useEffect(() => {
192
- const {lowPrev, highPrev} = inPropsRefPrev;
193
- if (
194
- (lowProp !== undefined && lowProp !== lowPrev) ||
195
- (highProp !== undefined && highProp !== highPrev)
196
- ) {
197
- updateThumbs();
198
- }
199
- }, [highProp, inPropsRefPrev.lowPrev, inPropsRefPrev.highPrev, lowProp]);
200
-
201
- useEffect(() => {
202
- updateThumbs();
203
- }, [updateThumbs]);
204
-
205
- const handleContainerLayout = useWidthLayout(containerWidthRef, updateThumbs);
206
- const handleThumbLayout = useCallback(
207
- ({nativeEvent}) => {
208
- const {
209
- layout: {width},
210
- } = nativeEvent;
211
- if (thumbWidth !== width) {
212
- setThumbWidth(width);
213
- }
214
- },
215
- [thumbWidth],
216
- );
217
-
218
- const lowStyles = useMemo(() => {
219
- return {transform: [{translateX: lowThumbX}]};
220
- }, [lowThumbX]);
221
-
222
- const highStyles = useMemo(() => {
223
- return disableRange
224
- ? null
225
- : [styles.highThumbContainer, {transform: [{translateX: highThumbX}]}];
226
- }, [disableRange, highThumbX]);
227
-
228
- const railContainerStyles = useMemo(() => {
229
- return [styles.railsContainer, {marginHorizontal: thumbWidth / 2}];
230
- }, [thumbWidth]);
231
-
232
- const [labelView, labelUpdate] = useThumbFollower(
233
- containerWidthRef,
234
- gestureStateRef,
235
- isPressed,
236
- allowLabelOverflow,
237
- disabledLow,
238
- disabledHigh,
239
- );
240
-
241
- const renderThumb = (name: string) => {
242
- const isDisabled =
243
- (name === 'low' && disabledLow) || (name === 'high' && disabledHigh);
244
-
245
- const thumbColor = isDisabled
246
- ? theme.colors.text.disable
247
- : theme.colors.primary;
248
-
249
- return (
250
- <View
251
- style={[
252
- Shadow.Light,
253
- {
254
- width: 20,
255
- height: 20,
256
- borderRadius: Radius.M,
257
- borderWidth: 4,
258
- borderColor: theme.colors.background.surface,
259
- backgroundColor: thumbColor,
260
- },
261
- ]}
262
- />
132
+ onSliderTouchStart,
133
+ onSliderTouchEnd,
134
+ ...restProps
135
+ }) => {
136
+ const {theme} = useContext(ApplicationContext);
137
+
138
+ const {inPropsRef, inPropsRefPrev, setLow, setHigh} = useLowHigh(
139
+ lowProp,
140
+ disableRange ? max : highProp,
141
+ min,
142
+ max,
143
+ step
263
144
  );
264
- };
265
-
266
- const lowThumb = renderThumb('low');
267
- const highThumb = renderThumb('high');
268
-
269
- const labelContainerProps = useLabelContainerProps(floatingLabel);
270
-
271
- const {panHandlers} = useMemo(
272
- () =>
273
- PanResponder.create({
274
- onStartShouldSetPanResponderCapture: falseFunc,
275
- onMoveShouldSetPanResponderCapture: falseFunc,
276
- onPanResponderTerminationRequest: falseFunc,
277
- onPanResponderTerminate: trueFunc,
278
- onShouldBlockNativeResponder: trueFunc,
279
-
280
- onMoveShouldSetPanResponder: (
281
- evt: GestureResponderEvent,
282
- gestureState: PanResponderGestureState,
283
- ) => Math.abs(gestureState.dx) > 2 * Math.abs(gestureState.dy),
284
-
285
- onPanResponderGrant: ({nativeEvent}, gestureState) => {
286
- const {numberActiveTouches} = gestureState;
287
- if (numberActiveTouches > 1) {
288
- return;
289
- }
290
- setPressed(true);
291
- const {current: lowThumbX} = lowThumbXRef;
292
- const {current: highThumbX} = highThumbXRef;
293
- const {locationX: downX, pageX} = nativeEvent;
294
- const containerX = pageX - downX;
295
-
296
- const {low, high, min, max} = inPropsRef.current;
297
- onSliderTouchStart?.(low, high);
298
- const containerWidth = containerWidthRef.current;
299
-
300
- const lowPosition =
301
- thumbWidth / 2 +
302
- ((low - min) / (max - min)) * (containerWidth - thumbWidth);
303
- const highPosition =
304
- thumbWidth / 2 +
305
- ((high - min) / (max - min)) * (containerWidth - thumbWidth);
306
-
307
- const isLow =
308
- disableRange || isLowCloser(downX, lowPosition, highPosition);
309
- gestureStateRef.current.isLow = isLow;
310
-
311
- if ((isLow && disabledLow) || (!isLow && disabledHigh)) {
312
- return;
313
- }
314
-
315
- const handlePositionChange = (positionInView: number) => {
316
- const {low, high, min, max, step} = inPropsRef.current;
317
- const minValue = isLow ? min : low + minRange;
318
- const maxValue = isLow ? high - minRange : max;
319
- const value = clamp(
320
- getValueForPosition(
321
- positionInView,
322
- containerWidth,
323
- thumbWidth,
324
- min,
325
- max,
326
- step,
327
- ),
328
- minValue,
329
- maxValue,
330
- );
331
- if (gestureStateRef.current.lastValue === value) {
332
- return;
333
- }
334
- const availableSpace = containerWidth - thumbWidth;
335
- const absolutePosition =
336
- ((value - min) / (max - min)) * availableSpace;
337
- gestureStateRef.current.lastValue = value;
338
- gestureStateRef.current.lastPosition =
339
- absolutePosition + thumbWidth / 2;
340
- (isLow ? lowThumbX : highThumbX).setValue(absolutePosition);
341
- onValueChanged?.(isLow ? value : low, isLow ? high : value, true);
342
- (isLow ? setLow : setHigh)(value);
343
- labelUpdate &&
344
- typeof labelUpdate === 'function' &&
345
- labelUpdate(gestureStateRef.current.lastPosition, value);
346
-
347
- typeof updateSelectedRail === 'function' && updateSelectedRail();
348
- };
349
- handlePositionChange(downX);
350
- pointerX.removeAllListeners();
351
- pointerX.addListener(({value: pointerPosition}) => {
352
- const positionInView = pointerPosition - containerX;
353
- handlePositionChange(positionInView);
354
- });
355
- },
356
-
357
- onPanResponderMove: (evt, gestureState) => {
358
- if (gestureStateRef.current.isLow ? disabledLow : disabledHigh) {
359
- return;
360
- }
361
-
362
- Animated.event([null, {moveX: pointerX}], {
363
- useNativeDriver: false,
364
- })(evt, gestureState);
365
- },
366
-
367
- onPanResponderRelease: () => {
368
- setPressed(false);
369
- const {low, high} = inPropsRef.current;
370
- if (
371
- (gestureStateRef.current.isLow && disabledLow) ||
372
- (!gestureStateRef.current.isLow && disabledHigh)
373
- ) {
374
- return;
375
- }
376
- onSliderTouchEnd?.(low, high);
377
- },
378
- }),
379
- [
380
- pointerX,
145
+ const lowThumbXRef = useRef(new Animated.Value(0));
146
+ const highThumbXRef = useRef(new Animated.Value(0));
147
+ const pointerX = useRef(new Animated.Value(0)).current;
148
+ const {current: lowThumbX} = lowThumbXRef;
149
+ const {current: highThumbX} = highThumbXRef;
150
+
151
+ const gestureStateRef = useRef({
152
+ isLow: true,
153
+ lastValue: 0,
154
+ lastPosition: 0,
155
+ });
156
+ const [isPressed, setPressed] = useState(false);
157
+
158
+ const containerWidthRef = useRef(0);
159
+ const [thumbWidth, setThumbWidth] = useState(0);
160
+
161
+ const [selectedRailStyle, updateSelectedRail] = useSelectedRail(
381
162
  inPropsRef,
163
+ containerWidthRef,
382
164
  thumbWidth,
165
+ disableRange
166
+ );
167
+
168
+ const updateThumbs = useCallback(() => {
169
+ const {current: containerWidth} = containerWidthRef;
170
+ if (!thumbWidth || !containerWidth) {
171
+ return;
172
+ }
173
+ const {low, high} = inPropsRef.current;
174
+ if (!disableRange) {
175
+ const {current: highThumbX} = highThumbXRef;
176
+ const highPosition =
177
+ ((high - min) / (max - min)) * (containerWidth - thumbWidth);
178
+ highThumbX.setValue(highPosition);
179
+ }
180
+ const {current: lowThumbX} = lowThumbXRef;
181
+ const lowPosition =
182
+ ((low - min) / (max - min)) * (containerWidth - thumbWidth);
183
+ lowThumbX.setValue(lowPosition);
184
+ typeof updateSelectedRail === 'function' && updateSelectedRail();
185
+ onValueChanged?.(low, high, false);
186
+ }, [
383
187
  disableRange,
188
+ inPropsRef,
189
+ max,
190
+ min,
384
191
  onValueChanged,
385
- disabledHigh,
386
- disabledLow,
387
- setLow,
388
- setHigh,
389
- labelUpdate,
192
+ thumbWidth,
390
193
  updateSelectedRail,
391
- ],
392
- );
194
+ ]);
195
+
196
+ useEffect(() => {
197
+ const {lowPrev, highPrev} = inPropsRefPrev;
198
+ if (
199
+ (lowProp !== undefined && lowProp !== lowPrev) ||
200
+ (highProp !== undefined && highProp !== highPrev)
201
+ ) {
202
+ updateThumbs();
203
+ }
204
+ }, [highProp, inPropsRefPrev.lowPrev, inPropsRefPrev.highPrev, lowProp]);
393
205
 
394
- const renderTrack = (color: string) => {
395
- return (
396
- <View
397
- style={{
398
- width: '100%',
399
- height: 4,
400
- borderRadius: Radius.L,
401
- backgroundColor: color,
402
- }}
403
- />
206
+ useEffect(() => {
207
+ updateThumbs();
208
+ }, [updateThumbs]);
209
+
210
+ const handleContainerLayout = useWidthLayout(
211
+ containerWidthRef,
212
+ updateThumbs
404
213
  );
405
- };
406
-
407
- const trackColor =
408
- disabledHigh && disabledLow
409
- ? theme.colors.text.disable
410
- : theme.colors.primary;
411
-
412
- return (
413
- <View {...restProps}>
414
- <View {...labelContainerProps}>{labelView}</View>
415
- <View onLayout={handleContainerLayout} style={styles.controlsContainer}>
416
- <View style={railContainerStyles}>
417
- {renderTrack(theme.colors.background.default)}
418
- <Animated.View style={selectedRailStyle as ViewStyle}>
419
- {renderTrack(trackColor)}
420
- </Animated.View>
421
- </View>
422
- <Animated.View style={lowStyles} onLayout={handleThumbLayout}>
423
- {lowThumb}
424
- </Animated.View>
425
- {!disableRange && (
426
- <Animated.View style={highStyles}>{highThumb}</Animated.View>
427
- )}
214
+ const handleThumbLayout = useCallback(
215
+ ({nativeEvent}) => {
216
+ const {
217
+ layout: {width},
218
+ } = nativeEvent;
219
+ if (thumbWidth !== width) {
220
+ setThumbWidth(width);
221
+ }
222
+ },
223
+ [thumbWidth]
224
+ );
225
+
226
+ const lowStyles = useMemo(() => {
227
+ return {transform: [{translateX: lowThumbX}]};
228
+ }, [lowThumbX]);
229
+
230
+ const highStyles = useMemo(() => {
231
+ return disableRange
232
+ ? null
233
+ : [styles.highThumbContainer, {transform: [{translateX: highThumbX}]}];
234
+ }, [disableRange, highThumbX]);
235
+
236
+ const railContainerStyles = useMemo(() => {
237
+ return [styles.railsContainer, {marginHorizontal: thumbWidth / 2}];
238
+ }, [thumbWidth]);
239
+
240
+ const [labelView, labelUpdate] = useThumbFollower(
241
+ containerWidthRef,
242
+ gestureStateRef,
243
+ isPressed,
244
+ allowLabelOverflow,
245
+ disabledLow,
246
+ disabledHigh
247
+ );
248
+
249
+ const renderThumb = (name: string) => {
250
+ const isDisabled =
251
+ (name === 'low' && disabledLow) || (name === 'high' && disabledHigh);
252
+
253
+ const thumbColor = isDisabled
254
+ ? theme.colors.text.disable
255
+ : theme.colors.primary;
256
+
257
+ return (
428
258
  <View
429
- {...panHandlers}
430
- style={styles.touchableArea}
431
- collapsable={false}
259
+ style={[
260
+ Shadow.Light,
261
+ {
262
+ width: 20,
263
+ height: 20,
264
+ borderRadius: Radius.M,
265
+ borderWidth: 4,
266
+ borderColor: theme.colors.background.surface,
267
+ backgroundColor: thumbColor,
268
+ },
269
+ ]}
432
270
  />
271
+ );
272
+ };
273
+
274
+ const lowThumb = renderThumb('low');
275
+ const highThumb = renderThumb('high');
276
+
277
+ const labelContainerProps = useLabelContainerProps(floatingLabel);
278
+
279
+ const {panHandlers} = useMemo(
280
+ () =>
281
+ PanResponder.create({
282
+ onStartShouldSetPanResponderCapture: falseFunc,
283
+ onMoveShouldSetPanResponderCapture: falseFunc,
284
+ onPanResponderTerminationRequest: falseFunc,
285
+ onPanResponderTerminate: trueFunc,
286
+ onShouldBlockNativeResponder: trueFunc,
287
+
288
+ onMoveShouldSetPanResponder: (
289
+ evt: GestureResponderEvent,
290
+ gestureState: PanResponderGestureState
291
+ ) => Math.abs(gestureState.dx) > 2 * Math.abs(gestureState.dy),
292
+
293
+ onPanResponderGrant: ({nativeEvent}, gestureState) => {
294
+ const {numberActiveTouches} = gestureState;
295
+ if (numberActiveTouches > 1) {
296
+ return;
297
+ }
298
+ setPressed(true);
299
+ const {current: lowThumbX} = lowThumbXRef;
300
+ const {current: highThumbX} = highThumbXRef;
301
+ const {locationX: downX, pageX} = nativeEvent;
302
+ const containerX = pageX - downX;
303
+
304
+ const {low, high, min, max} = inPropsRef.current;
305
+ onSliderTouchStart?.(low, high);
306
+ const containerWidth = containerWidthRef.current;
307
+
308
+ const lowPosition =
309
+ thumbWidth / 2 +
310
+ ((low - min) / (max - min)) * (containerWidth - thumbWidth);
311
+ const highPosition =
312
+ thumbWidth / 2 +
313
+ ((high - min) / (max - min)) * (containerWidth - thumbWidth);
314
+
315
+ const isLow =
316
+ disableRange || isLowCloser(downX, lowPosition, highPosition);
317
+ gestureStateRef.current.isLow = isLow;
318
+
319
+ if ((isLow && disabledLow) || (!isLow && disabledHigh)) {
320
+ return;
321
+ }
322
+
323
+ const handlePositionChange = (positionInView: number) => {
324
+ const {low, high, min, max, step} = inPropsRef.current;
325
+ const minValue = isLow ? min : low + minRange;
326
+ const maxValue = isLow ? high - minRange : max;
327
+ const value = clamp(
328
+ getValueForPosition(
329
+ positionInView,
330
+ containerWidth,
331
+ thumbWidth,
332
+ min,
333
+ max,
334
+ step
335
+ ),
336
+ minValue,
337
+ maxValue
338
+ );
339
+ if (gestureStateRef.current.lastValue === value) {
340
+ return;
341
+ }
342
+ const availableSpace = containerWidth - thumbWidth;
343
+ const absolutePosition =
344
+ ((value - min) / (max - min)) * availableSpace;
345
+ gestureStateRef.current.lastValue = value;
346
+ gestureStateRef.current.lastPosition =
347
+ absolutePosition + thumbWidth / 2;
348
+ (isLow ? lowThumbX : highThumbX).setValue(absolutePosition);
349
+ onValueChanged?.(isLow ? value : low, isLow ? high : value, true);
350
+ (isLow ? setLow : setHigh)(value);
351
+ labelUpdate &&
352
+ typeof labelUpdate === 'function' &&
353
+ labelUpdate(gestureStateRef.current.lastPosition, value);
354
+
355
+ typeof updateSelectedRail === 'function' && updateSelectedRail();
356
+ };
357
+ handlePositionChange(downX);
358
+ pointerX.removeAllListeners();
359
+ pointerX.addListener(({value: pointerPosition}) => {
360
+ const positionInView = pointerPosition - containerX;
361
+ handlePositionChange(positionInView);
362
+ });
363
+ },
364
+
365
+ onPanResponderMove: (evt, gestureState) => {
366
+ if (gestureStateRef.current.isLow ? disabledLow : disabledHigh) {
367
+ return;
368
+ }
369
+
370
+ Animated.event([null, {moveX: pointerX}], {
371
+ useNativeDriver: false,
372
+ })(evt, gestureState);
373
+ },
374
+
375
+ onPanResponderRelease: () => {
376
+ setPressed(false);
377
+ const {low, high} = inPropsRef.current;
378
+ if (
379
+ (gestureStateRef.current.isLow && disabledLow) ||
380
+ (!gestureStateRef.current.isLow && disabledHigh)
381
+ ) {
382
+ return;
383
+ }
384
+ onSliderTouchEnd?.(low, high);
385
+ },
386
+ }),
387
+ [
388
+ pointerX,
389
+ inPropsRef,
390
+ thumbWidth,
391
+ disableRange,
392
+ onValueChanged,
393
+ disabledHigh,
394
+ disabledLow,
395
+ setLow,
396
+ setHigh,
397
+ labelUpdate,
398
+ updateSelectedRail,
399
+ ]
400
+ );
401
+
402
+ const renderTrack = (color: string) => {
403
+ return (
404
+ <View
405
+ style={{
406
+ width: '100%',
407
+ height: 4,
408
+ borderRadius: Radius.L,
409
+ backgroundColor: color,
410
+ }}
411
+ />
412
+ );
413
+ };
414
+
415
+ const trackColor =
416
+ disabledHigh && disabledLow
417
+ ? theme.colors.text.disable
418
+ : theme.colors.primary;
419
+
420
+ return (
421
+ <View {...restProps}>
422
+ <View {...labelContainerProps}>{labelView}</View>
423
+ <View onLayout={handleContainerLayout} style={styles.controlsContainer}>
424
+ <View style={railContainerStyles}>
425
+ {renderTrack(theme.colors.background.default)}
426
+ <Animated.View style={selectedRailStyle as ViewStyle}>
427
+ {renderTrack(trackColor)}
428
+ </Animated.View>
429
+ </View>
430
+ <Animated.View style={lowStyles} onLayout={handleThumbLayout}>
431
+ {lowThumb}
432
+ </Animated.View>
433
+ {!disableRange && (
434
+ <Animated.View style={highStyles}>{highThumb}</Animated.View>
435
+ )}
436
+ <View
437
+ {...panHandlers}
438
+ style={styles.touchableArea}
439
+ collapsable={false}
440
+ />
441
+ </View>
433
442
  </View>
434
- </View>
435
- );
436
- };
443
+ );
444
+ }
445
+ );
437
446
 
438
- export default memo(Slider);
447
+ export {Slider};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@momo-kits/slider",
3
- "version": "0.81.1-beta.6",
3
+ "version": "0.81.1-rc.0",
4
4
  "private": false,
5
5
  "main": "index.tsx",
6
6
  "dependencies": {},
@@ -14,4 +14,4 @@
14
14
  "@momo-platform/versions": "4.1.11"
15
15
  },
16
16
  "license": "MoMo"
17
- }
17
+ }
package/publish.sh CHANGED
@@ -1,29 +1,27 @@
1
1
  #!/bin/bash
2
+
3
+ # Prepare dist files
2
4
  rm -rf dist
3
5
  mkdir dist
4
-
5
- cp . ./dist
6
-
7
- # GET VERSION from mck_package.json
8
- VERSIONSTRING=( v$(jq .version package.json) )
9
- VERSION=(${VERSIONSTRING//[\"]/})
10
- echo VERSION: $VERSION
11
-
12
- rsync -r --verbose --exclude '*.mdx' --exclude '*Demo.js' --exclude 'props-type.js' --exclude 'prop-types.js' ./* dist
13
-
14
- # #babel component to dist
15
- #babel ./dist -d dist --copy-files
16
-
17
- #copy option
18
- #cp -r ./src/ dist
19
-
20
-
21
- #npm login
22
- #publish dist to npm
6
+ rsync -r --exclude=/dist ./* dist
23
7
  cd dist
24
- npm publish --tag beta --access=public
8
+
9
+ if [ "$1" == "stable" ]; then
10
+ npm version $(npm view @momo-kits/foundation@stable version)
11
+ npm version patch
12
+ npm publish --tag stable --access=public
13
+ elif [ "$1" == "latest" ]; then
14
+ npm version $(npm view @momo-kits/foundation@latest version)
15
+ npm publish --tag latest --access=public
16
+ else
17
+ npm version $(npm view @momo-kits/slider@beta version)
18
+ npm version prerelease --preid=beta
19
+ npm publish --tag beta --access=public
20
+ fi
21
+
22
+ PACKAGE_NAME=$(npm pkg get name)
23
+ NEW_PACKAGE_VERSION=$(npm pkg get version)
24
+
25
+ # Clean up
25
26
  cd ..
26
27
  rm -rf dist
27
-
28
-
29
- ##curl -X POST -H 'Content-Type: application/json' 'https://chat.googleapis.com/v1/spaces/AAAAbP8987c/messages?key=AIzaSyDdI0hCZtE6vySjMm-WEfRq3CPzqKqqsHI&token=UGSFRvk_oYb9uGsAgs31bVvMm6jDkmD8zihGm3eyaQA%3D&threadKey=JoaXTEYaNNkl' -d '{"text": "@momo-kits/slider new version release: '*"$VERSION"*' https://www.npmjs.com/package/@momo-kits/slider"}'