Repository navigation
Expose Slider and RangeSlider OnValueChangeFinished - #429
Open
davidortinau wants to merge 1 commit into
Open
davidortinau wants to merge 1 commit into
davidortinau wants to merge 1 commit into
Conversation
Add an optional OnValueChangeFinished (Action?) to Slider and RangeSlider, forwarded to the bound Material 3 onValueChangeFinished that both facades passed as null. Apps can now run work once a drag, tap, key press or accessibility set-progress ends instead of on every onValueChange step. Leaving it unset keeps the Kotlin default. ComposeFacadeGenerator now surfaces a nullable IFunction0? bridge parameter as an optional Action? on the tree and direct surfaces, through the existing optional-callback lowering: RememberAction and the cleared $default bit only when supplied. Slider marks the slot [FacadeAdded], so the previous Composables.Slider signature and its direct helper remain. Add generator and binary-compatibility tests, device tests driven by real MotionEvents, a Gallery demo, public API entries and docs. Fixes jonathanpeppers#428 Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01WnVZbQvGRyjADVNbVVTgwD
There was a problem hiding this comment.
🔵 Needs a closer look
The Android touch tests and Gallery demo were compiled but not run, leaving callback ordering and identity stability during drag and recomposition unverified on a device or emulator.
No open issues 🎉
What changed in this PR
Adds optional OnValueChangeFinished callbacks to Slider and RangeSlider, addressing #428 so apps can defer work until a value change ends.
Changes:
- Extends facade generation to expose nullable
IFunction0callbacks as optionalActionproperties and parameters. - Wires both sliders to the existing Material 3 callbacks while preserving omitted-callback behavior and the previous
Composables.Sliderbinary signature. - Adds API documentation, generator and compatibility tests, touch-input device tests, and a Gallery demo.
The PR reports a successful solution build and 559 passing generator tests. Device tests and the Gallery demo were not run on a device or emulator.
| File | Description |
|---|---|
src/Microsoft.AndroidX.Compose/Slider.cs |
Documents completion-callback usage. |
src/Microsoft.AndroidX.Compose/RangeSlider.cs |
Adds and forwards the optional completion callback. |
src/Microsoft.AndroidX.Compose/PublicAPI.Unshipped.txt |
Records new properties and compatible Slider overloads. |
src/Microsoft.AndroidX.Compose/ComposeBridges.cs |
Forwards Slider’s callback to the bound API. |
src/Microsoft.AndroidX.Compose.SourceGenerators/ComposeFacadeGenerator.cs |
Generates optional zero-argument callback surfaces and adapters. |
src/Microsoft.AndroidX.Compose.SourceGenerators.Tests/FacadeGeneratorTests.cs |
Tests nullable callback generation and masks. |
src/Microsoft.AndroidX.Compose.SourceGenerators.Tests/FacadeAddedCompatibilityTests.cs |
Tests legacy compatibility and callback default handling. |
src/Microsoft.AndroidX.Compose.Gallery/Registry/Catalog.cs |
Registers the completion-callback demo. |
src/Microsoft.AndroidX.Compose.Gallery/Demos/Selection/SliderChangeFinishedDemo.cs |
Demonstrates live versus committed slider values. |
src/Microsoft.AndroidX.Compose.DeviceTests/SliderValueChangeFinishedTests.cs |
Adds touch-input timing and callback-refresh tests. |
src/Microsoft.AndroidX.Compose.DeviceTests/SliderValueChangeFinishedTestActivity.cs |
Hosts sliders for native input tests. |
src/Microsoft.AndroidX.Compose.DeviceTests/SliderTouchBounds.cs |
Supplies screen coordinates for injected touch events. |
.github/copilot-instructions.md |
Documents optional callback classification and changed-mask behavior. |
Review effort: Balanced
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.
SliderandRangeSlideralways passonValueChangeFinished: nullto Material 3, so C# apps can't run work once a drag, tap, key press or accessibility set-progress ends. This adds an optionalOnValueChangeFinishedto both, following the existing optionalSliderproperties (ValueRange,Colors,Thumb).API
Leaving it unset keeps today's behavior: the Kotlin default bit stays set and Kotlin uses its
nulldefault.Approach
ComposeFacadeGeneratorclassified everyIFunction0as a required constructorAction. A nullableIFunction0?now becomes an optionalAction?on every surface: a tree property, and an optional parameter on the explicit and implicit direct methods. It goes through the existing optional-callback lowering ([Callback]IFunction1?slots such asonTextLayout):RememberActiononly when supplied, so the peer is identity-stable and the latest delegate runs, and the$defaultbit is cleared only when supplied. Non-nullableIFunction0is unchanged, and no existing generated facade had a nullableIFunction0?parameter. The per-slot[Callback]unboxing moved into a sharedCallbackAdapterBodyhelper, and the sevenCallbackType is not nullsites now useHasCallbackWrapper.Slider:[FacadeAdded] IFunction0? onValueChangeFinishedon the existing wrapper passthrough, forwarded to the boundSliderKt.Slider.[FacadeAdded]keeps the oldComposables.SliderCLR signature and its direct helper; they leave the bit set and passdefault.RangeSlider(hand-written): anAction?property lowered withcomposer.RememberAction, clearingRangeSliderDefault.OnValueChangeFinishedonly when set.onValueChangeFinished, and the peer is the existingMutableComposableLambda0.Slider/RangeSliderXML docs, the classification and changed-bit rows in.github/copilot-instructions.md, and a Gallery demo (selection-slider-change-finished).docs/api-coverage.mdis per symbol andSlider/RangeSliderwere already covered, so it doesn't change.Validation
dotnet build Microsoft.AndroidX.Compose.slnx: 0 warnings, 0 errors (.NET SDK 11.0.100-rc.2.26504.105).dotnet test src/Microsoft.AndroidX.Compose.SourceGenerators.Tests: 559 passed. Two new tests fail with the generator change reverted:NullableFunction0_IsOptionalActionOnEverySurfacepins the tree property, its constructor (unchanged), the conditionalRememberAction, the default-bit clearing and the changed bits on the tree and direct surfaces.AddedOptionalActionKeepsOldContractsAndKotlinDefaultUntilSuppliedloads compiled consumers: a binary built against the old contract and the same source rebuilt both still call the legacy overload, which keeps the Kotlin default bit set. The tree property and the new direct overload clear the bit only when a callback is supplied.Sliderfacade (EmitCompilerGeneratedFiles) matches:if (OnValueChangeFinished is not null) __defaults &= ~...OnValueChangeFinished,RememberActiononly when set, and the legacyComposables.Sliderpassesdefaultwith the bit left set.SliderValueChangeFinishedTests(4 tests) inject realMotionEventdrags and taps into aSlider, aRangeSliderand a slider without the callback. They check that the callback waits for the release, runs exactly once after the lastonValueChange, and calls the latest delegate after a recomposition. They also check that a slider without the callback still drags. They compile in the solution build. I did not run them; no device or emulator was used for this PR.selection-slider-change-finishedbuilds; not run on a device.Not verified: any device or emulator run (device tests, Gallery), Release/R8 or NativeAOT, physical devices, TalkBack, or keyboard input.
Fixes #428
🤖 Generated with Claude Code
https://claude.ai/code/session_01WnVZbQvGRyjADVNbVVTgwD