react-native-gizwits-scroll-ruler 1.0.15 → 1.0.18

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.
@@ -20,6 +20,7 @@ import android.view.animation.DecelerateInterpolator;
20
20
 
21
21
  import java.lang.ref.WeakReference;
22
22
  import java.math.BigDecimal;
23
+ import java.text.DecimalFormat;
23
24
 
24
25
  /**
25
26
  * @author shenhuniurou
@@ -33,7 +34,7 @@ public class RNScrollRuler extends View {
33
34
  /**
34
35
  * 2个大刻度之间间距,默认为1
35
36
  */
36
- private int scaleLimit = 10;
37
+ private float scaleLimit = 10;
37
38
  /**
38
39
  * 尺子高度
39
40
  */
@@ -202,7 +203,7 @@ public class RNScrollRuler extends View {
202
203
 
203
204
  TypedArray a = getContext().getTheme().obtainStyledAttributes(attrs, R.styleable.RulerView, defStyleAttr, 0);
204
205
 
205
- scaleLimit = a.getInt(R.styleable.RulerView_scaleLimit, scaleLimit);
206
+ scaleLimit = a.getFloat(R.styleable.RulerView_scaleLimit, scaleLimit);
206
207
  step = a.getFloat(R.styleable.RulerView_step, step);
207
208
 
208
209
  rulerHeight = a.getDimensionPixelSize(R.styleable.RulerView_rulerHeight, (int) TypedValue.applyDimension(
@@ -529,13 +530,19 @@ public class RNScrollRuler extends View {
529
530
 
530
531
  //这里是滑动时候不断回调给使用者的结果值
531
532
  int numberLength = getNumLength(step);
532
- BigDecimal bigDecimal = new WeakReference<>(new BigDecimal(((width / 2 - moveX) / (scaleGap * scaleCount) + minScale) * scaleLimit)).get().setScale(numberLength, BigDecimal.ROUND_HALF_UP);
533
+ String formatPattern = "0.";
534
+ for (int i =0; i<numberLength; i++) {
535
+ formatPattern += "0";
536
+ }
537
+ DecimalFormat fmt = new DecimalFormat(formatPattern);
538
+ float value = ((width / 2 - moveX) / (scaleGap * scaleCount) + minScale) * scaleLimit;
539
+
533
540
  if (numberLength > 0) {
534
- currentScale = bigDecimal.floatValue();
535
- resultText = String.valueOf(currentScale);
541
+ currentScale = Float.valueOf(resultText);
542
+ resultText = fmt.format(value);
536
543
  } else {
537
- currentScale = bigDecimal.intValue();
538
- resultText = String.valueOf((int) currentScale);
544
+ currentScale = (int) value;
545
+ resultText = (int) value + "";
539
546
  }
540
547
 
541
548
  if (onChooseResulterListener != null) {
@@ -550,7 +557,12 @@ public class RNScrollRuler extends View {
550
557
  //绘制刻度,绘制刻度数字
551
558
  canvas.drawLine(0, rulerHeight - midScaleHeight, 0, rulerHeight, midScalePaint);
552
559
  scaleNumPaint.getTextBounds(num1 / scaleGap + minScale + "", 0, (num1 / scaleGap + minScale + "").length(), scaleNumRect);
553
- canvas.drawText((num1 / scaleCount + minScale) * scaleLimit + "", 0, rulerHeight - midScaleHeight - scaleNumRect.height(), scaleNumPaint);
560
+ float subValue = (num1 / scaleCount + minScale) * scaleLimit;
561
+ String valueText = (int) subValue + "";
562
+ if (numberLength > 0) {
563
+ valueText = fmt.format(subValue);
564
+ }
565
+ canvas.drawText(valueText, 0, rulerHeight - midScaleHeight - scaleNumRect.height(), scaleNumPaint);
554
566
  }
555
567
 
556
568
  } else { //绘制小数刻度
@@ -739,7 +751,7 @@ public class RNScrollRuler extends View {
739
751
  }
740
752
 
741
753
  public void setScaleLimit(float step) {
742
- this.scaleLimit = (int)(step * 10);
754
+ this.scaleLimit = step * 10;
743
755
  this.step = step;
744
756
 
745
757
  this.setMinScale(this.rawMinScale);
@@ -298,7 +298,7 @@
298
298
  - (void)setDefaultValue:(double)defaultValue {
299
299
  NSLog(@"设置默认值");
300
300
  _defaultValue = defaultValue;
301
- if (_maxValue != 0) {
301
+ if (_maxValue != 0 && !_scrollByHand) {
302
302
  double dv = ((defaultValue - _minValue)*10)/round(_step*10);
303
303
  int v = (int)dv;
304
304
  [self setRealValue:v animated:YES];
@@ -453,7 +453,7 @@
453
453
  -(void)setRealValue:(int)realValue animated:(BOOL)animated{
454
454
  _realValue = realValue;
455
455
  float totalValue = _realValue*_step +_minValue;
456
- _valueLab.text = [NSString stringWithFormat:@"%.1f", totalValue];
456
+ [self setValueToValueLabel:totalValue];
457
457
  [_collectionView setContentOffset:CGPointMake(_realValue*RulerGap, 0) animated:animated];
458
458
  }
459
459
 
@@ -461,6 +461,15 @@
461
461
  return 30+20+CollectionHeight;
462
462
  }
463
463
 
464
+ -(void)setValueToValueLabel:(float)value{
465
+ if(_step < 1.0){
466
+ _valueLab.text = [NSString stringWithFormat:@"%.1f",value];
467
+ } else{
468
+ _valueLab.text = [NSString stringWithFormat:@"%d",(int)roundf(value)];
469
+ }
470
+ }
471
+
472
+
464
473
  #pragma mark UICollectionViewDataSource & Delegate
465
474
  - (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section
466
475
  {
@@ -532,24 +541,24 @@
532
541
 
533
542
  #pragma mark -UIScrollViewDelegate
534
543
  -(void)scrollViewDidScroll:(UIScrollView *)scrollView{
535
- int value = scrollView.contentOffset.x/RulerGap;
536
- float totalValue = value*_step +_minValue;
537
-
538
- if (self.delegate && [self.delegate respondsToSelector:@selector(dyScrollRulerView:valueChange:)]) {
539
- [self.delegate dyScrollRulerView:self valueChange:totalValue];
540
- }
541
544
 
542
545
  if (_scrollByHand) {
546
+ int value = scrollView.contentOffset.x/RulerGap;
547
+ float totalValue = value*_step +_minValue;
548
+
549
+ if (self.delegate && [self.delegate respondsToSelector:@selector(dyScrollRulerView:valueChange:)]) {
550
+ [self.delegate dyScrollRulerView:self valueChange:totalValue];
551
+ }
543
552
  if (totalValue >= _maxValue) {
544
- _valueLab.text = [NSString stringWithFormat:@"%.1f",(float)_maxValue];
553
+ [self setValueToValueLabel:(float)_maxValue];
545
554
  }else if(totalValue <= _minValue){
546
555
  if(_minValue == 0) {
547
- _valueLab.text = @"0.0";
556
+ [self setValueToValueLabel:0.0];
548
557
  } else {
549
- _valueLab.text = [NSString stringWithFormat:@"%.1f",(float)_minValue];
558
+ [self setValueToValueLabel:(float)_minValue];
550
559
  }
551
560
  }else{
552
- _valueLab.text = [NSString stringWithFormat:@"%.1f",(value*_step) +_minValue];
561
+ [self setValueToValueLabel:(value*_step) +_minValue];
553
562
  }
554
563
  }
555
564
  }
@@ -597,8 +606,7 @@
597
606
  [self.collectionView reloadData];
598
607
  [self setDefaultValue:_defaultValue];
599
608
  }
600
-
601
-
609
+ [self.collectionView setContentOffset:CGPointMake(_realValue*RulerGap, 0) animated:NO];
602
610
  [super layoutSubviews];
603
611
  }
604
612
  @end
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "react-native-gizwits-scroll-ruler",
3
- "version": "1.0.15",
4
- "description": "iOS更新bug修复",
3
+ "version": "1.0.18",
4
+ "description": "安卓支持 0.01",
5
5
  "main": "index.js",
6
6
  "scripts": {
7
7
  "test": "echo \"Error: no test specified\" && exit 1"