How MovingNumbersView works
masterThe library renders each visual element (digit, comma, dot, or minus sign) as a centered component within an HStack. Each digit is represented by a 10-digit vertical stack that is moved up or down via a VerticalShift geometry effect based on the current digit being displayed.
To ensure SwiftUI calculates correct insertion and removal transitions, each element is assigned a specific id based on its significance:
- Digits: Multiples of 10 (e.g., 10, 20, 30).
- Decimal places: Negative multiples of 10 (e.g., -10, -20).
- Dot (.): ID of
0. - Minus sign (-): ID of
1. - Comma (,): ID of the next digit's ID plus 5.
Example ID mapping for -1,234.56: [1(-), 40, 35(,), 30, 20, 10, 0(.), -10, -20].