SwiftUItility

0.1.3

insub4067/SwiftUItility

What's New

0.1.3

2023-12-14T14:35:20Z

SwiftUItility

Environments Example

struct ContentView: View {
    
    @Environment(\.safeAreaInsets) var safeAreaInsets
    @Environment(\.spinner) var spinner
    @Environment(\.toast) var toast
    @Environment(\.alert) var alert
    
    var body: some View {
        // SafeAreaInsets
        Text("SafeAreaInsets")
            .padding(safeAreaInsets)
        
        // Spinner
        Button("Start Spinner") {
            spinner.start()
        }
        Button("Stop Spinner") {
            spinner.stop()
        }
        
        // Toast
        Button("Show Toast") {
            toast.show("Hello World")
        }
        
        // Alert
        Button("Show Alert") {
            let parameter = AlertParameter(
                message: "Warning",
                buttons: [
                    .init(title: "cancel", style: .cancel),
                    .init(title: "default", style: .default)
                ]
            )
            alert.show(parameter)
        }
    }
}

TextField Sync Example

struct ContentView: View {
    
    @StateObject var viewModel = ContentViewModel()
    @State var text = ""
    @FocusState var isFocused
    
    var body: some View {
        
        TextField("Placeholder", text: $text)
            .syncFocused($viewModel.isFocused, with: $isFocused)
    }
}

class ContentViewModel: ObservableObject {
    
    @Published var isFocused = false
}

Description

  • Swift Tools 5.9.0
View More Packages from this Author

Dependencies

  • None
Last updated: Sat Oct 19 2024 22:52:45 GMT-0900 (Hawaii-Aleutian Daylight Time)