@momo-kits/slider 0.0.49-beta.7 → 0.0.50-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/Slider.js +42 -9
- package/package.json +2 -2
package/Slider.js
CHANGED
|
@@ -9,11 +9,13 @@ import {
|
|
|
9
9
|
Text,
|
|
10
10
|
} from 'react-native';
|
|
11
11
|
import { get } from 'lodash';
|
|
12
|
-
import { Colors, Spacing } from '@momo-kits/core';
|
|
12
|
+
import { Colors, Spacing, LocalizedStrings } from '@momo-kits/core';
|
|
13
13
|
import DefaultMarker from './DefaultMarker';
|
|
14
14
|
import DefaultLabel from './DefaultLabel';
|
|
15
15
|
import { createArray, valueToPosition, positionToValue } from './converters';
|
|
16
16
|
|
|
17
|
+
const LANGUAGE = LocalizedStrings.getLanguage();
|
|
18
|
+
|
|
17
19
|
export default class Slider extends Component {
|
|
18
20
|
constructor(props) {
|
|
19
21
|
super(props);
|
|
@@ -393,6 +395,34 @@ export default class Slider extends Component {
|
|
|
393
395
|
}
|
|
394
396
|
}
|
|
395
397
|
|
|
398
|
+
_nFormatter(num) {
|
|
399
|
+
let markerLabel = num;
|
|
400
|
+
let digits = 0;
|
|
401
|
+
|
|
402
|
+
if (markerLabel >= 1000000) {
|
|
403
|
+
digits = 1;
|
|
404
|
+
}
|
|
405
|
+
|
|
406
|
+
const lookup = [
|
|
407
|
+
{ value: 1000000, symbol: LANGUAGE == 'en' ? 'M' : 'Tr' },
|
|
408
|
+
{ value: 1000, symbol: 'K' },
|
|
409
|
+
{ value: 1, symbol: '' },
|
|
410
|
+
];
|
|
411
|
+
|
|
412
|
+
let item = lookup.slice().find((item) => {
|
|
413
|
+
return markerLabel >= item.value;
|
|
414
|
+
});
|
|
415
|
+
|
|
416
|
+
if (item) {
|
|
417
|
+
markerLabel =
|
|
418
|
+
(markerLabel / item.value).toFixed(digits) + item.symbol;
|
|
419
|
+
} else {
|
|
420
|
+
markerLabel = '0';
|
|
421
|
+
}
|
|
422
|
+
|
|
423
|
+
return markerLabel;
|
|
424
|
+
}
|
|
425
|
+
|
|
396
426
|
render() {
|
|
397
427
|
const {
|
|
398
428
|
positionOne,
|
|
@@ -457,12 +487,12 @@ export default class Slider extends Component {
|
|
|
457
487
|
|
|
458
488
|
const markerContainerOne = {
|
|
459
489
|
top: markerOffsetY - 24,
|
|
460
|
-
left: trackOneLength + markerOffsetX -
|
|
490
|
+
left: trackOneLength + markerOffsetX - 32,
|
|
461
491
|
};
|
|
462
492
|
|
|
463
493
|
const markerContainerTwo = {
|
|
464
494
|
top: markerOffsetY - 24,
|
|
465
|
-
right: trackThreeLength - markerOffsetX -
|
|
495
|
+
right: trackThreeLength - markerOffsetX - 32,
|
|
466
496
|
};
|
|
467
497
|
|
|
468
498
|
const newContainerStyle = [styles.container, containerStyle];
|
|
@@ -473,6 +503,9 @@ export default class Slider extends Component {
|
|
|
473
503
|
});
|
|
474
504
|
}
|
|
475
505
|
|
|
506
|
+
const markerLabel1 = this._nFormatter(valueOne);
|
|
507
|
+
const markerLabel2 = this._nFormatter(valueTwo);
|
|
508
|
+
|
|
476
509
|
const body = (
|
|
477
510
|
<View style={{ alignItems: 'center' }}>
|
|
478
511
|
<View style={[styles.fullTrack, { width: sliderLength }]}>
|
|
@@ -521,7 +554,7 @@ export default class Slider extends Component {
|
|
|
521
554
|
<>
|
|
522
555
|
{onePressed && enableLabel && (
|
|
523
556
|
<View style={styles.valueContainer}>
|
|
524
|
-
<Text>{
|
|
557
|
+
<Text>{markerLabel1}</Text>
|
|
525
558
|
</View>
|
|
526
559
|
)}
|
|
527
560
|
<Marker
|
|
@@ -541,7 +574,7 @@ export default class Slider extends Component {
|
|
|
541
574
|
<>
|
|
542
575
|
{onePressed && enableLabel && (
|
|
543
576
|
<View style={styles.valueContainer}>
|
|
544
|
-
<Text>{
|
|
577
|
+
<Text>{markerLabel2}</Text>
|
|
545
578
|
</View>
|
|
546
579
|
)}
|
|
547
580
|
<MarkerLeft
|
|
@@ -577,7 +610,7 @@ export default class Slider extends Component {
|
|
|
577
610
|
<>
|
|
578
611
|
{twoPressed && enableLabel && (
|
|
579
612
|
<View style={styles.valueContainer}>
|
|
580
|
-
<Text>{
|
|
613
|
+
<Text>{markerLabel2}</Text>
|
|
581
614
|
</View>
|
|
582
615
|
)}
|
|
583
616
|
<Marker
|
|
@@ -599,7 +632,7 @@ export default class Slider extends Component {
|
|
|
599
632
|
<>
|
|
600
633
|
{twoPressed && enableLabel && (
|
|
601
634
|
<View style={styles.valueContainer}>
|
|
602
|
-
<Text>{
|
|
635
|
+
<Text>{markerLabel2}</Text>
|
|
603
636
|
</View>
|
|
604
637
|
)}
|
|
605
638
|
<MarkerRight
|
|
@@ -661,7 +694,7 @@ const styles = StyleSheet.create({
|
|
|
661
694
|
},
|
|
662
695
|
markerContainer: {
|
|
663
696
|
position: 'absolute',
|
|
664
|
-
width:
|
|
697
|
+
width: 64,
|
|
665
698
|
height: 48,
|
|
666
699
|
backgroundColor: 'transparent',
|
|
667
700
|
justifyContent: 'center',
|
|
@@ -678,7 +711,6 @@ const styles = StyleSheet.create({
|
|
|
678
711
|
},
|
|
679
712
|
full: { width: '100%', height: '100%' },
|
|
680
713
|
valueContainer: {
|
|
681
|
-
width: 40,
|
|
682
714
|
height: 32,
|
|
683
715
|
borderRadius: Spacing.S,
|
|
684
716
|
backgroundColor: Colors.white,
|
|
@@ -694,6 +726,7 @@ const styles = StyleSheet.create({
|
|
|
694
726
|
shadowOpacity: 0.24,
|
|
695
727
|
shadowRadius: 6,
|
|
696
728
|
elevation: 12,
|
|
729
|
+
paddingHorizontal: 8,
|
|
697
730
|
},
|
|
698
731
|
});
|
|
699
732
|
|
package/package.json
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@momo-kits/slider",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.50-rc.1",
|
|
4
4
|
"private": false,
|
|
5
5
|
"main": "index.js",
|
|
6
6
|
"dependencies": {
|
|
7
|
-
"@momo-platform/versions": "4.0.
|
|
7
|
+
"@momo-platform/versions": "4.0.2"
|
|
8
8
|
},
|
|
9
9
|
"peerDependencies": {
|
|
10
10
|
"@momo-kits/core": ">=0.0.5-beta",
|