Repository navigation
Settle the Material components' 2.0 shape: scoped thumbs, dimensions and nullable parts - #356
Merged
Merged
Conversation
As data classes, ColorPickerColors, ColorPickerShapes and ColorPickerDimensions could not gain a field after 2.0 without breaking componentN and copy for every caller compiled against them. They are final classes with a hand-written copy, which keeps a color or size left Unspecified and a shape left null, as Material's own classes do, and the defaults factories build through it so a call naming one value keeps the rest. The composition locals were public only to be read, which ColorPickerDefaults.current*() already does, so they leave the API.
A thumb handed only an InteractionSource could not see its slider's position, whether it was enabled or the color under it, so a custom thumb had to be fed them from outside, and a thumb over a translucent color had to make it opaque itself. Every slider and plane now passes its scope to its thumb, and its default is the library's own thumb, public as ColorPickerDefaults.SliderThumb and PlaneThumb. Sizes come in one dimensions parameter in place of thumbWidth, thumbTrackGap and ColorSlider's trackHeight, and ColorSlider takes a plain List of track colors, so kotlinx-collections-immutable leaves the dependencies.
showAlpha and a slot that could not be removed made two ways to say one thing, and left a picker's default slots built by internal functions its own default expressions called. The pickers and the dialog take null for a plane or alpha slider they should not draw, hand the plane its axes, and default their slots to ColorPickerDefaults.plane(), channelSlider() and alphaSlider(), which a caller can wrap. Every picker takes the orientation BasicColorPicker lays out and the dimensions its sliders and plane use; a new preview shows a horizontal picker, and the 27 existing baselines validate unchanged.
The README still showed showAlpha, thumb lambdas handed an InteractionSource and thumbWidth, none of which compile any more. It shows alphaSlider = null, the horizontal picker, a thumb reading its scope and dimensions copied from the theme, and the migration table maps each removed parameter to its replacement.
This file contains hidden or 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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Several of the Material components' signatures could not change after 2.0 without breaking callers: data classes for the theme, thumb slots that saw only an
InteractionSource, one parameter per size,showAlphabeside a slot that could not be removed, andImmutableListin a signature. This settles them over the Basic components from #355.Theme
ColorPickerColors,ColorPickerShapesandColorPickerDimensionsare final@Immutableclasses withcopy,equals,hashCodeandtoString, so a field can be added later.copykeeps a color or size leftUnspecifiedand a shape leftnull, andColorPickerDefaults.colors(),shapes()anddimensions()build through it, so naming one value keeps the scheme's others.LocalColorPickerColors,LocalColorPickerShapesandLocalColorPickerDimensionsare internal;ColorPickerDefaults.currentColors(),currentShapes()andcurrentDimensions()read them.Sliders and planes
thumbreads its component's scope:thumb = { MyThumb(interactionSource, thumbColor) }. The default isColorPickerDefaults.SliderThumborPlaneThumb, both public.dimensionsreplacesthumbWidth,thumbTrackGapandColorSlider'strackHeight.ColorSlidertakestrackColors: List<Color>, and kotlinx-collections-immutable is no longer a dependency.Pickers and the dialog
plane = nullandalphaSlider = nullleave those parts out, replacingshowPlaneandshowAlpha, and the plane slot is handed its axes.orientation, whereOrientation.Horizontalputs the plane beside the sliders, anddimensions.ColorPickerDefaults.plane(),channelSlider()andalphaSlider(), which a caller can wrap.The README, the docs page, the CHANGELOG and the migration table follow. A new screenshot preview shows the horizontal picker; the 27 existing baselines validate unchanged.
Tests: colorpicker 365 JVM, 126 Android host, 126 wasm; color 216, 206, 206; color-compose 14, 14, 14.
apiCheck, the iOS klib compile, the Android sample and the 28 screenshot previews pass.