@momo-kits/slider 0.0.73-beta → 0.72.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/Slider.web.js CHANGED
@@ -1,741 +1,761 @@
1
- import React, { Component } from 'react';
1
+ import React, {Component} from 'react';
2
2
  import PropTypes from 'prop-types';
3
- import {
4
- StyleSheet,
5
- PanResponder,
6
- View,
7
- I18nManager,
8
- ImageBackground,
9
- } from 'react-native';
10
- import { get } from 'lodash';
3
+ import {StyleSheet, PanResponder, View, I18nManager} from 'react-native';
4
+ import {get} from 'lodash';
11
5
  import DefaultMarker from './DefaultMarker';
12
- import DefaultLabel from './DefaultLabel';
13
- import { createArray, valueToPosition, positionToValue } from './converters';
14
- import Colors from '../../core/colors';
6
+ import {createArray, valueToPosition, positionToValue} from './converters';
7
+ import Colors from '../../core-v2/colors';
8
+ import Text from '../../core-v2/components/typography';
9
+ import LocalizedStrings from '../../core-v2/components/language/Language';
10
+ import Spacing from '../../core-v2/spacing';
15
11
 
16
- export default class Slider extends Component {
17
- constructor(props) {
18
- super(props);
19
- const {
20
- optionsArray,
21
- min,
22
- max,
23
- step,
24
- length,
25
- values
26
- } = this.props;
27
- this.optionsArray = optionsArray
28
- || createArray(min, max, step);
29
- const defaultSliderLength = length;
30
- this.stepLength = defaultSliderLength / this.optionsArray.length;
31
- const initialValues = values.map((value) => valueToPosition(value, this.optionsArray, defaultSliderLength));
32
- console.warn('initialValues', initialValues);
33
- this.state = {
34
- valueOne: values[0],
35
- valueTwo: values[1],
36
- pastOne: initialValues[0],
37
- pastTwo: initialValues[1],
38
- positionOne: initialValues[0],
39
- positionTwo: initialValues[1],
40
- sliderLength: defaultSliderLength
41
- };
42
- this.subscribePanResponder();
43
- }
44
-
45
- subscribePanResponder = () => {
46
- const customPanResponder = (start, move, end) => PanResponder.create({
47
- onStartShouldSetPanResponder: () => true,
48
- onStartShouldSetPanResponderCapture: () => true,
49
- onMoveShouldSetPanResponder: () => true,
50
- onMoveShouldSetPanResponderCapture: () => true,
51
- onPanResponderGrant: () => start(),
52
- onPanResponderMove: (evt, gestureState) => move(gestureState),
53
- onPanResponderTerminationRequest: () => false,
54
- onPanResponderRelease: (evt, gestureState) => end(gestureState),
55
- onPanResponderTerminate: (evt, gestureState) => end(gestureState),
56
- onShouldBlockNativeResponder: () => true,
57
- });
58
-
59
- this._panResponderBetween = customPanResponder(
60
- (gestureState) => {
61
- this.startOne(gestureState);
62
- this.startTwo(gestureState);
63
- },
64
- (gestureState) => {
65
- this.moveOne(gestureState);
66
- this.moveTwo(gestureState);
67
- },
68
- (gestureState) => {
69
- this.endOne(gestureState);
70
- this.endTwo(gestureState);
71
- },
72
- );
73
-
74
- this._panResponderOne = customPanResponder(
75
- this.startOne,
76
- this.moveOne,
77
- this.endOne,
78
- );
79
- this._panResponderTwo = customPanResponder(
80
- this.startTwo,
81
- this.moveTwo,
82
- this.endTwo,
83
- );
84
- };
85
-
86
- startOne = () => {
87
- const { enabledOne, onChangeStart } = this.props;
88
- const { onePressed } = this.state;
89
- if (enabledOne) {
90
- onChangeStart();
91
- this.setState({
92
- onePressed: !onePressed,
93
- });
94
- }
95
- };
96
-
97
- startTwo = () => {
98
- const { enabledTwo, onChangeStart } = this.props;
99
- const { twoPressed } = this.state;
100
- if (enabledTwo) {
101
- onChangeStart();
102
- this.setState({
103
- twoPressed: !twoPressed,
104
- });
105
- }
106
- };
12
+ const LANGUAGE = LocalizedStrings.getLanguage();
107
13
 
108
- moveOne = (gestureState) => {
109
- const {
110
- enabledOne,
111
- vertical,
112
- allowOverlap,
113
- minMarkerOverlapDistance,
114
- // sliderLength,
115
- touchDimensions,
116
- snapped,
117
- onChange,
118
- onMarkersPosition,
119
- allowRange = [],
120
- min,
121
- max
122
- } = this.props;
123
- const {
124
- pastOne,
125
- positionTwo,
126
- valueOne,
127
- valueTwo,
128
- sliderLength
129
- } = this.state;
130
- if (!enabledOne) {
131
- return;
132
- }
133
-
134
- const accumDistance = vertical
135
- ? -gestureState.dy
136
- : gestureState.dx;
137
- const accumDistanceDisplacement = vertical
138
- ? gestureState.dx
139
- : gestureState.dy;
140
-
141
- const unconfined = I18nManager.isRTL
142
- ? pastOne - accumDistance
143
- : accumDistance + pastOne;
144
- const bottom = 0;
145
- const trueTop = positionTwo
146
- - (allowOverlap
147
- ? 0
148
- : minMarkerOverlapDistance > 0
149
- ? minMarkerOverlapDistance
150
- : this.stepLength);
151
- const top = trueTop === 0 ? 0 : trueTop || sliderLength;
152
- const confined = unconfined < bottom ? bottom : unconfined > top ? top : unconfined;
153
- const { slipDisplacement } = touchDimensions;
154
-
155
- if (
156
- Math.abs(accumDistanceDisplacement) < slipDisplacement
157
- || !slipDisplacement
158
- ) {
159
- const value = positionToValue(
160
- confined,
161
- this.optionsArray,
162
- sliderLength,
163
- );
164
-
165
- if (allowRange?.length > 0 && value < get(allowRange, '[0]', min)) return;
166
- if (allowRange?.length > 1 && value > get(allowRange, '[1]', max)) return;
167
-
168
- const snappedValue = valueToPosition(
169
- value,
170
- this.optionsArray,
171
- sliderLength,
172
- );
173
-
174
- this.setState({
175
- positionOne: snapped ? snappedValue : confined,
176
- });
177
-
178
- if (value !== valueOne) {
179
- this.setState(
180
- {
181
- valueOne: value,
182
- },
183
- () => {
184
- const {
185
- valueOne: newValueOne,
186
- positionOne: newPositionOne
187
- } = this.state;
188
- const change = [newValueOne];
189
- if (valueTwo) {
190
- change.push(valueTwo);
191
- }
192
- onChange(change);
193
-
194
- onMarkersPosition([
195
- newPositionOne,
196
- positionTwo,
197
- ]);
198
- },
199
- );
200
- }
201
- }
14
+ export default class Slider extends Component {
15
+ constructor(props) {
16
+ super(props);
17
+ const {optionsArray, min, max, step, length, values} = this.props;
18
+ this.optionsArray = optionsArray || createArray(min, max, step);
19
+ const defaultSliderLength = length;
20
+ this.stepLength = defaultSliderLength / this.optionsArray.length;
21
+ const initialValues = values.map(value =>
22
+ valueToPosition(value, this.optionsArray, defaultSliderLength),
23
+ );
24
+ this.state = {
25
+ valueOne: values[0],
26
+ valueTwo: values[1],
27
+ pastOne: initialValues[0],
28
+ pastTwo: initialValues[1],
29
+ positionOne: initialValues[0],
30
+ positionTwo: initialValues[1],
31
+ sliderLength: defaultSliderLength,
202
32
  };
33
+ this.subscribePanResponder();
34
+ }
35
+
36
+ subscribePanResponder = () => {
37
+ const customPanResponder = (start, move, end) =>
38
+ PanResponder.create({
39
+ onStartShouldSetPanResponder: () => true,
40
+ onStartShouldSetPanResponderCapture: () => true,
41
+ onMoveShouldSetPanResponder: () => true,
42
+ onMoveShouldSetPanResponderCapture: () => true,
43
+ onPanResponderGrant: () => start(),
44
+ onPanResponderMove: (evt, gestureState) => move(gestureState),
45
+ onPanResponderTerminationRequest: () => false,
46
+ onPanResponderRelease: (evt, gestureState) => end(gestureState),
47
+ onPanResponderTerminate: (evt, gestureState) => end(gestureState),
48
+ onShouldBlockNativeResponder: () => true,
49
+ });
50
+
51
+ this._panResponderBetween = customPanResponder(
52
+ gestureState => {
53
+ this.startOne(gestureState);
54
+ this.startTwo(gestureState);
55
+ },
56
+ gestureState => {
57
+ this.moveOne(gestureState);
58
+ this.moveTwo(gestureState);
59
+ },
60
+ gestureState => {
61
+ this.endOne(gestureState);
62
+ this.endTwo(gestureState);
63
+ },
64
+ );
65
+
66
+ this._panResponderOne = customPanResponder(
67
+ this.startOne,
68
+ this.moveOne,
69
+ this.endOne,
70
+ );
71
+ this._panResponderTwo = customPanResponder(
72
+ this.startTwo,
73
+ this.moveTwo,
74
+ this.endTwo,
75
+ );
76
+ };
77
+
78
+ startOne = () => {
79
+ const {enabledOne, onChangeStart} = this.props;
80
+ const {onePressed} = this.state;
81
+ if (enabledOne) {
82
+ onChangeStart();
83
+ this.setState({
84
+ onePressed: !onePressed,
85
+ });
86
+ }
87
+ };
88
+
89
+ startTwo = () => {
90
+ const {enabledTwo, onChangeStart} = this.props;
91
+ const {twoPressed} = this.state;
92
+ if (enabledTwo) {
93
+ onChangeStart();
94
+ this.setState({
95
+ twoPressed: !twoPressed,
96
+ });
97
+ }
98
+ };
99
+
100
+ moveOne = gestureState => {
101
+ const {
102
+ enabledOne,
103
+ allowOverlap,
104
+ minMarkerOverlapDistance,
105
+ touchDimensions,
106
+ snapped,
107
+ onChange,
108
+ onMarkersPosition,
109
+ allowRange = [],
110
+ min,
111
+ max,
112
+ } = this.props;
113
+ const {pastOne, positionTwo, valueOne, valueTwo, sliderLength} = this.state;
114
+ if (!enabledOne) {
115
+ return;
116
+ }
203
117
 
204
- moveTwo = (gestureState) => {
205
- const {
206
- enabledTwo,
207
- vertical,
208
- allowOverlap,
209
- minMarkerOverlapDistance,
210
- // sliderLength,
211
- touchDimensions,
212
- snapped,
213
- onChange,
214
- onMarkersPosition
215
- } = this.props;
216
- const {
217
- pastTwo,
218
- positionOne,
219
- sliderLength,
220
- valueTwo,
221
- valueOne,
222
- } = this.state;
223
- if (!enabledTwo) {
224
- return;
225
- }
226
-
227
- const accumDistance = vertical
228
- ? -gestureState.dy
229
- : gestureState.dx;
230
- const accumDistanceDisplacement = vertical
231
- ? gestureState.dx
232
- : gestureState.dy;
233
-
234
- const unconfined = I18nManager.isRTL
235
- ? pastTwo - accumDistance
236
- : accumDistance + pastTwo;
237
- const bottom = positionOne
238
- + (allowOverlap
239
- ? 0
240
- : minMarkerOverlapDistance > 0
241
- ? minMarkerOverlapDistance
242
- : this.stepLength);
243
- const top = sliderLength;
244
- const confined = unconfined < bottom ? bottom : unconfined > top ? top : unconfined;
245
- const { slipDisplacement } = touchDimensions;
246
-
247
- if (
248
- Math.abs(accumDistanceDisplacement) < slipDisplacement
249
- || !slipDisplacement
250
- ) {
251
- const value = positionToValue(
252
- confined,
253
- this.optionsArray,
254
- sliderLength,
255
- );
256
-
257
- const snappedValue = valueToPosition(
258
- value,
259
- this.optionsArray,
260
- sliderLength,
261
- );
262
-
263
- this.setState({
264
- positionTwo: snapped ? snappedValue : confined,
265
- });
266
-
267
- if (value !== valueTwo) {
268
- this.setState(
269
- {
270
- valueTwo: value,
271
- },
272
- () => {
273
- console.log(valueOne);
274
- const {
275
- valueTwo: newValueTwo,
276
- positionTwo: newPositionTwo
277
- } = this.state;
278
- onChange([
279
- valueOne,
280
- newValueTwo,
281
- ]);
282
-
283
- onMarkersPosition([
284
- positionOne,
285
- newPositionTwo,
286
- ]);
287
- },
288
- );
118
+ const accumDistance = gestureState.dx;
119
+ const accumDistanceDisplacement = gestureState.dy;
120
+
121
+ const unconfined = I18nManager.isRTL
122
+ ? pastOne - accumDistance
123
+ : accumDistance + pastOne;
124
+ const bottom = 0;
125
+ const trueTop =
126
+ positionTwo -
127
+ (allowOverlap
128
+ ? 0
129
+ : minMarkerOverlapDistance > 0
130
+ ? minMarkerOverlapDistance
131
+ : this.stepLength);
132
+ const top = trueTop === 0 ? 0 : trueTop || sliderLength;
133
+ const confined =
134
+ unconfined < bottom ? bottom : unconfined > top ? top : unconfined;
135
+ const {slipDisplacement} = touchDimensions;
136
+
137
+ if (
138
+ Math.abs(accumDistanceDisplacement) < slipDisplacement ||
139
+ !slipDisplacement
140
+ ) {
141
+ const value = positionToValue(confined, this.optionsArray, sliderLength);
142
+
143
+ if (allowRange?.length > 0 && value < get(allowRange, '[0]', min)) {
144
+ return;
145
+ }
146
+ if (allowRange?.length > 1 && value > get(allowRange, '[1]', max)) {
147
+ return;
148
+ }
149
+
150
+ const snappedValue = valueToPosition(
151
+ value,
152
+ this.optionsArray,
153
+ sliderLength,
154
+ );
155
+
156
+ this.setState({
157
+ positionOne: snapped ? snappedValue : confined,
158
+ });
159
+
160
+ if (value !== valueOne) {
161
+ this.setState(
162
+ {
163
+ valueOne: value,
164
+ },
165
+ () => {
166
+ const {valueOne: newValueOne, positionOne: newPositionOne} =
167
+ this.state;
168
+ const change = [newValueOne];
169
+ if (valueTwo) {
170
+ change.push(valueTwo);
289
171
  }
290
- }
291
- };
172
+ onChange(change);
292
173
 
293
- endOne = (gestureState) => {
294
- const { onToggleOne, onChangeFinish } = this.props;
295
- const {
296
- positionOne, onePressed, valueOne, valueTwo
297
- } = this.state;
298
- if (gestureState.moveX === 0 && onToggleOne) {
299
- onToggleOne();
300
- return;
301
- }
174
+ onMarkersPosition([newPositionOne, positionTwo]);
175
+ },
176
+ );
177
+ }
178
+ }
179
+ };
180
+
181
+ moveTwo = gestureState => {
182
+ const {
183
+ enabledTwo,
184
+ allowOverlap,
185
+ minMarkerOverlapDistance,
186
+ // sliderLength,
187
+ touchDimensions,
188
+ snapped,
189
+ onChange,
190
+ onMarkersPosition,
191
+ } = this.props;
192
+ const {pastTwo, positionOne, sliderLength, valueTwo, valueOne} = this.state;
193
+ if (!enabledTwo) {
194
+ return;
195
+ }
302
196
 
197
+ const accumDistance = gestureState.dx;
198
+ const accumDistanceDisplacement = gestureState.dy;
199
+
200
+ const unconfined = I18nManager.isRTL
201
+ ? pastTwo - accumDistance
202
+ : accumDistance + pastTwo;
203
+ const bottom =
204
+ positionOne +
205
+ (allowOverlap
206
+ ? 0
207
+ : minMarkerOverlapDistance > 0
208
+ ? minMarkerOverlapDistance
209
+ : this.stepLength);
210
+ const top = sliderLength;
211
+ const confined =
212
+ unconfined < bottom ? bottom : unconfined > top ? top : unconfined;
213
+ const {slipDisplacement} = touchDimensions;
214
+
215
+ if (
216
+ Math.abs(accumDistanceDisplacement) < slipDisplacement ||
217
+ !slipDisplacement
218
+ ) {
219
+ const value = positionToValue(confined, this.optionsArray, sliderLength);
220
+
221
+ const snappedValue = valueToPosition(
222
+ value,
223
+ this.optionsArray,
224
+ sliderLength,
225
+ );
226
+
227
+ this.setState({
228
+ positionTwo: snapped ? snappedValue : confined,
229
+ });
230
+
231
+ if (value !== valueTwo) {
303
232
  this.setState(
304
- {
305
- pastOne: positionOne,
306
- onePressed: !onePressed,
307
- },
308
- () => {
309
- const change = [valueOne];
310
- if (valueTwo) {
311
- change.push(valueTwo);
312
- }
313
- onChangeFinish(change);
314
- },
233
+ {
234
+ valueTwo: value,
235
+ },
236
+ () => {
237
+ const {valueTwo: newValueTwo, positionTwo: newPositionTwo} =
238
+ this.state;
239
+ onChange([valueOne, newValueTwo]);
240
+
241
+ onMarkersPosition([positionOne, newPositionTwo]);
242
+ },
315
243
  );
316
- };
244
+ }
245
+ }
246
+ };
247
+
248
+ endOne = gestureState => {
249
+ const {onToggleOne, onChangeFinish} = this.props;
250
+ const {positionOne, onePressed, valueOne, valueTwo} = this.state;
251
+ if (gestureState.moveX === 0 && onToggleOne) {
252
+ onToggleOne();
253
+ return;
254
+ }
317
255
 
318
- endTwo = (gestureState) => {
319
- const { onToggleTwo, onChangeFinish } = this.props;
320
- const {
321
- twoPressed, positionTwo, valueOne, valueTwo
322
- } = this.state;
323
- if (gestureState.moveX === 0 && onToggleTwo) {
324
- onToggleTwo();
325
- return;
256
+ this.setState(
257
+ {
258
+ pastOne: positionOne,
259
+ onePressed: !onePressed,
260
+ },
261
+ () => {
262
+ const change = [valueOne];
263
+ if (valueTwo) {
264
+ change.push(valueTwo);
326
265
  }
266
+ onChangeFinish(change);
267
+ },
268
+ );
269
+ };
270
+
271
+ endTwo = gestureState => {
272
+ const {onToggleTwo, onChangeFinish} = this.props;
273
+ const {twoPressed, positionTwo, valueOne, valueTwo} = this.state;
274
+ if (gestureState.moveX === 0 && onToggleTwo) {
275
+ onToggleTwo();
276
+ return;
277
+ }
327
278
 
328
- this.setState(
329
- {
330
- twoPressed: !twoPressed,
331
- pastTwo: positionTwo,
332
- },
333
- () => {
334
- onChangeFinish([
335
- valueOne,
336
- valueTwo,
337
- ]);
338
- },
339
- );
340
- };
279
+ this.setState(
280
+ {
281
+ twoPressed: !twoPressed,
282
+ pastTwo: positionTwo,
283
+ },
284
+ () => {
285
+ onChangeFinish([valueOne, valueTwo]);
286
+ },
287
+ );
288
+ };
289
+
290
+ componentDidUpdate(prevProps, prevState) {
291
+ const {positionOne: prevPositionOne, positionTwo: prevPositionTwo} =
292
+ prevState;
293
+
294
+ const {positionOne, positionTwo, onePressed, twoPressed, sliderLength} =
295
+ this.state;
296
+ const {onMarkersPosition, min, max, step, values, optionsArray} =
297
+ this.props;
298
+
299
+ if (
300
+ typeof positionOne === 'undefined' &&
301
+ typeof positionTwo !== 'undefined'
302
+ ) {
303
+ return;
304
+ }
341
305
 
342
- componentDidUpdate(prevProps, prevState) {
343
- const {
344
- positionOne: prevPositionOne,
345
- positionTwo: prevPositionTwo,
346
- } = prevState;
347
-
348
- const {
349
- positionOne, positionTwo, onePressed, twoPressed, sliderLength
350
- } = this.state;
351
- const {
352
- onMarkersPosition, min, max, step, values, optionsArray
353
- } = this.props;
354
-
355
- if (
356
- typeof positionOne === 'undefined'
357
- && typeof positionTwo !== 'undefined'
358
- ) {
359
- return;
360
- }
306
+ if (positionOne !== prevPositionOne || positionTwo !== prevPositionTwo) {
307
+ onMarkersPosition([positionOne, positionTwo]);
308
+ }
361
309
 
362
- if (positionOne !== prevPositionOne || positionTwo !== prevPositionTwo) {
363
- onMarkersPosition([positionOne, positionTwo]);
364
- }
310
+ if (onePressed || twoPressed) {
311
+ return;
312
+ }
365
313
 
366
- if (onePressed || twoPressed) {
367
- return;
368
- }
314
+ const nextState = {};
315
+ if (
316
+ prevProps.min !== min ||
317
+ prevProps.max !== max ||
318
+ prevProps.step !== step ||
319
+ prevProps.values[0] !== values[0] ||
320
+ prevState.sliderLength !== sliderLength ||
321
+ prevProps.values[1] !== values[1] ||
322
+ (prevState.sliderLength !== sliderLength && prevProps.values[1])
323
+ ) {
324
+ this.optionsArray = optionsArray || createArray(min, max, step);
325
+
326
+ this.stepLength = sliderLength / this.optionsArray.length;
327
+
328
+ const positionOneValue = valueToPosition(
329
+ values[0],
330
+ this.optionsArray,
331
+ sliderLength,
332
+ );
333
+ // eslint-disable-next-line prefer-destructuring
334
+ nextState.valueOne = values[0];
335
+ nextState.pastOne = positionOneValue;
336
+ nextState.positionOne = positionOneValue;
337
+
338
+ const positionTwoValue = valueToPosition(
339
+ values[1],
340
+ this.optionsArray,
341
+ sliderLength,
342
+ );
343
+ // eslint-disable-next-line prefer-destructuring
344
+ nextState.valueTwo = values[1];
345
+ nextState.pastTwo = positionTwoValue;
346
+ nextState.positionTwo = positionTwoValue;
347
+
348
+ // eslint-disable-next-line react/no-did-update-set-state
349
+ this.setState(nextState);
350
+ }
351
+ }
352
+
353
+ onContentLayout(e) {
354
+ const {length} = this.props;
355
+ if (!length) {
356
+ const layoutLength = e.nativeEvent.layout.width;
357
+ this.setState({
358
+ sliderLength: layoutLength,
359
+ });
360
+ }
361
+ }
369
362
 
370
- const nextState = {};
371
- if (
372
- prevProps.min !== min
373
- || prevProps.max !== max
374
- || prevProps.step !== step
375
- || prevProps.values[0] !== values[0]
376
- || prevState.sliderLength !== sliderLength
377
- || prevProps.values[1] !== values[1]
378
- || (prevState.sliderLength !== sliderLength
379
- && prevProps.values[1])
380
- ) {
381
- this.optionsArray = optionsArray
382
- || createArray(min, max, step);
383
-
384
- this.stepLength = sliderLength / this.optionsArray.length;
385
-
386
- const positionOneValue = valueToPosition(
387
- values[0],
388
- this.optionsArray,
389
- sliderLength,
390
- );
391
- // eslint-disable-next-line prefer-destructuring
392
- nextState.valueOne = values[0];
393
- nextState.pastOne = positionOneValue;
394
- nextState.positionOne = positionOneValue;
395
-
396
- const positionTwoValue = valueToPosition(
397
- values[1],
398
- this.optionsArray,
399
- sliderLength,
400
- );
401
- // eslint-disable-next-line prefer-destructuring
402
- nextState.valueTwo = values[1];
403
- nextState.pastTwo = positionTwoValue;
404
- nextState.positionTwo = positionTwoValue;
405
-
406
- // eslint-disable-next-line react/no-did-update-set-state
407
- this.setState(nextState);
408
- }
363
+ _nFormatter(num) {
364
+ let markerLabel = num;
365
+ let digits = 0;
366
+
367
+ if (markerLabel >= 1000000) {
368
+ digits = 1;
409
369
  }
410
370
 
411
- onContentLayout(e) {
412
- const { vertical, length } = this.props;
413
- if (!length) {
414
- const layoutLength = vertical
415
- ? e.nativeEvent.layout.height
416
- : e.nativeEvent.layout.width;
417
- this.setState({
418
- sliderLength: layoutLength
419
- });
420
- }
371
+ const lookup = [
372
+ {
373
+ value: 1000000,
374
+ symbol: LANGUAGE == 'en' ? 'M' : 'Tr',
375
+ },
376
+ {
377
+ value: 1000,
378
+ symbol: 'K',
379
+ },
380
+ {
381
+ value: 1,
382
+ symbol: '',
383
+ },
384
+ ];
385
+
386
+ let item = lookup.slice().find(item => {
387
+ return markerLabel >= item.value;
388
+ });
389
+
390
+ if (item) {
391
+ markerLabel = (markerLabel / item.value).toFixed(digits) + item.symbol;
392
+ } else {
393
+ markerLabel = '0';
421
394
  }
422
395
 
423
- render() {
424
- const {
425
- positionOne, positionTwo, onePressed, valueOne, twoPressed, valueTwo, sliderLength
426
- } = this.state;
427
- const {
428
- style,
429
- selectedStyle,
430
- unselectedStyle,
431
- // sliderLength,
432
- markerOffsetX,
433
- markerOffsetY,
434
- values,
435
- customMarker,
436
- customMarkerLeft,
437
- customMarkerRight,
438
- isMarkersSeparated = false,
439
- customLabel,
440
- touchDimensions,
441
- containerStyle,
442
- vertical,
443
- trackStyle,
444
- markerContainerStyle,
445
- enabledOne,
446
- enabledTwo,
447
- markerStyle,
448
- pressedMarkerStyle,
449
- disabledMarkerStyle,
450
- valuePrefix,
451
- valueSuffix,
452
- enableLabel,
453
- imageBackgroundSource
454
- } = this.props;
455
- const twoMarkers = values.length === 2; // when allowOverlap, positionTwo could be 0, identified as string '0' and throwing 'RawText 0 needs to be wrapped in <Text>' error
456
-
457
- const trackOneLength = positionOne;
458
- const trackOneStyle = twoMarkers
459
- ? unselectedStyle
460
- : selectedStyle || styles.selectedTrack;
461
- const trackThreeLength = twoMarkers ? sliderLength - positionTwo : 0;
462
- const trackThreeStyle = unselectedStyle;
463
- const trackTwoLength = sliderLength - trackOneLength - trackThreeLength;
464
- const trackTwoStyle = twoMarkers
465
- ? selectedStyle || styles.selectedTrack
466
- : unselectedStyle;
467
- const Marker = customMarker;
468
-
469
- const MarkerLeft = customMarkerLeft;
470
- const MarkerRight = customMarkerRight;
471
-
472
- const Label = customLabel;
473
-
474
- const {
475
- borderRadius,
476
- } = touchDimensions;
477
- const touchStyle = {
478
- borderRadius: borderRadius || 0,
479
- };
480
-
481
- const markerContainerOne = {
482
- top: markerOffsetY - 24,
483
- left: trackOneLength + markerOffsetX - 24,
484
- };
485
-
486
- const markerContainerTwo = {
487
- top: markerOffsetY - 24,
488
- right: trackThreeLength - markerOffsetX - 24,
489
- };
490
-
491
- const newContainerStyle = [styles.container, containerStyle];
492
-
493
- if (vertical) {
494
- newContainerStyle.push({
495
- transform: [{ rotate: '-90deg' }],
496
- });
497
- }
396
+ return markerLabel;
397
+ }
398
+
399
+ render() {
400
+ const {
401
+ positionOne,
402
+ positionTwo,
403
+ onePressed,
404
+ valueOne,
405
+ twoPressed,
406
+ valueTwo,
407
+ sliderLength,
408
+ } = this.state;
409
+ const {
410
+ style,
411
+ markerOffsetX,
412
+ markerOffsetY,
413
+ values,
414
+ isMarkersSeparated = false,
415
+ touchDimensions,
416
+ containerStyle,
417
+ markerContainerStyle,
418
+ enabledOne,
419
+ enabledTwo,
420
+ valuePrefix,
421
+ valueSuffix,
422
+ enableLabel = true,
423
+ activeColor,
424
+ inactiveColor,
425
+ } = this.props;
426
+ const twoMarkers = values.length === 2; // when allowOverlap, positionTwo could be 0, identified as string '0' and throwing 'RawText 0 needs to be wrapped in <Text>' error
427
+
428
+ const trackOneLength = positionOne;
429
+ const trackOneStyle = styles.selectedTrack;
430
+ const trackThreeLength = twoMarkers ? sliderLength - positionTwo : 0;
431
+ const trackTwoLength = sliderLength - trackOneLength - trackThreeLength;
432
+ const trackTwoStyle = styles.selectedTrack;
433
+
434
+ const Marker = DefaultMarker;
435
+
436
+ const MarkerLeft = DefaultMarker;
437
+ const MarkerRight = DefaultMarker;
438
+ const {borderRadius} = touchDimensions;
439
+ const touchStyle = {
440
+ borderRadius: borderRadius || 0,
441
+ };
442
+
443
+ const markerContainerOne = {
444
+ top: markerOffsetY - 24,
445
+ left: trackOneLength + markerOffsetX - 32,
446
+ };
498
447
 
499
- const body = (
500
- <View style={{ alignItems: 'center' }}>
501
- <View style={[styles.fullTrack, { width: sliderLength }]}>
448
+ const markerContainerTwo = {
449
+ top: markerOffsetY - 24,
450
+ right: trackThreeLength - markerOffsetX - 32,
451
+ };
452
+
453
+ const newContainerStyle = [styles.container, containerStyle];
454
+
455
+ const markerLabel1 = this._nFormatter(valueOne);
456
+ const markerLabel2 = this._nFormatter(valueTwo);
457
+
458
+ const body = (
459
+ <View style={{alignItems: 'center'}}>
460
+ <View style={[styles.fullTrack, {width: sliderLength}]}>
461
+ <View
462
+ style={[
463
+ styles.track,
464
+ trackOneStyle,
465
+ {
466
+ width: trackOneLength,
467
+ backgroundColor: twoMarkers ? inactiveColor : activeColor,
468
+ },
469
+ !enabledOne && !twoMarkers && styles.disabledTrack,
470
+ ]}
471
+ />
472
+ <View
473
+ style={[
474
+ styles.track,
475
+ trackTwoStyle,
476
+ {
477
+ width: trackTwoLength,
478
+ backgroundColor: twoMarkers ? activeColor : inactiveColor,
479
+ },
480
+ !enabledOne && !enabledTwo && styles.disabledTrack,
481
+ ]}
482
+ {...(twoMarkers ? this._panResponderBetween.panHandlers : {})}
483
+ />
484
+ {twoMarkers && (
485
+ <View
486
+ style={[
487
+ styles.track,
488
+ {
489
+ width: trackThreeLength,
490
+ backgroundColor: inactiveColor,
491
+ },
492
+ ]}
493
+ />
494
+ )}
495
+ <View
496
+ style={[
497
+ styles.markerContainer,
498
+ markerContainerOne,
499
+ markerContainerStyle,
500
+ positionOne > sliderLength / 2 && styles.topMarkerContainer,
501
+ ]}>
502
+ <View
503
+ style={[styles.touch, touchStyle]}
504
+ ref={component => (this._markerOne = component)}
505
+ {...this._panResponderOne.panHandlers}>
506
+ {isMarkersSeparated === false ? (
507
+ <>
508
+ {onePressed && enableLabel && enabledOne && (
502
509
  <View
503
- style={[
504
- styles.track,
505
- trackStyle,
506
- trackOneStyle,
507
- { width: trackOneLength },
508
- ]}
509
- />
510
+ style={[
511
+ styles.valueContainer,
512
+ {
513
+ shadowColor: Colors.black_17,
514
+ shadowOffset: {
515
+ width: 2,
516
+ height: 2,
517
+ },
518
+ shadowOpacity: 0.07,
519
+ shadowRadius: 10,
520
+ },
521
+ ]}>
522
+ <Text.Label3>{markerLabel1}</Text.Label3>
523
+ </View>
524
+ )}
525
+ <Marker
526
+ activeColor={activeColor}
527
+ enabled={enabledOne}
528
+ pressed={onePressed}
529
+ currentValue={valueOne}
530
+ valuePrefix={valuePrefix}
531
+ valueSuffix={valueSuffix}
532
+ />
533
+ </>
534
+ ) : (
535
+ <>
536
+ {onePressed && enableLabel && enabledOne && (
510
537
  <View
538
+ style={[
539
+ styles.valueContainer,
540
+ {
541
+ shadowColor: Colors.black_17,
542
+ shadowOffset: {
543
+ width: 2,
544
+ height: 2,
545
+ },
546
+ shadowOpacity: 0.07,
547
+ shadowRadius: 10,
548
+ },
549
+ ]}>
550
+ <Text.Label3>{markerLabel1}</Text.Label3>
551
+ </View>
552
+ )}
553
+ <MarkerLeft
554
+ activeColor={activeColor}
555
+ enabled={enabledOne}
556
+ pressed={onePressed}
557
+ currentValue={valueOne}
558
+ valuePrefix={valuePrefix}
559
+ valueSuffix={valueSuffix}
560
+ />
561
+ </>
562
+ )}
563
+ </View>
564
+ </View>
565
+ {twoMarkers && positionOne !== sliderLength && (
566
+ <View
567
+ style={[
568
+ styles.markerContainer,
569
+ markerContainerTwo,
570
+ markerContainerStyle,
571
+ ]}>
572
+ <View
573
+ style={[styles.touch, touchStyle]}
574
+ ref={component => (this._markerTwo = component)}
575
+ {...this._panResponderTwo.panHandlers}>
576
+ {isMarkersSeparated === false ? (
577
+ <>
578
+ {twoPressed && enableLabel && enabledTwo && (
579
+ <View
511
580
  style={[
512
- styles.track,
513
- trackStyle,
514
- trackTwoStyle,
515
- { width: trackTwoLength },
516
- ]}
517
- {...(twoMarkers ? this._panResponderBetween.panHandlers : {})}
518
- />
519
- {twoMarkers && (
520
- <View
521
- style={[
522
- styles.track,
523
- trackStyle,
524
- trackThreeStyle,
525
- { width: trackThreeLength },
526
- ]}
527
- />
581
+ styles.valueContainer,
582
+ {
583
+ shadowColor: Colors.black_17,
584
+ shadowOffset: {
585
+ width: 2,
586
+ height: 2,
587
+ },
588
+ shadowOpacity: 0.07,
589
+ shadowRadius: 10,
590
+ },
591
+ ]}>
592
+ <Text.Label3>{markerLabel2}</Text.Label3>
593
+ </View>
528
594
  )}
529
- <View
595
+ <Marker
596
+ activeColor={activeColor}
597
+ pressed={twoPressed}
598
+ currentValue={valueTwo}
599
+ enabled={enabledTwo}
600
+ valuePrefix={valuePrefix}
601
+ valueSuffix={valueSuffix}
602
+ />
603
+ </>
604
+ ) : (
605
+ <>
606
+ {twoPressed && enableLabel && enabledTwo && (
607
+ <View
530
608
  style={[
531
- styles.markerContainer,
532
- markerContainerOne,
533
- markerContainerStyle,
534
- positionOne > sliderLength / 2 && styles.topMarkerContainer,
535
- ]}
536
- >
537
- <View
538
- style={[styles.touch, touchStyle]}
539
- ref={(component) => (this._markerOne = component)}
540
- {...this._panResponderOne.panHandlers}
541
- >
542
- {isMarkersSeparated === false
543
- ? (
544
- <Marker
545
- enabled={enabledOne}
546
- pressed={onePressed}
547
- markerStyle={markerStyle}
548
- pressedMarkerStyle={pressedMarkerStyle}
549
- disabledMarkerStyle={disabledMarkerStyle}
550
- currentValue={valueOne}
551
- valuePrefix={valuePrefix}
552
- valueSuffix={valueSuffix}
553
- />
554
- ) : (
555
- <MarkerLeft
556
- enabled={enabledOne}
557
- pressed={onePressed}
558
- markerStyle={markerStyle}
559
- pressedMarkerStyle={pressedMarkerStyle}
560
- disabledMarkerStyle={disabledMarkerStyle}
561
- currentValue={valueOne}
562
- valuePrefix={valuePrefix}
563
- valueSuffix={valueSuffix}
564
- />
565
- )}
566
- </View>
567
- </View>
568
- {twoMarkers && positionOne !== sliderLength && (
569
- <View
570
- style={[
571
- styles.markerContainer,
572
- markerContainerTwo,
573
- markerContainerStyle,
574
- ]}
575
- >
576
- <View
577
- style={[styles.touch, touchStyle]}
578
- ref={(component) => (this._markerTwo = component)}
579
- {...this._panResponderTwo.panHandlers}
580
- >
581
- {isMarkersSeparated === false
582
- ? (
583
- <Marker
584
- pressed={twoPressed}
585
- markerStyle={markerStyle}
586
- pressedMarkerStyle={pressedMarkerStyle}
587
- disabledMarkerStyle={disabledMarkerStyle}
588
- currentValue={valueTwo}
589
- enabled={enabledTwo}
590
- valuePrefix={valuePrefix}
591
- valueSuffix={valueSuffix}
592
- />
593
- ) : (
594
- <MarkerRight
595
- pressed={twoPressed}
596
- markerStyle={markerStyle}
597
- pressedMarkerStyle={pressedMarkerStyle}
598
- disabledMarkerStyle={disabledMarkerStyle}
599
- currentValue={valueTwo}
600
- enabled={enabledTwo}
601
- valuePrefix={valuePrefix}
602
- valueSuffix={valueSuffix}
603
- />
604
- )}
605
- </View>
606
- </View>
609
+ styles.valueContainer,
610
+ {
611
+ shadowColor: Colors.black_17,
612
+ shadowOffset: {
613
+ width: 2,
614
+ height: 2,
615
+ },
616
+ shadowOpacity: 0.07,
617
+ shadowRadius: 10,
618
+ },
619
+ ]}>
620
+ <Text.Label3>{markerLabel2}</Text.Label3>
621
+ </View>
607
622
  )}
608
- </View>
609
- </View>
610
- );
611
-
612
- return (
613
- <View style={style} onLayout={(e) => this.onContentLayout(e)}>
614
- {enableLabel && (
615
- <Label
616
- oneMarkerValue={valueOne}
617
- twoMarkerValue={valueTwo}
618
- oneMarkerLeftPosition={positionOne}
619
- twoMarkerLeftPosition={positionTwo}
620
- oneMarkerPressed={onePressed}
621
- twoMarkerPressed={twoPressed}
623
+ <MarkerRight
624
+ activeColor={activeColor}
625
+ pressed={twoPressed}
626
+ currentValue={valueTwo}
627
+ enabled={enabledTwo}
628
+ valuePrefix={valuePrefix}
629
+ valueSuffix={valueSuffix}
622
630
  />
631
+ </>
623
632
  )}
624
- {imageBackgroundSource && (
625
- <ImageBackground
626
- source={imageBackgroundSource}
627
- style={[styles.full, newContainerStyle]}
628
- >
629
- {body}
630
- </ImageBackground>
631
- )}
632
- {!imageBackgroundSource && (
633
- <View style={newContainerStyle}>{body}</View>
634
- )}
633
+ </View>
635
634
  </View>
636
- );
637
- }
635
+ )}
636
+ </View>
637
+ </View>
638
+ );
639
+
640
+ return (
641
+ <View style={style} onLayout={e => this.onContentLayout(e)}>
642
+ <View style={newContainerStyle}>{body}</View>
643
+ </View>
644
+ );
645
+ }
638
646
  }
639
647
 
640
648
  const styles = StyleSheet.create({
641
- container: {
642
- position: 'relative',
643
- height: 50,
644
- justifyContent: 'center'
645
- },
646
- fullTrack: {
647
- flexDirection: 'row',
648
- },
649
- track: {
650
- height: 4,
651
- backgroundColor: '#A7A7A7',
652
- },
653
- selectedTrack: {
654
- backgroundColor: Colors.primary,
655
- },
656
- markerContainer: {
657
- position: 'absolute',
658
- width: 48,
659
- height: 48,
660
- backgroundColor: 'transparent',
661
- justifyContent: 'center',
662
- alignItems: 'center',
663
- },
664
- topMarkerContainer: {
665
- zIndex: 1,
666
- },
667
- touch: {
668
- backgroundColor: 'transparent',
669
- justifyContent: 'center',
670
- alignItems: 'center',
671
- alignSelf: 'stretch',
672
- },
673
- full: { width: '100%', height: '100%' }
649
+ container: {
650
+ position: 'relative',
651
+ justifyContent: 'center',
652
+ minHeight: 48,
653
+ },
654
+ fullTrack: {
655
+ flexDirection: 'row',
656
+ },
657
+ track: {
658
+ height: 4,
659
+ backgroundColor: Colors.background_default,
660
+ borderRadius: 2,
661
+ },
662
+ selectedTrack: {
663
+ backgroundColor: Colors.pink_03,
664
+ },
665
+ markerContainer: {
666
+ position: 'absolute',
667
+ width: 64,
668
+ height: 52,
669
+ backgroundColor: 'transparent',
670
+ justifyContent: 'center',
671
+ alignItems: 'center',
672
+ },
673
+ topMarkerContainer: {
674
+ zIndex: 1,
675
+ },
676
+ touch: {
677
+ backgroundColor: 'transparent',
678
+ justifyContent: 'center',
679
+ alignItems: 'center',
680
+ alignSelf: 'stretch',
681
+ },
682
+ full: {
683
+ width: '100%',
684
+ height: '100%',
685
+ },
686
+ valueContainer: {
687
+ height: 24,
688
+ borderRadius: Spacing.XS,
689
+ backgroundColor: Colors.white,
690
+ justifyContent: 'center',
691
+ alignItems: 'center',
692
+ position: 'absolute',
693
+ top: -28,
694
+ paddingVertical: Spacing.XS,
695
+ paddingHorizontal: Spacing.S,
696
+ },
697
+ disabledTrack: {
698
+ backgroundColor: Colors.black_08,
699
+ },
674
700
  });
675
701
 
676
702
  Slider.defaultProps = {
677
- values: [0],
678
- onChangeStart: () => { },
679
- onChange: () => { },
680
- onChangeFinish: () => { },
681
- onMarkersPosition: () => { },
682
- step: 1,
683
- min: 0,
684
- max: 10,
685
- touchDimensions: {
686
- height: 50,
687
- width: 50,
688
- borderRadius: 15,
689
- slipDisplacement: 200,
690
- },
691
- customMarker: DefaultMarker,
692
- customMarkerLeft: DefaultMarker,
693
- customMarkerRight: DefaultMarker,
694
- customLabel: DefaultLabel,
695
- markerOffsetX: 0,
696
- markerOffsetY: 0,
697
- onToggleOne: undefined,
698
- onToggleTwo: undefined,
699
- enabledOne: true,
700
- enabledTwo: true,
701
- allowOverlap: false,
702
- snapped: false,
703
- vertical: false,
704
- minMarkerOverlapDistance: 0,
705
- length: 280
703
+ values: [0],
704
+ onChangeStart: () => {},
705
+ onChange: () => {},
706
+ onChangeFinish: () => {},
707
+ onMarkersPosition: () => {},
708
+ step: 1,
709
+ min: 0,
710
+ max: 10,
711
+ touchDimensions: {
712
+ height: 50,
713
+ width: 50,
714
+ borderRadius: 15,
715
+ slipDisplacement: 200,
716
+ },
717
+ markerOffsetX: 0,
718
+ markerOffsetY: 0,
719
+ onToggleOne: undefined,
720
+ onToggleTwo: undefined,
721
+ enabledOne: true,
722
+ enabledTwo: true,
723
+ allowOverlap: false,
724
+ snapped: false,
725
+ minMarkerOverlapDistance: 0,
726
+ length: 280,
727
+ activeColor: Colors.pink_03,
728
+ inactiveColor: Colors.black_03,
706
729
  };
707
730
 
708
731
  Slider.propTypes = {
709
- style: PropTypes.oneOfType([PropTypes.object, PropTypes.array]),
710
- selectedStyle: PropTypes.oneOfType([PropTypes.object, PropTypes.array]),
711
- unselectedStyle: PropTypes.oneOfType([PropTypes.object, PropTypes.array]),
712
- markerOffsetX: PropTypes.number,
713
- markerOffsetY: PropTypes.number,
714
- values: PropTypes.arrayOf(PropTypes.number),
715
- customMarker: PropTypes.func,
716
- customMarkerLeft: PropTypes.func,
717
- customMarkerRight: PropTypes.func,
718
- isMarkersSeparated: PropTypes.bool,
719
- touchDimensions: PropTypes.object,
720
- containerStyle: PropTypes.oneOfType([PropTypes.object, PropTypes.array]),
721
- vertical: PropTypes.bool,
722
- trackStyle: PropTypes.oneOfType([PropTypes.object, PropTypes.array]),
723
- markerContainerStyle: PropTypes.oneOfType([PropTypes.object, PropTypes.array]),
724
- enabledOne: PropTypes.bool,
725
- enabledTwo: PropTypes.bool,
726
- onChangeStart: PropTypes.func,
727
- onChange: PropTypes.func,
728
- onChangeFinish: PropTypes.func,
729
- onMarkersPosition: PropTypes.func,
730
- step: PropTypes.number,
731
- min: PropTypes.number,
732
- max: PropTypes.number,
733
- customLabel: PropTypes.any,
734
- onToggleOne: PropTypes.func,
735
- onToggleTwo: PropTypes.func,
736
- allowOverlap: PropTypes.bool,
737
- snapped: PropTypes.bool,
738
- minMarkerOverlapDistance: PropTypes.number,
739
- length: PropTypes.number,
740
- allowRange: PropTypes.arrayOf(PropTypes.number)
732
+ activeColor: PropTypes.string,
733
+ inactiveColor: PropTypes.string,
734
+ style: PropTypes.oneOfType([PropTypes.object, PropTypes.array]),
735
+ markerOffsetX: PropTypes.number,
736
+ markerOffsetY: PropTypes.number,
737
+ values: PropTypes.arrayOf(PropTypes.number),
738
+ isMarkersSeparated: PropTypes.bool,
739
+ touchDimensions: PropTypes.object,
740
+ containerStyle: PropTypes.oneOfType([PropTypes.object, PropTypes.array]),
741
+ markerContainerStyle: PropTypes.oneOfType([
742
+ PropTypes.object,
743
+ PropTypes.array,
744
+ ]),
745
+ enabledOne: PropTypes.bool,
746
+ enabledTwo: PropTypes.bool,
747
+ onChangeStart: PropTypes.func,
748
+ onChange: PropTypes.func,
749
+ onChangeFinish: PropTypes.func,
750
+ onMarkersPosition: PropTypes.func,
751
+ step: PropTypes.number,
752
+ min: PropTypes.number,
753
+ max: PropTypes.number,
754
+ onToggleOne: PropTypes.func,
755
+ onToggleTwo: PropTypes.func,
756
+ allowOverlap: PropTypes.bool,
757
+ snapped: PropTypes.bool,
758
+ minMarkerOverlapDistance: PropTypes.number,
759
+ length: PropTypes.number,
760
+ allowRange: PropTypes.arrayOf(PropTypes.number),
741
761
  };