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
17 changes: 17 additions & 0 deletions .githooks/pre-commit
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
#!/usr/bin/env bash
set -euo pipefail

staged_files=()
while IFS= read -r -d '' file; do
staged_files+=("$file")
done < <(git diff --cached --name-only -z --diff-filter=ACMR)

if command -v fvm >/dev/null 2>&1; then
DART_DISABLE_TELEMETRY=1 fvm dart format .
else
DART_DISABLE_TELEMETRY=1 dart format .
fi

if ((${#staged_files[@]})); then
git add -- "${staged_files[@]}"
fi
1 change: 1 addition & 0 deletions .github/CODEOWNERS
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
* @zhukeev
56 changes: 56 additions & 0 deletions .github/ISSUE_TEMPLATE/issue_report.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
name: Issue
description: Report a bug or request a feature
title: "[Issue]: "
labels:
- triage
body:
- type: dropdown
id: type
attributes:
label: Type
options:
- Bug
- "Feature request"
- Question
validations:
required: true
- type: textarea
id: summary
attributes:
label: Summary
description: What happened or what you want to add.
validations:
required: true
- type: textarea
id: steps
attributes:
label: Steps to reproduce
description: For bugs, include minimal steps.
placeholder: "1. ...\n2. ...\n3. ..."
- type: textarea
id: expected
attributes:
label: Expected behavior
- type: textarea
id: actual
attributes:
label: Actual behavior
- type: input
id: package_version
attributes:
label: Package version
placeholder: "1.0.23"
- type: input
id: flutter_version
attributes:
label: Flutter version
placeholder: "3.27.0"
- type: input
id: platform
attributes:
label: Platform
placeholder: "iOS / Android / Web / macOS / Windows / Linux"
- type: textarea
id: additional
attributes:
label: Additional context
32 changes: 32 additions & 0 deletions .github/workflows/auto-assign.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
name: Auto assign

on:
issues:
types: [opened, reopened]
pull_request_target:
types: [opened, reopened, ready_for_review]

permissions:
issues: write
pull-requests: write

jobs:
assign:
runs-on: ubuntu-latest
steps:
- name: Add assignee
uses: actions/github-script@v7
with:
script: |
const assignees = ['zhukeev'];
const issue_number = context.payload.pull_request
? context.payload.pull_request.number
: context.issue.number;
const { owner, repo } = context.repo;

await github.rest.issues.addAssignees({
owner,
repo,
issue_number,
assignees,
});
19 changes: 18 additions & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,21 @@ jobs:
- name: Checkout
uses: actions/checkout@v4

- name: Detect code changes
id: changes
uses: dorny/paths-filter@v3
with:
filters: |
code:
- "lib/**"
- "test/**"
- "example/**"
- "shaders/**"
- "assets/**"
- "pubspec.yaml"
- "analysis_options.yaml"
- "analysis_options.yml"

- name: Setup Flutter
uses: subosito/flutter-action@v2
with:
Expand All @@ -23,7 +38,7 @@ jobs:
run: flutter pub get

- name: Check formatting
run: dart format --line-length=120 --output=none --set-exit-if-changed lib test example
run: dart format --output=none --set-exit-if-changed .

- name: Run analysis
run: flutter analyze
Expand All @@ -33,9 +48,11 @@ jobs:
working-directory: example

- name: Run tests
if: steps.changes.outputs.code == 'true'
run: flutter test

- name: Run golden tests
if: steps.changes.outputs.code == 'true'
run: flutter test test/golden_test.dart

- name: Install pana
Expand Down
3 changes: 2 additions & 1 deletion example/lib/main.dart
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,8 @@ class _DemoListPage extends StatelessWidget {
_DemoEntry('SpoilerTextField', () => const SpoilerTextFieldPage()),
_DemoEntry('SpoilerTextWrapper', () => const SpoilerTextWrapperPage()),
_DemoEntry('SpoilerOverlay', () => const SpoilerOverlayPage()),
_DemoEntry('SpoilerOverlay Full', () => const SpoilerOverlayPage(fullPage: true)),
_DemoEntry('SpoilerOverlay Full',
() => const SpoilerOverlayPage(fullPage: true)),
];

return Scaffold(
Expand Down
3 changes: 2 additions & 1 deletion example/lib/pages/spoiler_overlay_page.dart
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,8 @@ class _SpoilerOverlayPageState extends State<SpoilerOverlayPage> {
'https://img.freepik.com/premium-photo/drawing-female-superhero-female-character_1308175-151081.jpg?w=1800';

bool divided = false;
WidgetSpoilerConfig config(bool shaders) => WidgetSpoilerConfig.defaultConfig().copyWith(
WidgetSpoilerConfig config(bool shaders) =>
WidgetSpoilerConfig.defaultConfig().copyWith(
enableGestureReveal: true,
particleConfig: const ParticleConfig(
density: .1,
Expand Down
3 changes: 2 additions & 1 deletion example/lib/pages/spoiler_text_field_page.dart
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@ class SpoilerTextFieldPage extends StatefulWidget {
}

class _SpoilerTextFieldPageState extends State<SpoilerTextFieldPage> {
final _controller = TextEditingController(text: 'This is a spoiler! Tap to reveal');
final _controller =
TextEditingController(text: 'This is a spoiler! Tap to reveal');

@override
void dispose() {
Expand Down
17 changes: 12 additions & 5 deletions lib/extension/rect_x.dart
Original file line number Diff line number Diff line change
Expand Up @@ -14,17 +14,24 @@ extension RectX on Rect {
/// ```
///
bool containsOffset(Offset offset) {
return bottom >= offset.dy && top <= offset.dy && left <= offset.dx && right >= offset.dx;
return bottom >= offset.dy &&
top <= offset.dy &&
left <= offset.dx &&
right >= offset.dx;
}

(Rect, Rect, Rect, Rect) divideRect() {
final halfWidth = width / 2;
final halfHeight = height / 2;

final topLeft = Rect.fromLTRB(left, top, left + halfWidth, top + halfHeight);
final topRight = Rect.fromLTRB(left + halfWidth, top, right, top + halfHeight);
final bottomLeft = Rect.fromLTRB(left, top + halfHeight, left + halfWidth, bottom);
final bottomRight = Rect.fromLTRB(left + halfWidth, top + halfHeight, right, bottom);
final topLeft =
Rect.fromLTRB(left, top, left + halfWidth, top + halfHeight);
final topRight =
Rect.fromLTRB(left + halfWidth, top, right, top + halfHeight);
final bottomLeft =
Rect.fromLTRB(left, top + halfHeight, left + halfWidth, bottom);
final bottomRight =
Rect.fromLTRB(left + halfWidth, top + halfHeight, right, bottom);

return (topLeft, topRight, bottomLeft, bottomRight);
}
Expand Down
5 changes: 4 additions & 1 deletion lib/models/fade_config.dart
Original file line number Diff line number Diff line change
Expand Up @@ -15,5 +15,8 @@ class FadeConfig {

@override
bool operator ==(Object other) =>
identical(this, other) || other is FadeConfig && padding == other.padding && edgeThickness == other.edgeThickness;
identical(this, other) ||
other is FadeConfig &&
padding == other.padding &&
edgeThickness == other.edgeThickness;
}
6 changes: 4 additions & 2 deletions lib/models/shader_config.dart
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,8 @@ class ShaderConfig {
/// Glitch stripes with RGB splits.
factory ShaderConfig.glitchStripes() => ShaderConfig(
customShaderPath: 'packages/spoiler_widget/shaders/glitch_stripes.frag',
onGetShaderUniforms: (rect, time, seed, fadeOffset, isFading, fadeRadius, config) {
onGetShaderUniforms:
(rect, time, seed, fadeOffset, isFading, fadeRadius, config) {
return [
rect.width,
rect.height,
Expand Down Expand Up @@ -177,7 +178,8 @@ class ShaderConfig {

/// Liquid Spectrum (HSV FBM) shader.
factory ShaderConfig.liquidSpectrum() => const ShaderConfig(
customShaderPath: 'packages/spoiler_widget/shaders/liquid_spectrum.frag',
customShaderPath:
'packages/spoiler_widget/shaders/liquid_spectrum.frag',
onGetShaderUniforms: _baseUniforms,
);
}
65 changes: 46 additions & 19 deletions lib/models/spoiler_config.dart
Original file line number Diff line number Diff line change
Expand Up @@ -116,10 +116,12 @@ class SpoilerConfig {
this.shaderConfig,
}) : particleConfig = particleConfig ??
ParticleConfig(
density: particleDensity ?? ParticleConfig.defaultConfig().density,
density:
particleDensity ?? ParticleConfig.defaultConfig().density,
speed: particleSpeed ?? ParticleConfig.defaultConfig().speed,
color: particleColor ?? ParticleConfig.defaultConfig().color,
maxParticleSize: maxParticleSize ?? ParticleConfig.defaultConfig().maxParticleSize,
maxParticleSize: maxParticleSize ??
ParticleConfig.defaultConfig().maxParticleSize,
),
fadeConfig = _resolveFadeConfig(
fadeConfig: fadeConfig,
Expand All @@ -129,10 +131,16 @@ class SpoilerConfig {
) {
assert(
particleConfig == null ||
(particleDensity == null && particleSpeed == null && particleColor == null && maxParticleSize == null),
(particleDensity == null &&
particleSpeed == null &&
particleColor == null &&
maxParticleSize == null),
);
assert(
fadeConfig == null || (enableFadeAnimation == null && fadeRadius == null && fadeEdgeThickness == null),
fadeConfig == null ||
(enableFadeAnimation == null &&
fadeRadius == null &&
fadeEdgeThickness == null),
);
}

Expand Down Expand Up @@ -179,31 +187,50 @@ class SpoilerConfig {
ValueChanged<bool>? onSpoilerVisibilityChanged,
ShaderConfig? shaderConfig,
}) {
final bool legacyParticleOverridesProvided =
particleDensity != null || particleSpeed != null || particleColor != null || maxParticleSize != null;
final bool legacyParticleOverridesProvided = particleDensity != null ||
particleSpeed != null ||
particleColor != null ||
maxParticleSize != null;

final bool legacyFadeOverridesProvided =
enableFadeAnimation != null || fadeRadius != null || fadeEdgeThickness != null;
final bool legacyFadeOverridesProvided = enableFadeAnimation != null ||
fadeRadius != null ||
fadeEdgeThickness != null;

final ParticleConfig? nextParticleConfig =
legacyParticleOverridesProvided ? null : (particleConfig ?? this.particleConfig);
final ParticleConfig? nextParticleConfig = legacyParticleOverridesProvided
? null
: (particleConfig ?? this.particleConfig);

final FadeConfig? nextFadeConfig = legacyFadeOverridesProvided ? null : (fadeConfig ?? this.fadeConfig);
final FadeConfig? nextFadeConfig =
legacyFadeOverridesProvided ? null : (fadeConfig ?? this.fadeConfig);

return SpoilerConfig(
particleDensity: legacyParticleOverridesProvided ? (particleDensity ?? this.particleDensity) : null,
particleSpeed: legacyParticleOverridesProvided ? (particleSpeed ?? this.particleSpeed) : null,
particleColor: legacyParticleOverridesProvided ? (particleColor ?? this.particleColor) : null,
maxParticleSize: legacyParticleOverridesProvided ? (maxParticleSize ?? this.maxParticleSize) : null,
enableFadeAnimation: legacyFadeOverridesProvided ? (enableFadeAnimation ?? this.enableFadeAnimation) : null,
fadeRadius: legacyFadeOverridesProvided ? (fadeRadius ?? this.fadeRadius) : null,
fadeEdgeThickness: legacyFadeOverridesProvided ? (fadeEdgeThickness ?? this.fadeEdgeThickness) : null,
particleDensity: legacyParticleOverridesProvided
? (particleDensity ?? this.particleDensity)
: null,
particleSpeed: legacyParticleOverridesProvided
? (particleSpeed ?? this.particleSpeed)
: null,
particleColor: legacyParticleOverridesProvided
? (particleColor ?? this.particleColor)
: null,
maxParticleSize: legacyParticleOverridesProvided
? (maxParticleSize ?? this.maxParticleSize)
: null,
enableFadeAnimation: legacyFadeOverridesProvided
? (enableFadeAnimation ?? this.enableFadeAnimation)
: null,
fadeRadius:
legacyFadeOverridesProvided ? (fadeRadius ?? this.fadeRadius) : null,
fadeEdgeThickness: legacyFadeOverridesProvided
? (fadeEdgeThickness ?? this.fadeEdgeThickness)
: null,
particleConfig: nextParticleConfig,
fadeConfig: nextFadeConfig,
isEnabled: isEnabled ?? this.isEnabled,
enableGestureReveal: enableGestureReveal ?? this.enableGestureReveal,
maskConfig: maskConfig ?? this.maskConfig,
onSpoilerVisibilityChanged: onSpoilerVisibilityChanged ?? this.onSpoilerVisibilityChanged,
onSpoilerVisibilityChanged:
onSpoilerVisibilityChanged ?? this.onSpoilerVisibilityChanged,
shaderConfig: shaderConfig ?? this.shaderConfig,
);
}
Expand Down
Loading