react-native-gizwits-scroll-ruler 1.0.16 → 1.0.19

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);
@@ -29,6 +29,7 @@
29
29
 
30
30
  #import "RCTScrollRuler.h"
31
31
 
32
+
32
33
  /**
33
34
  * 绘制三角形标示
34
35
  */
@@ -40,6 +41,13 @@
40
41
  @end
41
42
  @implementation DYTriangleView
42
43
 
44
+ +(NSString*)valueString:(double)value ByStep:(float)step{
45
+ if(step < 0.1){
46
+ return [NSString stringWithFormat:@"%.1f",value];
47
+ }
48
+ return [NSString stringWithFormat:@"%d", (int)value];
49
+ }
50
+
43
51
  -(void)drawRect:(CGRect)rect{
44
52
  //设置背景颜色
45
53
  [_bgColor set];
@@ -75,21 +83,21 @@
75
83
  @interface DYRulerView : UIView
76
84
 
77
85
  @property (nonatomic,assign)NSInteger betweenNumber;
78
- @property (nonatomic,assign)int minValue;
79
- @property (nonatomic,assign)int maxValue;
86
+ @property (nonatomic,assign)double minValue;
87
+ @property (nonatomic,assign)double maxValue;
80
88
  @property (nonatomic,assign)float step;
81
89
 
82
90
  @end
83
91
  @implementation DYRulerView
84
92
 
85
- -(void)setMaxValue:(int)maxValue{
93
+ -(void)setMaxValue:(double)maxValue{
86
94
  if(_maxValue != maxValue){
87
95
  _maxValue = maxValue;
88
96
  [self setNeedsDisplay];
89
97
  }
90
98
  }
91
99
 
92
- -(void)setMinValue:(int)minValue{
100
+ -(void)setMinValue:(double)minValue{
93
101
  if(_minValue != minValue){
94
102
  _minValue = minValue;
95
103
  [self setNeedsDisplay];
@@ -107,9 +115,9 @@
107
115
  [super drawRect:rect];
108
116
  CGFloat startX = 0;
109
117
  CGFloat lineCenterX = RulerGap;
110
- CGFloat shortLineY = rect.size.height - RulerLong;
111
- CGFloat longLineY = rect.size.height - RulerShort;
112
- CGFloat topY = 0;
118
+ // CGFloat shortLineY = rect.size.height - RulerLong;
119
+ // CGFloat longLineY = rect.size.height - RulerShort;
120
+ // CGFloat topY = 0;
113
121
 
114
122
  CGContextRef context = UIGraphicsGetCurrentContext();
115
123
  CGContextSetRGBStrokeColor(context, (float)0/255.0, (float)0/255.0, (float)0/255.0, 1.0);//设置线的颜色,默认是黑色
@@ -120,10 +128,7 @@
120
128
 
121
129
  if (i%_betweenNumber == 0){
122
130
  CGContextMoveToPoint(context, startX+lineCenterX*i, RulerShort);
123
- NSString *num = [NSString stringWithFormat:@"%d", (int)(i * _step) + _minValue];
124
- if ([num isEqualToString:@"0"]) {
125
- num = @"0";
126
- }
131
+ NSString *num = [DYTriangleView valueString:(i * _step) + _minValue ByStep:_step];
127
132
  NSDictionary *attribute = @{NSFontAttributeName:TextRulerFont, NSForegroundColorAttributeName:TextRulerFontColor};
128
133
  CGFloat width = [num boundingRectWithSize:CGSizeMake(CGFLOAT_MAX, CGFLOAT_MAX) options:0 attributes:attribute context:nil].size.width;
129
134
  [num drawInRect:CGRectMake(startX+lineCenterX*i-width/2, 0, width, 16) withAttributes:attribute];
@@ -143,7 +148,9 @@
143
148
 
144
149
  @interface DYHeaderRulerView : UIView
145
150
 
146
- @property(nonatomic,assign)int minValue;
151
+ @property(nonatomic,assign)double minValue;
152
+
153
+ @property(nonatomic,assign)float step;
147
154
 
148
155
  @end
149
156
 
@@ -151,7 +158,7 @@
151
158
 
152
159
  -(void)drawRect:(CGRect)rect{
153
160
 
154
- CGFloat longLineY = rect.size.height - RulerShort;
161
+ // CGFloat longLineY = rect.size.height - RulerShort;
155
162
  CGContextRef context = UIGraphicsGetCurrentContext();
156
163
  CGContextSetRGBStrokeColor(context, (float)0/255.0, (float)0/255.0,(float)0/255.0, 1.0);
157
164
  CGContextSetLineWidth(context, LineWidth);
@@ -160,13 +167,7 @@
160
167
  CGContextMoveToPoint(context, rect.size.width, RulerShort);
161
168
  CGContextAddLineToPoint(context, rect.size.width, rect.size.height-LineWidth/2);
162
169
 
163
- NSString *num;
164
- if (_minValue == 0) {
165
- num = @"0";
166
- } else {
167
- num = [NSString stringWithFormat:@"%d", _minValue];
168
- }
169
-
170
+ NSString *num = [DYTriangleView valueString:_minValue ByStep:_step];
170
171
  NSDictionary *attribute = @{NSFontAttributeName:TextRulerFont,NSForegroundColorAttributeName:TextRulerFontColor};
171
172
  CGFloat width = [num boundingRectWithSize:CGSizeMake(CGFLOAT_MAX, CGFLOAT_MAX) options:0 attributes:attribute context:nil].size.width;
172
173
  [num drawInRect:CGRectMake(rect.size.width-width/2, 0, width, 16) withAttributes:attribute];
@@ -183,11 +184,14 @@
183
184
  @interface DYFooterRulerView : UIView
184
185
 
185
186
  @property(nonatomic,assign)int maxValue;
187
+
188
+ @property(nonatomic,assign)float step;
189
+
186
190
  @end
187
191
  @implementation DYFooterRulerView
188
192
 
189
193
  -(void)drawRect:(CGRect)rect{
190
- CGFloat longLineY = rect.size.height - RulerShort;
194
+ // CGFloat longLineY = rect.size.height - RulerShort;
191
195
  CGContextRef context = UIGraphicsGetCurrentContext();
192
196
  CGContextSetRGBStrokeColor(context, (float)0/255.0, (float)0/255.0, (float)0/255.0, 1.0);
193
197
  CGContextSetLineWidth(context, LineWidth);
@@ -195,7 +199,7 @@
195
199
 
196
200
  CGContextMoveToPoint(context, 0, RulerShort);//起始点
197
201
  CGContextAddLineToPoint(context, 0, rect.size.height-LineWidth/2);
198
- NSString *num = [NSString stringWithFormat:@"%d",_maxValue];
202
+ NSString *num = [DYTriangleView valueString:_maxValue ByStep:_step];
199
203
  NSDictionary *attribute = @{NSFontAttributeName:TextRulerFont,NSForegroundColorAttributeName:TextRulerFontColor};
200
204
  CGFloat width = [num boundingRectWithSize:CGSizeMake(CGFLOAT_MAX, CGFLOAT_MAX) options:0 attributes:attribute context:nil].size.width;
201
205
  [num drawInRect:CGRectMake(0-width/2, 0, width, 16) withAttributes:attribute];
@@ -298,8 +302,8 @@
298
302
  - (void)setDefaultValue:(double)defaultValue {
299
303
  NSLog(@"设置默认值");
300
304
  _defaultValue = defaultValue;
301
- if (_maxValue != 0) {
302
- double dv = ((defaultValue - _minValue)*10)/round(_step*10);
305
+ if (_maxValue != 0 && !_scrollByHand) {
306
+ double dv = ((defaultValue - _minValue)*100)/round(_step*100);
303
307
  int v = (int)dv;
304
308
  [self setRealValue:v animated:YES];
305
309
  // [_collectionView setContentOffset:CGPointMake(((defaultValue-_minValue)/(float)_step)*RulerGap, 0) animated:YES];
@@ -463,7 +467,11 @@
463
467
 
464
468
  -(void)setValueToValueLabel:(float)value{
465
469
  if(_step < 1.0){
466
- _valueLab.text = [NSString stringWithFormat:@"%.1f",value];
470
+ if(_step < 0.1){
471
+ _valueLab.text = [NSString stringWithFormat:@"%.2f",value];
472
+ } else {
473
+ _valueLab.text = [NSString stringWithFormat:@"%.1f",value];
474
+ }
467
475
  } else{
468
476
  _valueLab.text = [NSString stringWithFormat:@"%d",(int)roundf(value)];
469
477
  }
@@ -487,7 +495,8 @@
487
495
  self.headerView = headerView;
488
496
  [cell.contentView addSubview:headerView];
489
497
  }
490
-
498
+ headerView.minValue = _minValue;
499
+ headerView.step = _step;
491
500
  return cell;
492
501
  }else if( indexPath.item == _stepNum +1){
493
502
  UICollectionViewCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:@"footerCell" forIndexPath:indexPath];
@@ -496,11 +505,12 @@
496
505
  footerView = [[DYFooterRulerView alloc]initWithFrame:CGRectMake(0, 0, self.frame.size.width/2, CollectionHeight)];
497
506
  footerView.backgroundColor = [UIColor clearColor];
498
507
  footerView.tag = 1001;
499
- footerView.maxValue = _maxValue;
508
+
500
509
  self.footerView = footerView;
501
510
  [cell.contentView addSubview:footerView];
502
511
  }
503
-
512
+ footerView.maxValue = _maxValue;
513
+ footerView.step = _step;
504
514
  return cell;
505
515
  }else{
506
516
  UICollectionViewCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:@"custemCell" forIndexPath:indexPath];
@@ -513,8 +523,8 @@
513
523
  }
514
524
  rulerView.backgroundColor = _bgColor;
515
525
  rulerView.step = _step;
516
- rulerView.minValue = (int)(_step*(indexPath.item-1)*_betweenNum+_minValue);
517
- rulerView.maxValue = (int)(_step*indexPath.item*_betweenNum);
526
+ rulerView.minValue = (_step*(indexPath.item-1)*_betweenNum+_minValue);
527
+ rulerView.maxValue = (_step*indexPath.item*_betweenNum);
518
528
  // [rulerView setNeedsDisplay];
519
529
 
520
530
  return cell;
@@ -606,8 +616,7 @@
606
616
  [self.collectionView reloadData];
607
617
  [self setDefaultValue:_defaultValue];
608
618
  }
609
-
610
-
619
+ [self.collectionView setContentOffset:CGPointMake(_realValue*RulerGap, 0) animated:NO];
611
620
  [super layoutSubviews];
612
621
  }
613
622
  @end
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "react-native-gizwits-scroll-ruler",
3
- "version": "1.0.16",
4
- "description": "iOS更新bug修复",
3
+ "version": "1.0.19",
4
+ "description": "iOS支持 0.01",
5
5
  "main": "index.js",
6
6
  "scripts": {
7
7
  "test": "echo \"Error: no test specified\" && exit 1"