-
Notifications
You must be signed in to change notification settings - Fork 33
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
lumen/LMN-420 update Range slider to support custom thumb with label (#…
…1745) * lumen/LMN-420_update_slider_to_provide_custom_thumb * Updated snapshots for 'rtl' * Updated snapshots for 'default' * LMN-420 Remove custom semantics There was an issue where this was announcing various different slider options with percentage/value based content. This provided a confusing user behaviour. The current behaviour isn't perfect, but we'd need to build a completely custom slider to solve this. We can create an issue for the slider to improve. the API/accessibility support * added missing liecnes --------- Co-authored-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com> Co-authored-by: Maria Neumayer <[email protected]>
- Loading branch information
1 parent
b3fcffa
commit 5c2c71a
Showing
10 changed files
with
227 additions
and
15 deletions.
There are no files selected for viewing
Binary file added
BIN
+5.07 KB
...default/net.skyscanner.backpack.compose.slider.BpkSliderTest_rangeWithLabel.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+4.92 KB
...bug/rtl/net.skyscanner.backpack.compose.slider.BpkSliderTest_rangeWithLabel.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
156 changes: 156 additions & 0 deletions
156
...ose/src/main/kotlin/net/skyscanner/backpack/compose/slider/internal/BpkRangeSliderImpl.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,156 @@ | ||
/* | ||
* Backpack for Android - Skyscanner's Design System | ||
* | ||
* Copyright 2018 Skyscanner Ltd | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
* | ||
*/ | ||
package net.skyscanner.backpack.compose.slider.internal | ||
|
||
import androidx.compose.foundation.background | ||
import androidx.compose.foundation.interaction.MutableInteractionSource | ||
import androidx.compose.foundation.layout.Arrangement | ||
import androidx.compose.foundation.layout.Column | ||
import androidx.compose.foundation.layout.Spacer | ||
import androidx.compose.foundation.layout.height | ||
import androidx.compose.foundation.layout.padding | ||
import androidx.compose.material3.ExperimentalMaterial3Api | ||
import androidx.compose.material3.RangeSlider | ||
import androidx.compose.material3.SliderDefaults | ||
import androidx.compose.runtime.Composable | ||
import androidx.compose.runtime.remember | ||
import androidx.compose.ui.Alignment | ||
import androidx.compose.ui.ExperimentalComposeUiApi | ||
import androidx.compose.ui.Modifier | ||
import androidx.compose.ui.semantics.invisibleToUser | ||
import androidx.compose.ui.semantics.semantics | ||
import androidx.compose.ui.semantics.stateDescription | ||
import androidx.compose.ui.text.style.TextAlign | ||
import net.skyscanner.backpack.compose.flare.BpkFlarePointerDirection | ||
import net.skyscanner.backpack.compose.text.BpkText | ||
import net.skyscanner.backpack.compose.theme.BpkTheme | ||
import net.skyscanner.backpack.compose.tokens.BpkBorderRadius | ||
import net.skyscanner.backpack.compose.tokens.BpkSpacing | ||
import net.skyscanner.backpack.compose.utils.FlareShape | ||
|
||
@OptIn(ExperimentalMaterial3Api::class) | ||
@Composable | ||
internal fun BpkRangeSliderImpl( | ||
value: ClosedFloatingPointRange<Float>, | ||
onValueChange: (ClosedFloatingPointRange<Float>) -> Unit, | ||
enabled: Boolean, | ||
minValue: Float, | ||
maxValue: Float, | ||
steps: Int, | ||
onValueChangeFinished: (() -> Unit)?, | ||
modifier: Modifier = Modifier, | ||
lowerThumbLabel: String? = null, | ||
upperThumbLabel: String? = null, | ||
) { | ||
val startInteractionSource = remember { MutableInteractionSource() } | ||
val endInteractionSource = remember { MutableInteractionSource() } | ||
RangeSlider( | ||
value = value, | ||
onValueChange = onValueChange, | ||
modifier = modifier, | ||
enabled = enabled, | ||
startInteractionSource = startInteractionSource, | ||
endInteractionSource = endInteractionSource, | ||
valueRange = minValue..maxValue, | ||
steps = steps, | ||
onValueChangeFinished = onValueChangeFinished, | ||
startThumb = { | ||
lowerThumbLabel?.let { | ||
SlideRangeLabel( | ||
label = it, | ||
enabled = enabled, | ||
interactionSource = startInteractionSource, | ||
) | ||
} ?: SliderDefaults.Thumb( | ||
interactionSource = startInteractionSource, | ||
colors = sliderColors(), | ||
enabled = enabled, | ||
) | ||
}, | ||
endThumb = { | ||
upperThumbLabel?.let { | ||
SlideRangeLabel( | ||
label = it, | ||
enabled = enabled, | ||
interactionSource = endInteractionSource, | ||
) | ||
} ?: SliderDefaults.Thumb( | ||
interactionSource = endInteractionSource, | ||
colors = sliderColors(), | ||
enabled = enabled, | ||
) | ||
}, | ||
colors = sliderColors(), | ||
) | ||
} | ||
|
||
@OptIn(ExperimentalComposeUiApi::class) | ||
@Composable | ||
private fun SlideRangeLabel( | ||
enabled: Boolean, | ||
label: String, | ||
interactionSource: MutableInteractionSource, | ||
modifier: Modifier = Modifier, | ||
) { | ||
Column( | ||
modifier = modifier | ||
.semantics { stateDescription = label } | ||
.padding(bottom = BpkSpacing.Xl), | ||
verticalArrangement = Arrangement.Center, | ||
horizontalAlignment = Alignment.CenterHorizontally, | ||
) { | ||
BpkText( | ||
text = label, | ||
color = BpkTheme.colors.textPrimaryInverse, | ||
style = BpkTheme.typography.label2, | ||
textAlign = TextAlign.Center, | ||
modifier = Modifier | ||
.background( | ||
color = BpkTheme.colors.coreAccent, | ||
shape = FlareShape( | ||
borderRadius = BpkBorderRadius.Sm, | ||
flareHeight = BpkSpacing.Sm, | ||
pointerDirection = BpkFlarePointerDirection.Down, | ||
), | ||
) | ||
.padding(top = BpkSpacing.Sm) | ||
.padding(bottom = BpkSpacing.Md) | ||
.padding(horizontal = BpkSpacing.Md) | ||
.semantics { invisibleToUser() }, | ||
|
||
) | ||
Spacer( | ||
modifier = Modifier.height(BpkSpacing.Sm), | ||
) | ||
SliderDefaults.Thumb( | ||
interactionSource = interactionSource, | ||
colors = sliderColors(), | ||
enabled = enabled, | ||
) | ||
} | ||
} | ||
|
||
@Composable | ||
internal fun sliderColors() = SliderDefaults.colors( | ||
thumbColor = BpkTheme.colors.coreAccent, | ||
activeTrackColor = BpkTheme.colors.coreAccent, | ||
inactiveTrackColor = BpkTheme.colors.line, | ||
activeTickColor = BpkTheme.colors.coreAccent, | ||
inactiveTickColor = BpkTheme.colors.line, | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.