Skip to content

Commit 8675839

Browse files
Evyraadwojteg1337
authored andcommitted
Inverted slider android
1 parent ae961f2 commit 8675839

File tree

4 files changed

+34
-20
lines changed

4 files changed

+34
-20
lines changed

README.md

Lines changed: 10 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -73,12 +73,12 @@ Check out the [example project](example) for more examples.
7373
- [`maximumTrackTintColor`](#maximumtracktintcolor)
7474
- [`testID`](#testid)
7575
- [`value`](#value)
76+
- [`inverted`](#inverted)
7677
- [`thumbTintColor`](#thumbtintcolor)
7778
- [`maximumTrackImage`](#maximumtrackimage)
7879
- [`minimumTrackImage`](#minimumtrackimage)
7980
- [`thumbImage`](#thumbimage)
8081
- [`trackImage`](#trackimage)
81-
- [`inverted`](#inverted)
8282

8383
---
8484

@@ -204,6 +204,15 @@ _This is not a controlled component_, you don't need to update the value during
204204

205205
---
206206

207+
### `inverted`
208+
Reverses the direction of the slider. Default value is false.
209+
210+
| Type | Required |
211+
| ---- | -------- |
212+
| bool | No |
213+
214+
---
215+
207216
### `thumbTintColor`
208217

209218
Color of the foreground switch grip.
@@ -222,8 +231,6 @@ Assigns a maximum track image. Only static images are supported. The leftmost pi
222231
| ---------------------- | -------- | -------- |
223232
| Image.propTypes.source | No | iOS |
224233

225-
---
226-
227234
### `minimumTrackImage`
228235

229236
Assigns a minimum track image. Only static images are supported. The rightmost pixel of the image will be stretched to fill the track.
@@ -252,15 +259,6 @@ Assigns a single image for the track. Only static images are supported. The cent
252259
| ---------------------- | -------- | -------- |
253260
| Image.propTypes.source | No | iOS |
254261

255-
---
256-
257-
### `inverted`
258-
Reverses the direction of the slider. Default value is false.
259-
260-
| Type | Required | Platform |
261-
| ---- | -------- | -------- |
262-
| bool | No | iOS |
263-
264262
## Maintainers
265263

266264
- [Michał Chudziak](https://github.com/michalchudziak) - [Callstack](https://callstack.com/)

android/src/main/java/com/reactnativecommunity/slider/ReactSliderManager.java

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77

88
package com.reactnativecommunity.slider;
99

10+
import android.os.Build;
1011
import android.graphics.PorterDuff;
1112
import android.graphics.drawable.Drawable;
1213
import android.graphics.drawable.LayerDrawable;
@@ -125,7 +126,17 @@ public Class getShadowNodeClass() {
125126

126127
@Override
127128
protected ReactSlider createViewInstance(ThemedReactContext context) {
128-
return new ReactSlider(context, null, STYLE);
129+
ReactSlider slider = new ReactSlider(context, null, STYLE);
130+
131+
if (Build.VERSION.SDK_INT >= 21) {
132+
/**
133+
* The "splitTrack" parameter should have "false" value,
134+
* otherwise the SeekBar progress line doesn't appear when it is rotated.
135+
*/
136+
slider.setSplitTrack(false);
137+
}
138+
139+
return slider;
129140
}
130141

131142
@ReactProp(name = ViewProps.ENABLED, defaultBoolean = true)
@@ -185,6 +196,12 @@ public void setMaximumTrackTintColor(ReactSlider view, Integer color) {
185196
background.setColorFilter(color, PorterDuff.Mode.SRC_IN);
186197
}
187198
}
199+
200+
@ReactProp(name = "inverted", defaultBoolean = false)
201+
public void setInverted(ReactSlider view, boolean inverted) {
202+
if (inverted) view.setScaleX(-1f);
203+
else view.setScaleX(1f);
204+
}
188205

189206
@Override
190207
protected void addEventEmitters(final ThemedReactContext reactContext, final ReactSlider view) {

example/SliderExample.js

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -193,7 +193,6 @@ exports.examples = [
193193
},
194194
{
195195
title: 'Inverted slider direction',
196-
platform: 'ios',
197196
render(): React.Element<any> {
198197
return <SliderExample value={0.6} inverted />;
199198
},

js/Slider.js

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -54,12 +54,6 @@ type IOSProps = $ReadOnly<{|
5454
* Sets an image for the thumb. Only static images are supported.
5555
*/
5656
thumbImage?: ?ImageSource,
57-
58-
/**
59-
* If true the slider will be inverted.
60-
* Default value is false.
61-
*/
62-
inverted?: ?boolean,
6357
|}>;
6458

6559
type Props = $ReadOnly<{|
@@ -146,6 +140,12 @@ type Props = $ReadOnly<{|
146140
* Used to locate this view in UI automation tests.
147141
*/
148142
testID?: ?string,
143+
144+
/**
145+
* If true the slider will be inverted.
146+
* Default value is false.
147+
*/
148+
inverted?: ?boolean,
149149
|}>;
150150

151151
/**

0 commit comments

Comments
 (0)