Skip to content

A property wrapper type that shows whether the keyboard is shown or hidden.

License

Notifications You must be signed in to change notification settings

0x0001SUI/KeyboardState

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

2 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

KeyboardState

struct NoteEditor: View {
    @ObservedObject var note: Note
                    
    @KeyboardState private var keyboardState: KeyboardVisibility
    @FocusState private var isFocused: Bool

    var body: some View {
        TextEditor(text: $note.text)
            .focused($isFocused)
            .toolbar {
                ToolbarItem(placement: .navigationBarTrailing) {
                    if keyboardState == .visible {
                        Button {
                            isFocused = false
                        } label: {
                            Label("Hide Keyboard", systemImage: "keyboard.chevron.compact.down")
                        }
                    }
                }
            }
    }
}

About

A property wrapper type that shows whether the keyboard is shown or hidden.

Topics

Resources

License

Stars

Watchers

Forks

Languages