Skip to content

refactor(api): trim over-engineered scaling, fast-path, and SwiftUI surface - #7

Merged
Dicky019 merged 3 commits into
mainfrom
refactor/remove-fast-scaling-variants
Jun 21, 2026
Merged

Dicky019 merged 3 commits into
mainfrom
refactor/remove-fast-scaling-variants

Conversation

@Dicky019

@Dicky019 Dicky019 commented Jun 21, 2026 •

Copy link
Copy Markdown
Owner

Summary

Removes redundant and speculative public API across the scaling, fast-path, debug, and SwiftUI layers, reducing ScreenUtil to its cross-platform scaling primitives plus the platform ergonomics that carry real logic. Driven by a multi-lens audit (over-engineering, clean-code, SOLID, Swift-concurrency, SwiftUI/UIKit). Net −733 lines (253 insertions, 986 deletions) across 24 files, with no behavior change to the surviving API.

⚠️ Breaking change — public API removed. Acceptable pre-v1.0 (not yet released). See Migration below.

What changed

Scaling

  • Numeric+Scaling: 4 copy-paste Int/Float/Double/CGFloat extensions → 2 generics (BinaryInteger, BinaryFloatingPoint) — also covers Int64/UInt uniformly, closing the silent-scale-to-zero gap.
  • Removed the per-value .fastW/.fastH/.fastSp numeric variants (~1.1× over .w/.h/.sp, not the documented speedup). The real hot-loop path — FastScale / withFastScale — is unchanged.
  • FastScale now delegates to the internal ScaleFactorCache core instead of re-implementing the capture.
  • Consolidated batch scaling onto BatchScaler (added scale/points/rects); dropped the redundant, drifted ScreenUtil.batch* methods.

Debug

  • ScreenUtilDebug struct+singleton → caseless enum of static methods; dropped validateScaling, generateTestReport, and the free-function wrappers.

SwiftUI

  • Removed Font.scaledSystem/scaledCustom, @ScaledValue/@ScreenPercentage, and the responsiveFrame/responsivePadding/responsiveCornerRadius view modifiers — all thin sugar over the .w/.h/.sp/.r primitives applied inside native modifiers. Kept EnvironmentValues.screenUtil (file renamed to Environment+ScreenUtil.swift).

Bug fixes (included)

  • responsivePadding(.all) scaled every edge by height only — fixed to scale each axis by its own factor (now applied at consumer call sites).
  • UIView constraint helpers now disable the autoresizing mask and batch-activate constraints.

Docs / examples / tests

Updated to the new surface; stale CLAUDE.md "Known Issues" (data race, stale-on-rotation — both already fixed in source) struck.

Migration

Removed Use instead
100.fastW / .fastH / .fastSp 100.w / .h / .sp (or FastScale in a hot loop)
ScreenUtil.shared.batchWidths(xs) ScreenUtil.shared.batchScaler.widths(xs)
.font(.scaledSystem(size: 16)) .font(.system(size: 16.sp))
@ScaledValue(.width) var w = 100 let w = 100.w
.responsiveFrame(width: 200, height: 50) .frame(width: 200.w, height: 50.h)
ScreenUtilDebug.shared.printCurrentConfiguration() ScreenUtilDebug.printCurrentConfiguration()

Verification

  • swift build clean under -strict-concurrency=complete, no new warnings.
  • swift test: 105 tests, 0 failures (down from 116 — removed tests covered deleted API; no behavioral coverage lost).
  • UIKit-only helpers are build-verified on the CI iOS job (not compiled on the macOS test host).

Commits

  • refactor(api): trim over-engineered scaling and SwiftUI convenience surface
  • refactor(scaling): remove .fastW/.fastH/.fastSp numeric variants
  • docs(scaling): drop removed .fast* numeric API from docs

Dicky019 added 2 commits June 21, 2026 19:22
Remove .fastW/.fastH/.fastSp from CLAUDE.md Public Contract & Module Map and from README; strike the resolved Known Issues (data race, rotation) and correct the Sendable note. Ignore graphify-out/ and .superpowers/.
The per-value fast variants only skipped one isFinite guard while still paying a per-value atomic snapshot load (~1.1x, not a real speedup). The capture-once FastScale/withFastScale path is unchanged; the Debug benchmark is repointed to FastScale.width and the dead/flaky fast tests removed.
@Dicky019
Dicky019 force-pushed the refactor/remove-fast-scaling-variants branch from e97c3d9 to 4d027b2 Compare June 21, 2026 10:24
…urface

Collapse the duplicated/speculative API down to the cross-platform scaling
primitives and the minimum SwiftUI/UIKit ergonomics that carry real logic.

Scaling:
- Numeric+Scaling: 4 copy-paste extensions → 2 generics (BinaryInteger,
  BinaryFloatingPoint), now covering Int64/UInt uniformly.
- FastScale delegates to the internal ScaleFactorCache core instead of
  re-implementing the capture.
- Consolidate batch scaling onto BatchScaler (add scale/points/rects);
  drop the redundant ScreenUtil.batch* methods.

Debug:
- ScreenUtilDebug struct+singleton → caseless enum of static methods;
  drop validateScaling, generateTestReport, and free-function wrappers.

SwiftUI:
- Remove Font.scaledSystem/scaledCustom, @ScaledValue/@ScreenPercentage,
  and the responsiveFrame/responsivePadding/responsiveCornerRadius view
  modifiers — all thin sugar over the .w/.h/.sp/.r primitives applied
  inside native modifiers. Keep EnvironmentValues.screenUtil (renamed file
  Environment+ScreenUtil.swift).

Also: fix responsivePadding(.all) consumers via native per-axis scaling,
UIView constraint helpers disable the autoresizing mask and batch-activate,
and update tests, examples, and docs.

Build clean under -strict-concurrency=complete; 105 tests, 0 failures.
@Dicky019 Dicky019 changed the title refactor(scaling): remove .fastW/.fastH/.fastSp numeric variants The per-value fast variants only skipped one isFinite guard while still paying a per-value atomic snapshot load (~1.1x, not a real speedup). The capture-once FastScale/withFastScale path is unchanged; the Debug benchmark is repointed to FastScale.width and the dead/flaky fast tests removed. refactor(api): trim over-engineered scaling, fast-path, and SwiftUI surface Jun 21, 2026
@Dicky019 Dicky019 self-assigned this Jun 21, 2026
@Dicky019
Dicky019 merged commit ca6c013 into main Jun 21, 2026
4 checks passed
@Dicky019
Dicky019 deleted the refactor/remove-fast-scaling-variants branch June 21, 2026 10:30
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant