@@ -47,12 +47,12 @@ - (instancetype)initWithFrame:(CGRect)frame
47
47
forControlEvents: (UIControlEventTouchUpInside |
48
48
UIControlEventTouchUpOutside |
49
49
UIControlEventTouchCancel)];
50
-
50
+
51
51
UITapGestureRecognizer *tapGesturer;
52
52
tapGesturer = [[UITapGestureRecognizer alloc ] initWithTarget: self action: @selector (tapHandler: )];
53
53
[tapGesturer setNumberOfTapsRequired: 1 ];
54
54
[slider addGestureRecognizer: tapGesturer];
55
-
55
+
56
56
slider.value = (float )defaultProps->value ;
57
57
self.contentView = slider;
58
58
}
@@ -65,12 +65,12 @@ - (void)tapHandler:(UITapGestureRecognizer *)gesture {
65
65
}
66
66
RNCSlider *slider = (RNCSlider *)gesture.view ;
67
67
slider.isSliding = _isSliding;
68
-
68
+
69
69
// Ignore this tap if in the middle of a slide.
70
70
if (_isSliding) {
71
71
return ;
72
72
}
73
-
73
+
74
74
if (!slider.tapToSeek ) {
75
75
return ;
76
76
}
@@ -88,14 +88,14 @@ - (void)tapHandler:(UITapGestureRecognizer *)gesture {
88
88
}
89
89
90
90
[slider setValue: [slider discreteValue: value] animated: YES ];
91
-
91
+
92
92
std::dynamic_pointer_cast<const RNCSliderEventEmitter>(_eventEmitter)
93
93
->onRNCSliderSlidingStart (RNCSliderEventEmitter::OnRNCSliderSlidingStart{.value = static_cast <Float>(slider.lastValue )});
94
-
94
+
95
95
// Trigger onValueChange to address https://github.com/react-native-community/react-native-slider/issues/212
96
96
std::dynamic_pointer_cast<const RNCSliderEventEmitter>(_eventEmitter)
97
97
->onRNCSliderValueChange (RNCSliderEventEmitter::OnRNCSliderValueChange{.value = static_cast <Float>(slider.value )});
98
-
98
+
99
99
std::dynamic_pointer_cast<const RNCSliderEventEmitter>(_eventEmitter)
100
100
->onRNCSliderSlidingComplete (RNCSliderEventEmitter::OnRNCSliderSlidingComplete{.value = static_cast <Float>(slider.value )});
101
101
}
@@ -122,7 +122,7 @@ - (void)sliderTouchEnd:(RNCSlider *)sender
122
122
- (void )RNCSendSliderEvent : (RNCSlider *)sender withContinuous : (BOOL )continuous isSlidingStart : (BOOL )isSlidingStart
123
123
{
124
124
float value = [sender discreteValue: sender.value];
125
-
125
+
126
126
if (value < sender.lowerLimit ) {
127
127
value = sender.lowerLimit ;
128
128
[sender setValue: value animated: NO ];
@@ -134,7 +134,7 @@ - (void)RNCSendSliderEvent:(RNCSlider *)sender withContinuous:(BOOL)continuous i
134
134
if (!sender.isSliding ) {
135
135
[sender setValue: value animated: NO ];
136
136
}
137
-
137
+
138
138
if (continuous) {
139
139
if (sender.lastValue != value) {
140
140
std::dynamic_pointer_cast<const RNCSliderEventEmitter>(_eventEmitter)
@@ -150,15 +150,15 @@ - (void)RNCSendSliderEvent:(RNCSlider *)sender withContinuous:(BOOL)continuous i
150
150
->onRNCSliderSlidingStart (RNCSliderEventEmitter::OnRNCSliderSlidingStart{.value = static_cast <Float>(value)});
151
151
}
152
152
}
153
-
153
+
154
154
sender.lastValue = value;
155
155
}
156
156
157
157
- (void )updateProps : (const Props::Shared &)props oldProps : (const Props::Shared &)oldProps
158
158
{
159
159
const auto &oldScreenProps = *std::static_pointer_cast<const RNCSliderProps>(_props);
160
160
const auto &newScreenProps = *std::static_pointer_cast<const RNCSliderProps>(props);
161
-
161
+
162
162
if (oldScreenProps.value != newScreenProps.value ) {
163
163
if (!slider.isSliding ) {
164
164
slider.value = newScreenProps.value ;
@@ -176,12 +176,7 @@ - (void)updateProps:(const Props::Shared &)props oldProps:(const Props::Shared &
176
176
if (oldScreenProps.maximumValue != newScreenProps.maximumValue ) {
177
177
[slider setMaximumValue: newScreenProps.maximumValue];
178
178
}
179
- if (oldScreenProps.lowerLimit != newScreenProps.lowerLimit ) {
180
- slider.lowerLimit = newScreenProps.lowerLimit ;
181
- }
182
- if (oldScreenProps.upperLimit != newScreenProps.upperLimit ) {
183
- slider.upperLimit = newScreenProps.upperLimit ;
184
- }
179
+ updateLimits (slider, newScreenProps.lowerLimit , newScreenProps.upperLimit );
185
180
if (oldScreenProps.tapToSeek != newScreenProps.tapToSeek ) {
186
181
slider.tapToSeek = newScreenProps.tapToSeek ;
187
182
}
@@ -272,6 +267,21 @@ - (void)loadImageFromImageSource:(ImageSource)source completionBlock:(RNCLoadIma
272
267
}
273
268
}
274
269
270
+ void updateLimits (RNCSlider *slider, float newLowerLimit, float newUpperLimit) {
271
+ if (slider.lowerLimit != newLowerLimit) {
272
+ slider.lowerLimit = newLowerLimit;
273
+ }
274
+
275
+ if (slider.upperLimit != newUpperLimit) {
276
+ slider.upperLimit = newUpperLimit;
277
+ }
278
+
279
+ if (slider.lowerLimit > slider.upperLimit ) {
280
+ NSLog (@" Invalid configuration: lowerLimit > upperLimit, reverting lowerLimit to upperLimit." );
281
+ slider.lowerLimit = slider.upperLimit ;
282
+ }
283
+ }
284
+
275
285
- (void )setInverted : (BOOL )inverted
276
286
{
277
287
if (inverted) {
0 commit comments