Skip to content

Commit 5895d6a

Browse files
Custom thumb's component with additional props (#655)
* Add new fields to MarkerProps for custom component * Implement min, max and index into Custom Component value * Provide new custom component with the example in example app * Provide currentValue with defined value of Slider * Update package name ref in example lockfile * Fix the typing and styling * Adjust the pods lockfile * Remove the redundant example * Optimize the StepsIndicator a bit by rendering only the changed * Describe the custom components in details in README * Simplify README by not using the screenshots
1 parent a0bb8b5 commit 5895d6a

File tree

12 files changed

+333
-125
lines changed

12 files changed

+333
-125
lines changed
12.4 KB
Loading
7.1 KB
Loading
10.2 KB
Loading

README.md

Lines changed: 93 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -107,11 +107,102 @@ To use this library you need to ensure you are using the correct version of Reac
107107
| `minimumTrackImage` | Assigns a minimum track image. Only static images are supported. The rightmost pixel of the image will be stretched to fill the track. | Image<br/>.propTypes<br/>.source | No | iOS |
108108
| `thumbImage` | Sets an image for the thumb. Only static images are supported. Needs to be a URI of a local or network image; base64-encoded SVG is not supported. | Image<br/>.propTypes<br/>.source | No | |
109109
| `trackImage` | Assigns a single image for the track. Only static images are supported. The center pixel of the image will be stretched to fill the track. | Image<br/>.propTypes<br/>.source | No | iOS | |
110-
| ⚠️ **Experimental:**</br> `StepMarker` | Component to be rendered for each step on the track,<br/>with the possibility to change the styling, when thumb is at that given step | `FC<MarkerProps>`, <br/> where <br/> `MarkerProps`: `{stepMarked: boolean}` | No | iOS, Android, Windows |
111-
| ⚠️ **Experimental:**</br> `renderStepNumber` | Turns on the displaying of numbers of steps.<br/>Numbers of steps are displayed under the track | bool | No | iOS, Android, Windows |
110+
| [`StepMarker`](#stepmarker) | Component to be rendered for each step on the track,<br/>with the possibility to change the styling, when thumb is at that given step | `FC<MarkerProps>` | No | iOS, Android, Windows |
111+
| [`renderStepNumber`](#renderstepnumber) | Turns on the displaying of numbers of steps.<br/>Numbers of steps are displayed under the track | bool | No | iOS, Android, Windows |
112112
| `ref` | Reference object. | MutableRefObject | No | web |
113113
| `View` | [Inherited `View` props...](https://github.com/facebook/react-native-website/blob/master/docs/view.md#props) | | | |
114114

115+
## Custom step marker and step numbers
116+
117+
It is possible to render default step numbers under your slider and to render custom step component and step marker.
118+
<br/>This can be achieved by using:
119+
120+
### `renderStepNumber`
121+
122+
Turns on the displaying of numbers of steps.<br/>Numbers of steps are displayed under the track.
123+
<br/>Two font sizes are available and they will be selected automatically depending on the overall number of steps.
124+
125+
### `StepMarker`
126+
127+
Your custom component rendered for every step on the Slider, both the thumb and the rest of steps along the Slider's whole length.
128+
<br/>This `StepMarker` prop accepts your custom component and provides it with the following parameters:
129+
130+
<table>
131+
<tr>
132+
<td>
133+
134+
```typescript
135+
stepMarked: boolean;
136+
```
137+
138+
</td>
139+
<td>
140+
141+
Indicates whether that custom step is the one that the thum is currently on.
142+
<br/>If user drags or clicks on that step, thumb will be moved there and the `stepMarked` parameter will be set to `true`.
143+
<br/>Use it, to differentiate between rendering your custom thumb component, or your custom step marker.
144+
145+
</td>
146+
</tr>
147+
<tr>
148+
<td>
149+
150+
```typescript
151+
currentValue: number;
152+
```
153+
154+
</td>
155+
<td>
156+
Contains the `number` type saying at which value of the Slider the thumb currently is.
157+
<br/>Use it, for example, to render the Slider value on every step marker, or to render different step marker's variant depending on the Thumb position.
158+
159+
</td>
160+
</tr>
161+
<tr>
162+
<td>
163+
164+
```typescript
165+
index: number;
166+
```
167+
168+
</td>
169+
<td>
170+
171+
Contains the index at which this exact instantiation of your custom step marker was rendered at.
172+
<br/>Use it if you would like to render step number within the step marker, or, for example, if you want to render many variants of step marker depending on their positions along the Slider's width.
173+
174+
</td>
175+
</tr>
176+
<tr>
177+
<td>
178+
179+
```typescript
180+
min: number;
181+
```
182+
183+
</td>
184+
<td>
185+
186+
Minimum value of the Slider. It is equal to `minimumValue` and has the same default if not set.
187+
188+
</td>
189+
</tr>
190+
<tr>
191+
<td>
192+
193+
```typescript
194+
max: number;
195+
```
196+
197+
</td>
198+
<td>
199+
200+
Maximum value of the Slider. It is equal to `maximumValue` and has the same default if not set.
201+
202+
</td>
203+
</tr>
204+
</table>
205+
115206
## Roadmap and Progress
116207

117208
There's a Project board available [here](https://github.com/callstack/react-native-slider/projects/1) which contains all reported issues organized into columns regarding their status.

example/ios/Podfile.lock

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1806,10 +1806,10 @@ EXTERNAL SOURCES:
18061806

18071807
SPEC CHECKSUMS:
18081808
boost: 1dca942403ed9342f98334bf4c3621f011aa7946
1809-
DoubleConversion: fea03f2699887d960129cc54bba7e52542b6f953
1809+
DoubleConversion: f16ae600a246532c4020132d54af21d0ddb2a385
18101810
FBLazyVector: be7314029d6ec6b90f0f75ce1195b8130ed9ac4f
18111811
fmt: 10c6e61f4be25dc963c36bd73fc7b1705fe975be
1812-
glog: c5d68082e772fa1c511173d6b30a9de2c05a69a2
1812+
glog: 08b301085f15bcbb6ff8632a8ebaf239aae04e6a
18131813
hermes-engine: 0555a84ea495e8e3b4bde71b597cd87fbb382888
18141814
RCT-Folly: bf5c0376ffe4dd2cf438dcf86db385df9fdce648
18151815
RCTDeprecation: 2c5e1000b04ab70b53956aa498bf7442c3c6e497
@@ -1874,4 +1874,4 @@ SPEC CHECKSUMS:
18741874

18751875
PODFILE CHECKSUM: 1a52083da6c006694389963dc5ddd0deab10abc9
18761876

1877-
COCOAPODS: 1.15.2
1877+
COCOAPODS: 1.14.2

example/package-lock.json

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)