diff --git a/PlantUML/PlantUMLEditorView.swift b/PlantUML/PlantUMLEditorView.swift index a4cc345..2c77b0a 100644 --- a/PlantUML/PlantUMLEditorView.swift +++ b/PlantUML/PlantUMLEditorView.swift @@ -36,7 +36,7 @@ struct PlantUMLEditorView: View { HStack { EditorView() .onReceive( customKeyboard.$itemsToAdd ) { items in - print( "\(items)") + // print( "\(items)") appendBelow(values: items) } if !isPreviewVisible { @@ -58,6 +58,7 @@ struct PlantUMLEditorView: View { } + func SaveButton() -> some View { Button( action: saveToDocument ) { @@ -91,6 +92,7 @@ struct PlantUMLEditorView: View { Label( "clone", systemImage: "arrow.down.doc") .labelStyle(.titleAndIcon) + } } @@ -102,6 +104,7 @@ struct PlantUMLEditorView: View { Label( "add above", systemImage: "arrow.up") .labelStyle(.titleAndIcon) + } } @@ -149,8 +152,12 @@ struct PlantUMLEditorView: View { ToolbarItemGroup(placement: .keyboard) { AddBelowButton() AddAboveButton() + ShowKeyboardButton( show: $customKeyboard.showKeyboard ) + } + } + .font(.footnote) .listStyle(SidebarListStyle()) } diff --git a/PlantUML/PlantUMLTextField.swift b/PlantUML/PlantUMLTextField.swift index f5896ba..cd42829 100644 --- a/PlantUML/PlantUMLTextField.swift +++ b/PlantUML/PlantUMLTextField.swift @@ -33,7 +33,7 @@ struct PlantUMLTextField: View { if( isFocused ) { - ShowKeyboardAccessoryButton + ShowKeyboardAccessoryButton( show: $showKeyboard ) } } @@ -53,29 +53,6 @@ struct PlantUMLTextField: View { } } -extension PlantUMLTextField { - - var ShowKeyboardAccessoryButton: some View { - - Button(action: { - - print( "show keyboard") - -// if let rootViewController = getWindows()?.first?.rootViewController { -// rootViewController.view.endEditing(true) -// } - - self.showKeyboard.toggle() - - }) { - - Image(systemName: "keyboard.badge.ellipsis") - .foregroundColor(.black.opacity(0.5)) - } - } -} - - struct PlantUMLTextField_Previews: PreviewProvider { static var previews: some View { PlantUMLTextField(value: "test", showKeyboard: .constant(false), onChange: { (v) in } ) diff --git a/PlantUMLKeyboard/Sources/PlantUMLKeyboard/ShowKeyboardButton.swift b/PlantUMLKeyboard/Sources/PlantUMLKeyboard/ShowKeyboardButton.swift new file mode 100644 index 0000000..3d772e3 --- /dev/null +++ b/PlantUMLKeyboard/Sources/PlantUMLKeyboard/ShowKeyboardButton.swift @@ -0,0 +1,55 @@ +// +// SwiftUIView.swift +// +// +// Created by Bartolomeo Sorrentino on 14/09/22. +// + +import SwiftUI + +public struct ShowKeyboardAccessoryButton: View { + + @Binding var show: Bool + + public init( show: Binding ) { + self._show = show + } + + public var body: some View { + Button(action: { + show.toggle() + }) { + Image(systemName: "keyboard.badge.ellipsis") + .foregroundColor(.black.opacity(0.5)) + } + + } +} + +public struct ShowKeyboardButton: View { + + @Binding var show: Bool + + public init( show: Binding ) { + self._show = show + } + + public var body: some View { + Button(action: { + show.toggle() + }) { + Label( "PlantUML Keyboard", systemImage: "keyboard.badge.ellipsis" ) + .labelStyle(.titleAndIcon) + } + + } +} + +struct ShowKeyboardButton_Previews: PreviewProvider { + static var previews: some View { + VStack { + ShowKeyboardButton( show: Binding.constant(false)) + ShowKeyboardAccessoryButton( show: Binding.constant(false)) + } + } +}