Skip to content

SwiftUIKeyPress is a package to make up for the lack of keyboard input in SwiftUI.

License

Notifications You must be signed in to change notification settings

croyfoo/SwiftUIKeyPress

 
 

Repository files navigation

SwiftUIKeyPress

SwiftUIKeyPress is a package to make up for the lack of keyboard input in SwiftUI.

How to use?

There are three ways that you can implement SwiftUIPress

First:

struct ContentView: View
    @State var keys = [UIKey]()

    var body: some View {
        Text(keys.map(\.characters).reduce("", +))
            .padding()
            .onKeyPress($keys)
    }
}

Second:

struct ContentView: View
    @State var keys = [UIKey]()

    var body: some View {
        Text(keys.map(\.characters).reduce("", +))
            .padding()
            .onKeyPress { keys in
                self.keys = keys
            }
    }
}

Third:

struct ContentView: View
    @State var keys = [UIKey]()

    var body: some View {
        Text(keys.map(\.characters).reduce("", +))
            .padding()
            .onKeyUpdate { keys in
                self.keys = keys
            }
    }
}

A Tips

You only can use 1 SwiftUIKeyPress modifier on every one view. The others will not work.

And on MacOS, UIKey is a string value.

About

SwiftUIKeyPress is a package to make up for the lack of keyboard input in SwiftUI.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • Swift 100.0%