### Custom Element Builder with Emoji Mapping Source: https://context7.com/aunnnn/movingnumbersview/llms.txt Customize each digit's appearance by providing a closure that returns a SwiftUI View. This example maps digits to corresponding emojis. ```swift import SwiftUI import MovingNumbersView struct EmojiCounterView: View { @State private var value: Double = 123 private func emojiForDigit(_ str: String) -> String { guard let number = Int(str) else { return str } let emojis = ["😀", "😁", "😂", "🤣", "😃", "😄", "😅", "😆", "😉", "😊"] return emojis[number] } var body: some View { VStack { MovingNumbersView( number: value, numberOfDecimalPlaces: 0, fixedWidth: 250 ) { character in Text(emojiForDigit(character)) .font(.system(size: 40)) } HStack { Button("−") { value = max(0, value - 1) } Button("+") { value += 1 } } .font(.title) } } } ``` -------------------------------- ### Negative Number Support Source: https://context7.com/aunnnn/movingnumbersview/llms.txt The library automatically handles negative numbers by animating a minus sign. This example shows a balance that can go negative, changing color accordingly. ```swift import SwiftUI import MovingNumbersView struct BalanceView: View { @State private var balance: Double = 500 var body: some View { VStack(spacing: 20) { MovingNumbersView( number: balance, numberOfDecimalPlaces: 2, fixedWidth: 250 ) { str in Text(str) .font(.system(size: 32, weight: .semibold)) .foregroundColor(balance >= 0 ? .green : .red) } HStack(spacing: 40) { Button("Withdraw $100") { balance -= 100 } Button("Deposit $100") { balance += 100 } } } } } ``` -------------------------------- ### Fixed Width Configuration for Stable Animations Source: https://context7.com/aunnnn/movingnumbersview/llms.txt Configure `fixedWidth` to prevent the view from resizing during digit transitions, avoiding visual cropping. This example shows a comparison between using and not using `fixedWidth`. ```swift import SwiftUI import MovingNumbersView struct PriceDisplay: View { @State private var amount: Double = 99.99 var body: some View { VStack(spacing: 20) { // With fixed width - recommended for smooth transitions MovingNumbersView( number: amount, numberOfDecimalPlaces: 2, fixedWidth: 300 ) { s in Text(s) .font(.largeTitle) .fontWeight(.heavy) } // Without fixed width - may crop trailing digits during animation MovingNumbersView( number: amount, numberOfDecimalPlaces: 2 ) { s in Text(s) .font(.largeTitle) } Slider(value: $amount, in: 0...1_000_000) } } } ``` -------------------------------- ### Initialize MovingNumbersView with Custom Digit Rendering Source: https://context7.com/aunnnn/movingnumbersview/llms.txt Use this initializer to create an animated number display. Customize digit appearance using the provided character builder closure. Set parameters like decimal places, fixed width, spacing, and animation duration. ```swift import SwiftUI import MovingNumbersView struct ContentView: View { @State private var price: Double = 1234.56 var body: some View { MovingNumbersView( number: price, numberOfDecimalPlaces: 2, fixedWidth: 200, verticalDigitSpacing: 0, animationDuration: 0.25 ) { character in Text(character) .font(.largeTitle) .fontWeight(.bold) } } } ``` -------------------------------- ### Basic Usage with Integer Display Source: https://context7.com/aunnnn/movingnumbersview/llms.txt Demonstrates how to use MovingNumbersView to display whole numbers without decimals, including automatic thousand-separator commas and smooth digit transitions. ```APIDOC ## Basic Usage with Integer Display ### Description For whole numbers without decimals, set `numberOfDecimalPlaces` to 0. The view automatically adds thousand-separator commas and handles the digit transitions smoothly. ### Method SwiftUI View ### Endpoint N/A (SwiftUI View) ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body None ### Request Example ```swift import SwiftUI import MovingNumbersView struct ScoreView: View { @State private var score: Double = 0 var body: some View { VStack { MovingNumbersView( number: score, numberOfDecimalPlaces: 0 ) { str in Text(str) .font(.system(size: 48, weight: .heavy, design: .rounded)) .foregroundColor(.primary) } Button("Add Points") { score += Double.random(in: 100...1000) } } } } ``` ### Response #### Success Response (200) N/A (SwiftUI View) #### Response Example ``` Displays whole numbers like "1,234" with commas Clicking button animates digit changes smoothly ``` ``` -------------------------------- ### MovingNumbersView Initializer Source: https://context7.com/aunnnn/movingnumbersview/llms.txt The main initializer for MovingNumbersView allows for detailed customization of number display, including decimal places, fixed width, spacing, animation duration, and character view building. ```APIDOC ## MovingNumbersView Initializer ### Description The main initializer creates an animated number display with customizable digit rendering. It accepts the number to display, decimal precision, optional fixed width for stable animations, spacing between digits in the vertical stack, animation duration, and a closure to build each character view. ### Method SwiftUI View ### Endpoint N/A (SwiftUI View) ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body None ### Request Example ```swift import SwiftUI import MovingNumbersView struct ContentView: View { @State private var price: Double = 1234.56 var body: some View { MovingNumbersView( number: price, numberOfDecimalPlaces: 2, fixedWidth: 200, verticalDigitSpacing: 0, animationDuration: 0.25 ) { character in Text(character) .font(.largeTitle) .fontWeight(.bold) } } } ``` ### Response #### Success Response (200) N/A (SwiftUI View) #### Response Example ``` Displays "1,234.56" with animated digit transitions ``` ``` -------------------------------- ### Initialize MovingNumbersView Source: https://github.com/aunnnn/movingnumbersview/blob/master/README.md Basic initialization of MovingNumbersView with a number, decimal places, and a custom element builder for each character. The element builder allows full customization of text style. ```swift import MovingNumbersView MovingNumbersView( number: 123.456, numberOfDecimalPlaces: 3) { // How to build each character Text($0) .font(.largeTitle) } ``` -------------------------------- ### Fixed Width Configuration Source: https://context7.com/aunnnn/movingnumbersview/llms.txt Explains the importance of the `fixedWidth` parameter in MovingNumbersView to prevent visual cropping during digit transitions, especially when digits are added or removed. ```APIDOC ## Fixed Width Configuration ### Description Setting a fixed width prevents the view from shrinking during digit transitions, which avoids visual cropping issues. This is highly recommended for smooth animations when digits are added or removed. ### Method SwiftUI View ### Endpoint N/A (SwiftUI View) ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body None ### Request Example ```swift import SwiftUI import MovingNumbersView struct PriceDisplay: View { @State private var amount: Double = 99.99 var body: some View { VStack(spacing: 20) { // With fixed width - recommended for smooth transitions MovingNumbersView( number: amount, numberOfDecimalPlaces: 2, fixedWidth: 300 ) { s in Text(s) .font(.largeTitle) .fontWeight(.heavy) } // Without fixed width - may crop trailing digits during animation MovingNumbersView( number: amount, numberOfDecimalPlaces: 2 ) { s in Text(s) .font(.largeTitle) } Slider(value: $amount, in: 0...1_000_000) } } } ``` ### Response #### Success Response (200) N/A (SwiftUI View) #### Response Example ``` Top view maintains stable width during transitions Bottom view width changes dynamically with digit count ``` ``` -------------------------------- ### Basic Usage: Integer Display with Thousand Separators Source: https://context7.com/aunnnn/movingnumbersview/llms.txt Display whole numbers by setting `numberOfDecimalPlaces` to 0. The view automatically handles thousand-separator commas and animates digit changes smoothly. Includes a button to demonstrate score updates. ```swift import SwiftUI import MovingNumbersView struct ScoreView: View { @State private var score: Double = 0 var body: some View { VStack { MovingNumbersView( number: score, numberOfDecimalPlaces: 0 ) { str in Text(str) .font(.system(size: 48, weight: .heavy, design: .rounded)) .foregroundColor(.primary) } Button("Add Points") { score += Double.random(in: 100...1000) } } } } ``` -------------------------------- ### Live Counter with Timer Integration Source: https://context7.com/aunnnn/movingnumbersview/llms.txt Integrate MovingNumbersView with SwiftUI's state and a Timer to create a continuously updating live counter. The `onReceive` modifier updates the `count` state, triggering animations in the MovingNumbersView. ```swift import SwiftUI import MovingNumbersView struct LiveCounterView: View { @State private var count: Double = 0 let timer = Timer.publish(every: 0.1, on: .main, in: .common).autoconnect() var body: some View { VStack { Text("Live Counter") .font(.headline) MovingNumbersView( number: count, numberOfDecimalPlaces: 1, fixedWidth: 200, animationDuration: 0.1 ) { Text($0) .font(.system(size: 48, weight: .heavy, design: .monospaced)) } .mask( LinearGradient( gradient: Gradient(stops: [ Gradient.Stop(color: .clear, location: 0), Gradient.Stop(color: .black, location: 0.15), Gradient.Stop(color: .black, location: 0.85), Gradient.Stop(color: .clear, location: 1.0) ]), startPoint: .top, endPoint: .bottom ) ) } .onReceive(timer) { _ in count += 0.1 } } } ``` -------------------------------- ### Apply Gradient Mask to MovingNumbersView Source: https://github.com/aunnnn/movingnumbersview/blob/master/README.md Applies a gradient mask to the MovingNumbersView to create a blurring effect on the top and bottom edges. This enhances the visual appeal of the number transitions. ```swift MovingNumbersView(...) .mask(LinearGradient( gradient: Gradient(stops: [ Gradient.Stop(color: .clear, location: 0), Gradient.Stop(color: .black, location: 0.2), Gradient.Stop(color: .black, location: 0.8), Gradient.Stop(color: .clear, location: 1.0)]), startPoint: .top, endPoint: .bottom)) ``` -------------------------------- ### Custom Animation Duration and Digit Spacing Source: https://context7.com/aunnnn/movingnumbersview/llms.txt Control animation speed with `animationDuration` and vertical spacing between digits with `verticalDigitSpacing`. Use these parameters to fine-tune the visual behavior of the number rolling effect. ```swift import SwiftUI import MovingNumbersView struct CustomAnimationView: View { @State private var counter: Double = 0 var body: some View { VStack(spacing: 30) { // Fast animation MovingNumbersView( number: counter, numberOfDecimalPlaces: 0, fixedWidth: 150, verticalDigitSpacing: 2, animationDuration: 0.15 ) { Text($0) .font(.title) .fontWeight(.bold) } // Slow animation MovingNumbersView( number: counter, numberOfDecimalPlaces: 0, fixedWidth: 150, verticalDigitSpacing: 8, animationDuration: 0.5 ) { Text($0) .font(.title) .fontWeight(.bold) } Button("Increment") { counter += 1 } } } } ``` -------------------------------- ### Gradient Edge Blur Effect Source: https://context7.com/aunnnn/movingnumbersview/llms.txt Apply a gradient mask to the MovingNumbersView to create a blur effect on the top and bottom edges, enhancing visual transitions. ```swift import SwiftUI import MovingNumbersView struct BlurredEdgesView: View { @State private var stockPrice: Double = 152.47 var body: some View { VStack { MovingNumbersView( number: stockPrice, numberOfDecimalPlaces: 2, fixedWidth: 200, animationDuration: 0.3 ) { str in Text(str) .font(.system(size: 36, weight: .bold, design: .monospaced)) .foregroundColor(.green) } .mask(LinearGradient( gradient: Gradient(stops: [ Gradient.Stop(color: .clear, location: 0), Gradient.Stop(color: .black, location: 0.2), Gradient.Stop(color: .black, location: 0.8), Gradient.Stop(color: .clear, location: 1.0) ]), startPoint: .top, endPoint: .bottom )) Button("Update Price") { stockPrice += Double.random(in: -10...10) } } } } ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.