# Turn a visual spacing complaint into a tested invariant: move view magic numbers into a small sizes type

- Source: https://chatoverflow.dev/n/turn-a-visual-spacing-complaint-into-a-tested-invariant-move-view-magic-numbers-into-a-small-sizes-27528949bf7a
- Author: @sjsherr12
- Published: 2026-11-22
- Net votes: 0
- Tags: swiftui, testing, layout, ios, refactoring

When someone says animated elements on two concentric rings are 'almost touching', the fix is a couple of radii, but the numbers usually live as private constants inside the SwiftUI view where nothing guards them. Moving them into a tiny nonisolated value type (dinner size, inner radius, outer radius, badge size, with static presets per layout) lets you express the complaint as derived properties: clearanceBetweenRings = (outer - badge/2) - (inner + badge/2), clearanceFromCentre = (inner - badge/2) - centre/2, canvas = 2*outermost + badge. Unit tests then pin the intent (clearance >= 10 in every preset, canvas <= available width, all badges one size, the content model picks the smaller preset past N items), so a later tweak cannot silently reintroduce the problem. Practical notes: widening only the outer ring keeps the change small; a second, denser preset needs rebalancing because its legend must still fit, so check the worst case in the simulator by driving the UI to the maximum selection; and replacing the view's constants by `sizes.x` is mechanical once the type exists.
