From 9138f9d7f6293cf48fdda9c87638e6e523930498 Mon Sep 17 00:00:00 2001 From: Rehmat Singh Gill Date: Fri, 20 Nov 2026 13:55:11 -0800 Subject: [PATCH] feat(wave): support independent corner radii --- CHANGELOG.md | 5 +++ doc/distortion_wave.md | 3 +- doc/distortion_wave_usage.md | 10 ++++-- example/pubspec.lock | 2 +- lib/src/distortion_wave/distortion_wave.dart | 15 ++++++++ .../render/render_wave_stage.dart | 17 ++++++++-- pubspec.yaml | 2 +- .../widget/distortion_wave_test.dart | 34 +++++++++++++++++++ 8 files changed, 80 insertions(+), 8 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 4ce96cb..602da53 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -3,6 +3,11 @@ All notable changes to this package are documented here, following [Keep a Changelog](https://keepachangelog.com/en/1.1.0/). +## 0.4.0 + +- Add `DistortionWave.cornerRadii` for surfaces with independent corner + radii, including inset sheets. + ## 0.3.0 The first release on pub.dev. Two shader effects for Flutter, built for diff --git a/doc/distortion_wave.md b/doc/distortion_wave.md index be2609c..3c3aac1 100644 --- a/doc/distortion_wave.md +++ b/doc/distortion_wave.md @@ -184,7 +184,8 @@ Per pixel, in the stage's logical coordinates (see the shader's header): ### The edges' corners -`RenderWaveStage._corners`: when the widget passed the display's radii +`RenderWaveStage._corners` uses `DistortionWave.cornerRadii` when supplied. +Otherwise, when the widget passed the display's radii (`MediaQuery.maybeDisplayCornerRadiiOf`, only when no style or theme sets `WaveGlow.cornerRadius`) and the stage fills the view (global origin and `MediaQuery.sizeOf` size, within half a pixel), each corner takes the diff --git a/doc/distortion_wave_usage.md b/doc/distortion_wave_usage.md index 537f2d1..eca1287 100644 --- a/doc/distortion_wave_usage.md +++ b/doc/distortion_wave_usage.md @@ -73,6 +73,7 @@ const DistortionWave({ WaveSource? source, WaveType? type, WavePalette? palette, + BorderRadius? cornerRadii, WaveStyle? style, DistortionWaveController? controller, double? progress, // asserted 0–1 @@ -90,6 +91,7 @@ const DistortionWave({ | `source` | Where the wave opens from. Null → the anchor rules below. Read only when a run starts from rest. | | `type` | Shorthand for `style.type`; wins over it. | | `palette` | Shorthand for `style.palette`; wins over it. | +| `cornerRadii` | Explicit per-corner superellipse radii for the surface, including inset surfaces. Takes precedence over the display corners and `WaveGlow.cornerRadius`. | | `style` | Everything else; over the nearest `DistortionWaveTheme`'s style, over the type's tuned defaults. | | `controller` | Attached, it owns playback; `revealed` is ignored. | | `progress` | Non-null holds the wave at that point of its life (0–1) instead of animating. Back to null plays on from the held point toward `revealed` (or the controller's `isRevealed`). | @@ -471,8 +473,12 @@ fields to 0–1, `blur` to 0–64, `returnSpeed` to 0.01–100, dot `count` to ## Display corners -A wave that **fills the view** puts its edge colour and hairline on the -display's own corners, each corner its own radius, read from +Use `DistortionWave.cornerRadii` when a surface has its own set of corner +radii. A sheet can give the wave its top corners and the display's bottom +corners. + +Without explicit radii, a wave that **fills the view** puts its edge colour +and hairline on the display's corners, read from `MediaQuery.displayCornerRadii` (via `MediaQuery.maybeDisplayCornerRadiiOf`). "Fills the view" means the wave's top-left is at the global origin and its size equals `MediaQuery.sizeOf` (both within half a pixel). Otherwise — a diff --git a/example/pubspec.lock b/example/pubspec.lock index c060d3f..4792414 100644 --- a/example/pubspec.lock +++ b/example/pubspec.lock @@ -174,7 +174,7 @@ packages: path: ".." relative: true source: path - version: "0.3.0" + version: "0.4.0" sky_engine: dependency: transitive description: flutter diff --git a/lib/src/distortion_wave/distortion_wave.dart b/lib/src/distortion_wave/distortion_wave.dart index 79b199c..2c0af78 100644 --- a/lib/src/distortion_wave/distortion_wave.dart +++ b/lib/src/distortion_wave/distortion_wave.dart @@ -63,6 +63,7 @@ class DistortionWave extends StatefulWidget { this.source, this.type, this.palette, + this.cornerRadii, this.style, this.controller, this.progress, @@ -97,6 +98,12 @@ class DistortionWave extends StatefulWidget { /// Its colours; shorthand for `style.palette`, and wins over it. final WavePalette? palette; + /// Individual superellipse corner radii of the surface the wave fills. + /// + /// Takes precedence over display corners and `WaveGlow.cornerRadius`. + /// Works for both full-screen and inset surfaces. + final BorderRadius? cornerRadii; + /// Everything else about its look, over the nearest /// [DistortionWaveTheme]'s style, over the tuned defaults of its type. final WaveStyle? style; @@ -144,6 +151,7 @@ class DistortionWave extends StatefulWidget { DiagnosticsProperty('source', source, defaultValue: null), ) ..add(EnumProperty('type', type, defaultValue: null)) + ..add(DiagnosticsProperty('cornerRadii', cornerRadii)) ..add(DiagnosticsProperty('style', style, defaultValue: null)) ..add(DoubleProperty('progress', progress, defaultValue: null)); } @@ -389,6 +397,7 @@ class _DistortionWaveState extends State snapshots: _snapshots, plain: _reducedMotion(), revealing: _revealing, + cornerRadii: widget.cornerRadii, displayRadii: _followsDisplay ? MediaQuery.maybeDisplayCornerRadiiOf(context) : null, @@ -416,6 +425,7 @@ class WaveStage this.snapshots = WaveSnapshots.onChange, this.plain = false, this.revealing = false, + this.cornerRadii, this.displayRadii, this.viewSize, this.outgoing, @@ -443,6 +453,9 @@ class WaveStage /// Whether the wave is heading for [incoming]. final bool revealing; + /// The surface's explicit corner radii, if supplied. + final BorderRadius? cornerRadii; + /// The display's corner radii, for edges that follow them while the stage /// fills the view; null when the style sets its own radius. final BorderRadius? displayRadii; @@ -474,6 +487,7 @@ class WaveStage snapshots: snapshots, plain: plain, revealing: revealing, + cornerRadii: cornerRadii, displayRadii: displayRadii, viewSize: viewSize, ); @@ -488,6 +502,7 @@ class WaveStage ..snapshots = snapshots ..plain = plain ..revealing = revealing + ..cornerRadii = cornerRadii ..displayRadii = displayRadii ..viewSize = viewSize; } diff --git a/lib/src/distortion_wave/render/render_wave_stage.dart b/lib/src/distortion_wave/render/render_wave_stage.dart index 04656b0..8c26ac6 100644 --- a/lib/src/distortion_wave/render/render_wave_stage.dart +++ b/lib/src/distortion_wave/render/render_wave_stage.dart @@ -65,6 +65,7 @@ class RenderWaveStage extends RenderBox this._snapshots = WaveSnapshots.onChange, this._plain = false, this._revealing = false, + this._cornerRadii, this._displayRadii, this._viewSize, }); @@ -145,6 +146,16 @@ class RenderWaveStage extends RenderBox markNeedsPaint(); } + BorderRadius? _cornerRadii; + + /// Explicit corner radii for the wave, independent of the stage's position. + BorderRadius? get cornerRadii => _cornerRadii; + set cornerRadii(BorderRadius? value) { + if (value == _cornerRadii) return; + _cornerRadii = value; + markNeedsPaint(); + } + BorderRadius? _displayRadii; /// The display's corner radii, when the edges should follow them: set when @@ -167,10 +178,10 @@ class RenderWaveStage extends RenderBox markNeedsPaint(); } - /// The corners the edges follow this frame: the display's — each corner - /// its own — while the stage fills the view and the display reports them; - /// else the spec's radius on all four. + /// The explicit corners, the display's corners for a full-view stage, or + /// the spec's radius on all four corners. BorderRadius get _corners { + if (_cornerRadii case final corners?) return corners; final radii = _displayRadii; final view = _viewSize; if (radii != null && view != null && attached && hasSize) { diff --git a/pubspec.yaml b/pubspec.yaml index 175a0d3..667a113 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -3,7 +3,7 @@ description: >- Shader effects for Flutter: BorderBeam, light around a widget's border, and DistortionWave, a wave carrying one screen into another. Built for Impeller; also runs on Skia and web. -version: 0.3.0 +version: 0.4.0 repository: https://github.com/SimplifyJobs/prismatic issue_tracker: https://github.com/SimplifyJobs/prismatic/issues homepage: https://github.com/SimplifyJobs/prismatic diff --git a/test/distortion_wave/widget/distortion_wave_test.dart b/test/distortion_wave/widget/distortion_wave_test.dart index 9b46ccc..2d39203 100644 --- a/test/distortion_wave/widget/distortion_wave_test.dart +++ b/test/distortion_wave/widget/distortion_wave_test.dart @@ -24,6 +24,7 @@ void main() { bool maintainState = true, WaveStyle? style, WavePalette? palette, + BorderRadius? cornerRadii, WaveSource? source, Widget? child, Widget? revealedChild, @@ -35,6 +36,7 @@ void main() { maintainState: maintainState, style: style, palette: palette, + cornerRadii: cornerRadii, source: source, revealedChild: revealedChild ?? flatSide(incomingColor, 'in'), child: child ?? flatSide(outgoingColor, 'out'), @@ -955,6 +957,38 @@ void main() { ); }); + testWidgets('explicit corners apply to an inset wave and update in place', ( + tester, + ) async { + useWaveView(tester); + const corners = BorderRadius.only( + topLeft: Radius.circular(32), + topRight: Radius.circular(32), + bottomLeft: Radius.circular(54), + bottomRight: Radius.circular(40), + ); + const uniform = WaveStyle(glow: WaveGlow(cornerRadius: 20)); + + Widget insetWave(BorderRadius? radii) => waveHost( + Padding( + padding: const EdgeInsets.only(top: 40), + child: wave(progress: 0.5, cornerRadii: radii, style: uniform), + ), + displayCornerRadii: BorderRadius.circular(50), + ); + + await tester.pumpWidget(insetWave(corners)); + final stage = waveStage(tester); + expect(stage.debugCorners, corners); + + final folded = corners.copyWith(bottomRight: Radius.zero); + await tester.pumpWidget(insetWave(folded)); + expect(stage.debugCorners, folded); + + await tester.pumpWidget(insetWave(null)); + expect(stage.debugCorners, BorderRadius.circular(20)); + }); + testWidgets('starts no ticker until it runs, and stops when it arrives', ( tester, ) async {