Repository navigation
feat: save and restore the grid layout automatically through a storage provider (#411) - #525
Open
michaelstonis wants to merge 3 commits into
Open
michaelstonis wants to merge 3 commits into
michaelstonis wants to merge 3 commits into
Conversation
This branch has not been deployed
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.
Closes #411.
Stacked on #505: until that PR merges, this one also shows its commits.
Changes
Setting
LayoutStateKeyon the MAUI or Uno grid restores the layout saved under that key once, when the grid is attached, and then saves it again after the user changes it. The logic is in Core (KumikoLayoutAutoSave, internal); the hosts add the properties, a default store, a timer and the way back onto the UI thread.Loaded) and a key is set. A store that answers at once (the default stores) puts the layout back before the first frame; a later answer is applied on the UI thread when it arrives, and a newer key or an unload cancels it. Changes made before the restore finishes are not saved, andSaveLayoutStateAsync()does nothing then, so the defaults can never overwrite a saved layout. If the grid has no columns yet (generated from items) the restore waits for them (AutoGeneratedColumnsandColumnschanges) and applies one UI turn later. Applying the layout is not a change, saves nothing and makes no announcement (the hosts'Announceis muted while it runs). Restore happens once per key, not on every re-attach.SortColumnsChanged,FilterChanged,ColumnsChanged(visibility, freeze, order),ColumnOrderChanged, group descriptions, and, whenLayoutStateOptionsasks for the part,GroupExpandedChanged, the selection'sSelectionChangedandCurrentCellChanged,ScrollState.ScrollChanged, and the hosts' summary-row collection handlers. Width has no public event, soKumikoSourceraises a new internalColumnWidthChangedfrom the existing column property hook (KumikoSource.Columns.cs).LayoutSaveDelay; a change during the window only marks it busy, and a timer that finds the window busy arms again. Saving happens after a whole delay with no change (so a resize drag or a scroll writes once, and a continuous scroll allocates nothing per event). The save also runs when the grid is removed from the page, on key change (under the old key, then the new key loads), and fromSaveLayoutStateAsync().ValueTaskis read at once, otherwise a continuation posts back to the UI thread. Writes are serialized and never overlap or reorder; while one is in flight only the newest later snapshot is kept.JsonException), a store that throws or faults, a layout that cannot be applied and a capture failure are caught and raised asLayoutStateError(KumikoLayoutStateErrorEventArgs:OperationLoad/Restore/Save,Key,Exception) and traced. The grid keeps its layout; the next change overwrites a corrupt value. A throwing error handler is caught too.Preferences(Android, iOS, Mac Catalyst); on Windows a JSON file inFileSystem.AppDataDirectory, because a Windows settings value is limited to a few kilobytes. The file store (KumikoFileLayoutStore, internal, in Core) hashes the key into the file name and replaces the file atomically.ApplicationData.Current.LocalSettings, with a file inApplicationData.Current.LocalFolderfor a layout over 3800 characters (the 8 KB per value limit), marked by a settings flag so a short layout is read synchronously. Both are Uno's own implementations of the API on every target (checked:net10.0-desktop,net10.0-browserwasmandnet10.0compile; the code was not run on a device or in a browser). Not available: an unpackaged WinAppSDK app, whereApplicationData.Currentthrows; the error is reported throughLayoutStateErrorand the app setsLayoutStateStore. Documented in the README and onLayoutStateStore.LayoutStateKey="Samples.Grouping".src/KumikoUI.Core/Input/and noKumikoRenderer*.cswas touched.Public API added (
PublicAPI.Unshipped.txt)IKumikoLayoutStore(LoadAsync,SaveAsync),KumikoLayoutStateErrorEventArgs,KumikoLayoutStateOperation.KumikoDataGrid:LayoutStateKey,LayoutStateStore,LayoutSaveDelay,LayoutStateOptions(bindable and dependency properties, each with its...Propertyfield),LayoutStateErrorevent,SaveLayoutStateAsync().Deviations from the issue text
LayoutChangedonKumikoSourceis not added: the task forbids new input hooks and the existing events are enough, so the aggregation is internal toKumikoLayoutAutoSave. It could be exposed later.LayoutStateOptions(which parts to save, from Layout state: save and restore expanded groups, selection, scroll position and summary rows #354), which the issue does not list.tests/KumikoUI.Core.Tests/KumikoLayoutAutoSaveTests.csrather thanKumikoLayoutStateTests.cs; host tests are intests/KumikoUI.Maui.Tests/KumikoDataGridLayoutAutoSaveTests.cs.TestDispatchernow records the timers it creates so a host test can fire the one a grid started.Acceptance criteria
LayoutChangedfires once per user change (see deviation: the debounced save fires once per burst, tested with a 13-step resize drag, single changes and a 200-change instant burst); debounced save; flush on unload; restore before user interaction (synchronous store applied on attach; async store applied when it answers, changes before that ignored); key change (old key saved, new loaded, stale timer saves nothing); corrupt JSON ignored and overwritten by the next save; store exceptions (synchronous, faulted task, throwing error handler, failing default store) do not crash. Tests are deterministic: fake clock-free timer, fake UI-thread queue, fake stores.IKumikoLayoutStore. Custom store: tested on MAUI host and Core. MAUI default store: compiled fornet10.0-maccatalyst; itsPreferencespath is not runnable in the xUnit host (the test checks the failure is reported, not thrown). Uno: compiles on desktop, browserwasm andnet10.0; the Uno host andUnoLayoutStorehave no test (the Uno test project does not compileKumikoDataGrid), the shared Core logic is covered. Nothing was run on a device.LayoutStateKey(Uno sample builds; the MAUI sample does not build on this machine for an unrelated restore error, see Verification).PublicAPI.Unshipped.txtupdated for Core, Maui and Uno (lines taken from the RS0016 diagnostics, as in Layout state: save and restore expanded groups, selection, scroll position and summary rows #354).AnnounceChangeson, an announcement throws on the test host, and a restored sorted layout does not).Verification
dotnet build src/KumikoUI.Core --no-incremental: 0 warnings, 0 errors.dotnet build src/KumikoUI.SkiaSharp --no-incremental: 0 warnings, 0 errors.dotnet build src/KumikoUI.Maui -f net10.0-maccatalyst --no-incremental: 0 warnings, 0 errors.dotnet build src/KumikoUI.Uno -f net10.0-desktop --no-incremental: 0 errors; the only 2 warnings are the existingUno0001ones in files this change does not touch.-f net10.0-browserwasmand-f net10.0also build with 0 errors.dotnet build samples/SampleApp.Uno -f net10.0-desktop: succeeded (same 2 existing warnings).dotnet build samples/SampleApp.Maui -f net10.0-maccatalyst: fails at restore with NU1605 (package downgrade), unrelated; not built here.dotnet test tests/KumikoUI.Core.Tests: 4421 passed, 5 skipped (37 new).dotnet test tests/KumikoUI.Maui.Tests: 464 passed (13 new).dotnet test tests/KumikoUI.Uno.Tests: 321 passed.dotnet test tests/KumikoUI.SkiaSharp.Tests: 42 passed.nullfor the store andConsole.WriteLinefor the error, so both documentation snippet projects build with 0 errors.