@momo-kits/slider 0.89.5 → 0.89.6-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.
- package/hooks.tsx +11 -11
- package/index.tsx +240 -231
- package/package.json +2 -2
- package/publish.sh +21 -23
package/hooks.tsx
CHANGED
|
@@ -5,7 +5,7 @@ import React, {
|
|
|
5
5
|
useRef,
|
|
6
6
|
useState,
|
|
7
7
|
} from 'react';
|
|
8
|
-
import {Animated
|
|
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]
|
|
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,95 +115,103 @@ export interface SliderProps extends ViewProps {
|
|
|
115
115
|
onSliderTouchEnd?: (low: number, high: number) => void;
|
|
116
116
|
}
|
|
117
117
|
|
|
118
|
-
const Slider: React.FC<SliderProps> = memo(
|
|
119
|
-
|
|
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
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
124
|
+
low: lowProp,
|
|
125
|
+
high: highProp,
|
|
126
|
+
floatingLabel = false,
|
|
127
|
+
allowLabelOverflow = false,
|
|
128
|
+
disableRange = false,
|
|
129
|
+
disabledHigh = false,
|
|
130
|
+
disabledLow = false,
|
|
131
|
+
onValueChanged,
|
|
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
|
|
144
|
+
);
|
|
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;
|
|
149
150
|
|
|
150
|
-
|
|
151
|
-
|
|
151
|
+
const gestureStateRef = useRef({
|
|
152
|
+
isLow: true,
|
|
153
|
+
lastValue: 0,
|
|
154
|
+
lastPosition: 0,
|
|
155
|
+
});
|
|
156
|
+
const [isPressed, setPressed] = useState(false);
|
|
152
157
|
|
|
153
|
-
|
|
154
|
-
|
|
158
|
+
const containerWidthRef = useRef(0);
|
|
159
|
+
const [thumbWidth, setThumbWidth] = useState(0);
|
|
155
160
|
|
|
156
|
-
|
|
161
|
+
const [selectedRailStyle, updateSelectedRail] = useSelectedRail(
|
|
157
162
|
inPropsRef,
|
|
158
163
|
containerWidthRef,
|
|
159
164
|
thumbWidth,
|
|
160
|
-
disableRange
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
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 =
|
|
172
177
|
((high - min) / (max - min)) * (containerWidth - thumbWidth);
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
178
|
+
highThumbX.setValue(highPosition);
|
|
179
|
+
}
|
|
180
|
+
const {current: lowThumbX} = lowThumbXRef;
|
|
181
|
+
const lowPosition =
|
|
177
182
|
((low - min) / (max - min)) * (containerWidth - thumbWidth);
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
183
|
+
lowThumbX.setValue(lowPosition);
|
|
184
|
+
typeof updateSelectedRail === 'function' && updateSelectedRail();
|
|
185
|
+
onValueChanged?.(low, high, false);
|
|
186
|
+
}, [
|
|
187
|
+
disableRange,
|
|
188
|
+
inPropsRef,
|
|
189
|
+
max,
|
|
190
|
+
min,
|
|
191
|
+
onValueChanged,
|
|
192
|
+
thumbWidth,
|
|
193
|
+
updateSelectedRail,
|
|
194
|
+
]);
|
|
190
195
|
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
196
|
+
useEffect(() => {
|
|
197
|
+
const {lowPrev, highPrev} = inPropsRefPrev;
|
|
198
|
+
if (
|
|
194
199
|
(lowProp !== undefined && lowProp !== lowPrev) ||
|
|
195
200
|
(highProp !== undefined && highProp !== highPrev)
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
201
|
+
) {
|
|
202
|
+
updateThumbs();
|
|
203
|
+
}
|
|
204
|
+
}, [highProp, inPropsRefPrev.lowPrev, inPropsRefPrev.highPrev, lowProp]);
|
|
200
205
|
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
206
|
+
useEffect(() => {
|
|
207
|
+
updateThumbs();
|
|
208
|
+
}, [updateThumbs]);
|
|
204
209
|
|
|
205
|
-
|
|
206
|
-
|
|
210
|
+
const handleContainerLayout = useWidthLayout(
|
|
211
|
+
containerWidthRef,
|
|
212
|
+
updateThumbs
|
|
213
|
+
);
|
|
214
|
+
const handleThumbLayout = useCallback(
|
|
207
215
|
({nativeEvent}) => {
|
|
208
216
|
const {
|
|
209
217
|
layout: {width},
|
|
@@ -212,170 +220,170 @@ const Slider: React.FC<SliderProps> = memo(({
|
|
|
212
220
|
setThumbWidth(width);
|
|
213
221
|
}
|
|
214
222
|
},
|
|
215
|
-
[thumbWidth]
|
|
216
|
-
|
|
223
|
+
[thumbWidth]
|
|
224
|
+
);
|
|
217
225
|
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
226
|
+
const lowStyles = useMemo(() => {
|
|
227
|
+
return {transform: [{translateX: lowThumbX}]};
|
|
228
|
+
}, [lowThumbX]);
|
|
221
229
|
|
|
222
|
-
|
|
223
|
-
|
|
230
|
+
const highStyles = useMemo(() => {
|
|
231
|
+
return disableRange
|
|
224
232
|
? null
|
|
225
233
|
: [styles.highThumbContainer, {transform: [{translateX: highThumbX}]}];
|
|
226
|
-
|
|
234
|
+
}, [disableRange, highThumbX]);
|
|
227
235
|
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
236
|
+
const railContainerStyles = useMemo(() => {
|
|
237
|
+
return [styles.railsContainer, {marginHorizontal: thumbWidth / 2}];
|
|
238
|
+
}, [thumbWidth]);
|
|
231
239
|
|
|
232
|
-
|
|
240
|
+
const [labelView, labelUpdate] = useThumbFollower(
|
|
233
241
|
containerWidthRef,
|
|
234
242
|
gestureStateRef,
|
|
235
243
|
isPressed,
|
|
236
244
|
allowLabelOverflow,
|
|
237
245
|
disabledLow,
|
|
238
|
-
disabledHigh
|
|
239
|
-
|
|
246
|
+
disabledHigh
|
|
247
|
+
);
|
|
240
248
|
|
|
241
|
-
|
|
242
|
-
|
|
249
|
+
const renderThumb = (name: string) => {
|
|
250
|
+
const isDisabled =
|
|
243
251
|
(name === 'low' && disabledLow) || (name === 'high' && disabledHigh);
|
|
244
252
|
|
|
245
|
-
|
|
253
|
+
const thumbColor = isDisabled
|
|
246
254
|
? theme.colors.text.disable
|
|
247
255
|
: theme.colors.primary;
|
|
248
256
|
|
|
249
|
-
|
|
257
|
+
return (
|
|
250
258
|
<View
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
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
|
+
]}
|
|
262
270
|
/>
|
|
263
|
-
|
|
264
|
-
|
|
271
|
+
);
|
|
272
|
+
};
|
|
265
273
|
|
|
266
|
-
|
|
267
|
-
|
|
274
|
+
const lowThumb = renderThumb('low');
|
|
275
|
+
const highThumb = renderThumb('high');
|
|
268
276
|
|
|
269
|
-
|
|
277
|
+
const labelContainerProps = useLabelContainerProps(floatingLabel);
|
|
270
278
|
|
|
271
|
-
|
|
279
|
+
const {panHandlers} = useMemo(
|
|
272
280
|
() =>
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
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) {
|
|
312
340
|
return;
|
|
313
341
|
}
|
|
314
|
-
|
|
315
|
-
const
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
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 &&
|
|
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 &&
|
|
344
352
|
typeof labelUpdate === 'function' &&
|
|
345
353
|
labelUpdate(gestureStateRef.current.lastPosition, value);
|
|
346
354
|
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
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
|
+
}),
|
|
379
387
|
[
|
|
380
388
|
pointerX,
|
|
381
389
|
inPropsRef,
|
|
@@ -388,28 +396,28 @@ const Slider: React.FC<SliderProps> = memo(({
|
|
|
388
396
|
setHigh,
|
|
389
397
|
labelUpdate,
|
|
390
398
|
updateSelectedRail,
|
|
391
|
-
]
|
|
392
|
-
|
|
399
|
+
]
|
|
400
|
+
);
|
|
393
401
|
|
|
394
|
-
|
|
395
|
-
|
|
402
|
+
const renderTrack = (color: string) => {
|
|
403
|
+
return (
|
|
396
404
|
<View
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
|
|
405
|
+
style={{
|
|
406
|
+
width: '100%',
|
|
407
|
+
height: 4,
|
|
408
|
+
borderRadius: Radius.L,
|
|
409
|
+
backgroundColor: color,
|
|
410
|
+
}}
|
|
403
411
|
/>
|
|
404
|
-
|
|
405
|
-
|
|
412
|
+
);
|
|
413
|
+
};
|
|
406
414
|
|
|
407
|
-
|
|
415
|
+
const trackColor =
|
|
408
416
|
disabledHigh && disabledLow
|
|
409
|
-
|
|
410
|
-
|
|
417
|
+
? theme.colors.text.disable
|
|
418
|
+
: theme.colors.primary;
|
|
411
419
|
|
|
412
|
-
|
|
420
|
+
return (
|
|
413
421
|
<View {...restProps}>
|
|
414
422
|
<View {...labelContainerProps}>{labelView}</View>
|
|
415
423
|
<View onLayout={handleContainerLayout} style={styles.controlsContainer}>
|
|
@@ -423,16 +431,17 @@ const Slider: React.FC<SliderProps> = memo(({
|
|
|
423
431
|
{lowThumb}
|
|
424
432
|
</Animated.View>
|
|
425
433
|
{!disableRange && (
|
|
426
|
-
|
|
434
|
+
<Animated.View style={highStyles}>{highThumb}</Animated.View>
|
|
427
435
|
)}
|
|
428
436
|
<View
|
|
429
|
-
|
|
430
|
-
|
|
431
|
-
|
|
437
|
+
{...panHandlers}
|
|
438
|
+
style={styles.touchableArea}
|
|
439
|
+
collapsable={false}
|
|
432
440
|
/>
|
|
433
441
|
</View>
|
|
434
442
|
</View>
|
|
435
|
-
|
|
436
|
-
}
|
|
443
|
+
);
|
|
444
|
+
}
|
|
445
|
+
);
|
|
437
446
|
|
|
438
447
|
export {Slider};
|
package/package.json
CHANGED
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
|
-
|
|
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"}'
|