Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
3 changes: 2 additions & 1 deletion doc/distortion_wave.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
10 changes: 8 additions & 2 deletions doc/distortion_wave_usage.md
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@ const DistortionWave({
WaveSource? source,
WaveType? type,
WavePalette? palette,
BorderRadius? cornerRadii,
WaveStyle? style,
DistortionWaveController? controller,
double? progress, // asserted 0–1
Expand All @@ -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`). |
Expand Down Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion example/pubspec.lock
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,7 @@ packages:
path: ".."
relative: true
source: path
version: "0.3.0"
version: "0.4.0"
sky_engine:
dependency: transitive
description: flutter
Expand Down
15 changes: 15 additions & 0 deletions lib/src/distortion_wave/distortion_wave.dart
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ class DistortionWave extends StatefulWidget {
this.source,
this.type,
this.palette,
this.cornerRadii,
this.style,
this.controller,
this.progress,
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -144,6 +151,7 @@ class DistortionWave extends StatefulWidget {
DiagnosticsProperty<WaveSource>('source', source, defaultValue: null),
)
..add(EnumProperty<WaveType>('type', type, defaultValue: null))
..add(DiagnosticsProperty<BorderRadius>('cornerRadii', cornerRadii))

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P3: This nullable property is missing defaultValue: null, unlike source, style and progress above it. Add it so unset radii are omitted from diagnostics output.

Prompt for AI agents
Check if this issue is valid — if so, understand the root cause and fix it. When an issue isn't valid or won't be fixed in this PR, reply in its thread with the reason and then resolve the thread. At lib/src/distortion_wave/distortion_wave.dart, line 154:

<comment>This nullable property is missing `defaultValue: null`, unlike `source`, `style` and `progress` above it. Add it so unset radii are omitted from diagnostics output.</comment>

<file context>
@@ -144,6 +151,7 @@ class DistortionWave extends StatefulWidget {
         DiagnosticsProperty<WaveSource>('source', source, defaultValue: null),
       )
       ..add(EnumProperty<WaveType>('type', type, defaultValue: null))
+      ..add(DiagnosticsProperty<BorderRadius>('cornerRadii', cornerRadii))
       ..add(DiagnosticsProperty<WaveStyle>('style', style, defaultValue: null))
       ..add(DoubleProperty('progress', progress, defaultValue: null));
</file context>
Suggested change
..add(DiagnosticsProperty<BorderRadius>('cornerRadii', cornerRadii))
..add(
DiagnosticsProperty<BorderRadius>(
'cornerRadii',
cornerRadii,
defaultValue: null,
),
)

..add(DiagnosticsProperty<WaveStyle>('style', style, defaultValue: null))
..add(DoubleProperty('progress', progress, defaultValue: null));
}
Expand Down Expand Up @@ -389,6 +397,7 @@ class _DistortionWaveState extends State<DistortionWave>
snapshots: _snapshots,
plain: _reducedMotion(),
revealing: _revealing,
cornerRadii: widget.cornerRadii,
displayRadii: _followsDisplay
? MediaQuery.maybeDisplayCornerRadiiOf(context)
: null,
Expand Down Expand Up @@ -416,6 +425,7 @@ class WaveStage
this.snapshots = WaveSnapshots.onChange,
this.plain = false,
this.revealing = false,
this.cornerRadii,
this.displayRadii,
this.viewSize,
this.outgoing,
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -474,6 +487,7 @@ class WaveStage
snapshots: snapshots,
plain: plain,
revealing: revealing,
cornerRadii: cornerRadii,
displayRadii: displayRadii,
viewSize: viewSize,
);
Expand All @@ -488,6 +502,7 @@ class WaveStage
..snapshots = snapshots
..plain = plain
..revealing = revealing
..cornerRadii = cornerRadii
..displayRadii = displayRadii
..viewSize = viewSize;
}
Expand Down
17 changes: 14 additions & 3 deletions lib/src/distortion_wave/render/render_wave_stage.dart
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ class RenderWaveStage extends RenderBox
this._snapshots = WaveSnapshots.onChange,
this._plain = false,
this._revealing = false,
this._cornerRadii,
this._displayRadii,
this._viewSize,
});
Expand Down Expand Up @@ -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
Expand All @@ -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) {
Expand Down
2 changes: 1 addition & 1 deletion pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
34 changes: 34 additions & 0 deletions test/distortion_wave/widget/distortion_wave_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ void main() {
bool maintainState = true,
WaveStyle? style,
WavePalette? palette,
BorderRadius? cornerRadii,
WaveSource? source,
Widget? child,
Widget? revealedChild,
Expand All @@ -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'),
Expand Down Expand Up @@ -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 {
Expand Down
Loading