Skip to content

Build every slider on the library's own BasicColorSlider - #354

Merged
smelfungus merged 7 commits into
masterfrom
own-slider
Sep 26, 2026
Merged

smelfungus merged 7 commits into
masterfrom
own-slider

Conversation

@smelfungus

@smelfungus smelfungus commented Sep 26, 2026 •

Copy link
Copy Markdown
Member

Every slider was built on Material 3's slot overload of Slider, which is experimental in material3 1.9.0 and was removed upstream (androidx b5fc89bd). A library compiled against it breaks at runtime once an app resolves a material3 without it. The sliders now run on the library's own slider, built from foundation modifiers as ChannelPlane already is.

BasicColorSlider

  • A public slider over 0..1 with no look of its own. It draws only its required track and thumb slots, which read its position, whether it is enabled, its interactions and the thumb's opaque color from a sealed ColorSliderScope.
  • It reproduces the Material slider's layout: the track is the width less the thumb's and starts half a thumb in, mirrored in right-to-left layouts.
  • A tap jumps to the point tapped. A drag starts past the touch slop and follows the finger's own position, so a caller whose value arrives late has it drawn and the drag carries on from the finger. A tap or drag is consumed, so a clickable card or row around the slider does not take it.
  • Left and Right move by step, swapped in right-to-left layouts; Page Up and Page Down by pageStep; Home and End to the ends. Up and Down are left alone so focus can move on. A screen reader steps by step, and a setProgress that changes nothing returns false.
  • Press, drag, focus and hover go to the one interactionSource, emitted in order. The press shows on a tap, a drag, a mouse button or a finger held still for 100 ms, so a scroll that starts on the slider leaves the thumb alone. A gesture cut off part-way, by disabling the slider, removing it or swapping its source, cancels its press and drag and reports its end.

The Material sliders

  • ColorSlider, ChannelSlider and AlphaSlider keep their look: the same gradient track, and a handle drawn as Material draws its own. The 27 screenshot baselines validate unchanged. The handle keeps its layout width while it narrows, so the track no longer shifts under a finger.
  • ColorSlider, ChannelSlider, AlphaSlider, ColorPlane and ChannelPlane take an interactionSource, and the pointer handlers are keyed on it. A plane torn down mid-drag cancels its drag on the source and ends the state's interaction.

Behaviour changes (listed in the CHANGELOG):

  • Up and Down no longer move a slider.
  • ColorSlider's Page Up raises its value; Material's lowered it.
  • A screen reader moves ColorSlider and AlphaSlider a hundredth at a time.
  • A slider reports presses to its thumb, where Material's reported only drags.

Tests: colorpicker 303 JVM, 121 Android host, 121 wasm; color 216, 206, 206; color-compose 14, 14, 14. apiCheck, the iOS klib compile, the Android sample and the 27 screenshot previews pass.

Every slider is built on Material 3's slot overload of Slider, which is experimental in the material3 the library uses and was removed upstream in androidx b5fc89bd; a library compiled against it breaks at runtime once an app resolves a material3 without it. BasicColorSlider is the replacement, built from foundation modifiers as ChannelPlane already is, with its look left to a track slot and a thumb slot that read a sealed ColorSliderScope.

Up and Down are not among its keys: a horizontal slider that kept them trapped focus on D-pad devices, which is why Material reverted the same change (b/460912699). Page Up raises the value, where Material's handler lowers it. Keys step from the last value they reported until a composition answers it, so a batch of presses moves as far as it should.
A drag reports the finger's position each time rather than stepping from the value, so a caller whose value arrives late has it drawn and the drag carries on from the finger. A tap is a lift over the slider before the touch slop; a finger lifted elsewhere, or a gesture a scrolling parent takes, reports nothing.

A press is reported the moment a finger lands. A gesture torn down part-way, as when the slider is disabled under the finger, cancels its press and its drag, or a thumb drawn from the caller's source would stay pressed. The handler is keyed on the source, because one kept across a new source goes on reporting to the old one.
Material's slot overload of Slider is experimental in material3 1.9.0 and removed upstream, so ColorSlider, ChannelSlider and AlphaSlider move onto the library's own slider. The look stays: the same track, and a handle drawn as Material draws its own. The 27 screenshot baselines validate unchanged. The handle keeps its layout width while it narrows, so the track no longer shifts by 2 dp under a finger.

Up and Down no longer move a slider, so focus can leave a column of them on a D-pad device. ColorSlider's Page Up raises its value, and a screen reader moves ColorSlider and AlphaSlider by their 0.01 key step, where Material left the increment to the platform.
A thumb could already read its component's source, but a caller could not supply one, so nothing outside a component could observe its interactions or share a source with it. The plane's pointer handler is now keyed on the source as well: a handler kept across a new source went on reporting to the old one.
A tap on a slider inside a clickable card or list row also clicked the row: the down and the tap's up went unconsumed, where Material's tap detector consumed both. The slider consumes them; a scrolling parent still starts from a consumed down.

Interactions were emitted from a remembered coroutine scope, which is cancelled with the component, so a slider removed mid-drag never cancelled its press or drag on a caller's source, and a thumb reading it stayed pressed. They are emitted with tryEmit, in order. A gesture cut off without a cancel event, as when the source is swapped mid-drag, reports its end too, and a plane disabled mid-drag cancels its drag and ends the state's interaction.

Arrow keys stepped from the last value they reported until a recomposition, and a caller that clamped a value back to the one it had caused none, so the keys drifted off the drawn value. The unanswered step is state read in composition, so every step recomposes and is dropped there.
The press was reported the moment a finger landed, so every vertical scroll that started on a slider in a list flashed its thumb: the default handle narrowed and a custom thumb that lifts on press rose, until the scroll took the touch and cancelled it. The press now shows on a tap, on a drag, or once a finger has rested for 100 ms, which is Android's tap timeout and what clickable waits inside a scrolling container; a mouse button, which starts no scroll, shows it at once.
onValueChangeFinished is also called when a tap ends, which the sliders' KDoc, the picker's and the README left out. ColorSlider's KDoc did not mention Home and End or that Up and Down are left for focus, as the channel and alpha sliders' does. SliderInteractionGuard's KDoc said a slider removed mid-drag never reports its end; it usually does, through the cancel event its pointer handler receives, and the guard covers the case where the handler is cancelled instead.
@smelfungus
smelfungus merged commit 77beec4 into master Sep 26, 2026
2 checks passed
@smelfungus
smelfungus deleted the own-slider branch September 26, 2026 05:48
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant