-
Notifications
You must be signed in to change notification settings - Fork 296
Expand file tree
/
Copy pathReactSliderManagerImpl.java
More file actions
174 lines (145 loc) · 6.28 KB
/
ReactSliderManagerImpl.java
File metadata and controls
174 lines (145 loc) · 6.28 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
package com.reactnativecommunity.slider;
import static com.facebook.drawee.drawable.RoundedCornersDrawable.Type.CLIPPING;
import android.graphics.PorterDuff;
import android.graphics.PorterDuffColorFilter;
import android.graphics.drawable.Drawable;
import android.graphics.drawable.LayerDrawable;
import android.os.Build;
import com.facebook.drawee.drawable.RoundedCornersDrawable;
import com.facebook.react.bridge.ReadableArray;
import com.facebook.react.bridge.ReadableMap;
import com.facebook.react.common.MapBuilder;
import com.facebook.react.uimanager.ThemedReactContext;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import javax.annotation.Nullable;
public class ReactSliderManagerImpl {
public static final String REACT_CLASS = "RNCSlider";
public static ReactSlider createViewInstance(ThemedReactContext context) {
ReactSlider slider = new ReactSlider(context, null);
if (Build.VERSION.SDK_INT >= 21) {
/**
* The "splitTrack" parameter should have "false" value,
* otherwise the SeekBar progress line doesn't appear when it is rotated.
*/
slider.setSplitTrack(false);
}
return slider;
}
public static void setValue(ReactSlider view, double value) {
if (view.isSliding() == false) {
view.setValue(value);
if (view.isAccessibilityFocused() && Build.VERSION.SDK_INT > Build.VERSION_CODES.Q) {
view.setupAccessibility((int)value);
}
}
}
public static void setMinimumValue(ReactSlider view, double value) {
view.setMinValue(value);
}
public static void setMaximumValue(ReactSlider view, double value) {
view.setMaxValue(value);
}
public static void setLowerLimit(ReactSlider view, double value) {
view.setLowerLimit(value);
}
public static void setUpperLimit(ReactSlider view, double value) {
view.setUpperLimit(value);
}
public static void setStep(ReactSlider view, double value) {
view.setStep(value);
}
public static void setDisabled(ReactSlider view, boolean disabled) {
view.setEnabled(!disabled);
}
public static void setThumbTintColor(ReactSlider view, Integer color) {
if (view.getThumb() != null) {
if (color == null) {
view.getThumb().clearColorFilter();
} else {
view.getThumb().setColorFilter(color, PorterDuff.Mode.SRC_IN);
}
}
}
public static void setMinimumTrackTintColor(ReactSlider view, Integer color) {
LayerDrawable drawable = (LayerDrawable) view.getProgressDrawable().getCurrent();
Drawable progress = drawable.findDrawableByLayerId(android.R.id.progress);
if (color == null) {
progress.clearColorFilter();
} else {
if (Build.VERSION.SDK_INT > Build.VERSION_CODES.P) {
progress.setColorFilter(new PorterDuffColorFilter((int)color, PorterDuff.Mode.SRC_IN));
}
else {
progress.setColorFilter(color, PorterDuff.Mode.SRC_IN);
}
}
}
public static void setThumbImage(ReactSlider view, @Nullable ReadableMap source) {
String uri = null;
if (source != null) {
uri = source.getString("uri");
}
view.setThumbImage(uri);
}
public static void setMaximumTrackTintColor(ReactSlider view, Integer color) {
LayerDrawable drawable = (LayerDrawable) view.getProgressDrawable().getCurrent();
Drawable background = drawable.findDrawableByLayerId(android.R.id.background);
if (color == null) {
background.clearColorFilter();
} else {
if (Build.VERSION.SDK_INT > Build.VERSION_CODES.P) {
background.setColorFilter(new PorterDuffColorFilter((int)color, PorterDuff.Mode.SRC_IN));
}
else {
background.setColorFilter(color, PorterDuff.Mode.SRC_IN);
}
}
}
public static void setInverted(ReactSlider view, boolean inverted) {
if (inverted) view.setScaleX(-1f);
else view.setScaleX(1f);
}
public static void setAccessibilityUnits(ReactSlider view, String accessibilityUnits) {
view.setAccessibilityUnits(accessibilityUnits);
}
public static void setAccessibilityIncrements(ReactSlider view, ReadableArray accessibilityIncrements) {
List objectList = accessibilityIncrements.toArrayList();
List<String> stringList = new ArrayList<>();
for(Object item: objectList) {
stringList.add((String)item);
}
view.setAccessibilityIncrements(stringList);
}
public static Map<String, Object> getExportedCustomBubblingEventTypeConstants() {
return MapBuilder.of(
ReactSliderEvent.EVENT_NAME, MapBuilder.of("registrationName", ReactSliderEvent.EVENT_NAME)
);
}
public static Map<String, Object> getExportedCustomDirectEventTypeConstants() {
return MapBuilder.of(
ReactSlidingStartEvent.EVENT_NAME, MapBuilder.of("registrationName", ReactSlidingStartEvent.EVENT_NAME),
ReactSlidingCompleteEvent.EVENT_NAME, MapBuilder.of("registrationName", ReactSlidingCompleteEvent.EVENT_NAME)
);
}
public static void setSliderThickness(ReactSlider view, double value) {
LayerDrawable drawable = (LayerDrawable) view.getProgressDrawable().getCurrent();
for (int i = 0; i < drawable.getNumberOfLayers(); i ++ ) {
// 0 is max/background progress; 1 is ???; 2 is min/current progress
drawable.setLayerHeight(i, (int) value);
}
}
public static void setSliderCornerRoundness(ReactSlider view, double value) {
LayerDrawable drawable = (LayerDrawable) view.getProgressDrawable().getCurrent();
for (int i = 0; i < drawable.getNumberOfLayers(); i ++ ) {
RoundedCornersDrawable newDrawable = new RoundedCornersDrawable(drawable.getDrawable(i));
newDrawable.setRadius((float) value);
newDrawable.setType(CLIPPING);
drawable.setDrawable(i, newDrawable);
}
}
public static void setThumbSize(ReactSlider view, double w, double h) {
view.thumbDrawable.setDimension(w, h);
}
}