diff --git a/PlantUML/PlantUMLContentView.swift b/PlantUML/PlantUMLContentView.swift index 523886e..312ad34 100644 --- a/PlantUML/PlantUMLContentView.swift +++ b/PlantUML/PlantUMLContentView.swift @@ -19,11 +19,12 @@ import LineEditor // case row(id: String) // } -typealias PlantUMLLineEditorView = LineEditorView +typealias PlantUMLLineEditorView = LineEditorView struct PlantUMLContentView: View { @Environment(\.editMode) private var editMode @Environment(\.openURL) private var openURL + @State var keyboardTab: String = "general" @EnvironmentObject private var diagram: PlantUMLDiagramObject @@ -49,7 +50,12 @@ struct PlantUMLContentView: View { if( isEditorVisible ) { PlantUMLLineEditorView( items: $diagram.items, fontSize: $fontSize, - showLine: $showLine) + showLine: $showLine) { onHide, onPressSymbol in + PlantUMLKeyboardView( selectedTab: $keyboardTab, + onHide: onHide, + onPressSymbol: onPressSymbol) + } + } // Divider().background(Color.blue).padding() diff --git a/PlantUMLKeyboard/Sources/PlantUMLKeyboard/PlantUMLKeyboard.swift b/PlantUMLKeyboard/Sources/PlantUMLKeyboard/PlantUMLKeyboard.swift index aded960..fe32eb0 100644 --- a/PlantUMLKeyboard/Sources/PlantUMLKeyboard/PlantUMLKeyboard.swift +++ b/PlantUMLKeyboard/Sources/PlantUMLKeyboard/PlantUMLKeyboard.swift @@ -2,13 +2,14 @@ import SwiftUI import UIKit import LineEditor -public struct PlantUMLKeyboardView: LineEditorKeyboard { - +public struct PlantUMLKeyboardView: View { + @Binding var selectedTab:String var onHide:() -> Void var onPressSymbol: (Symbol) -> Void - public init(onHide: @escaping () -> Void, onPressSymbol: @escaping (LineEditorKeyboardSymbol) -> Void) { + public init(selectedTab: Binding, onHide: @escaping () -> Void, onPressSymbol: @escaping (Symbol) -> Void) { + self._selectedTab = selectedTab self.onHide = onHide self.onPressSymbol = onPressSymbol } @@ -17,7 +18,7 @@ public struct PlantUMLKeyboardView: LineEditorKeyboard { ZStack(alignment: .topLeading) { - TabView { + TabView( selection: $selectedTab ) { ForEach( plantUMLSymbols ) { group in ContentView( group ) @@ -25,6 +26,7 @@ public struct PlantUMLKeyboardView: LineEditorKeyboard { Label( group.name, systemImage: "list.dash") .labelStyle(.titleOnly) } + tag( group.name ) } } @@ -126,7 +128,7 @@ extension PlantUMLKeyboardView { struct PlantUMLKeyboardView_Previews: PreviewProvider { static var previews: some View { - PlantUMLKeyboardView( onHide: { }, onPressSymbol: { _ in } ) + PlantUMLKeyboardView( selectedTab: .constant("general"), onHide: { }, onPressSymbol: { _ in } ) .previewInterfaceOrientation(.landscapeLeft) } } diff --git a/PlantUMLKeyboard/Sources/PlantUMLKeyboard/PlantUMLSymbol.swift b/PlantUMLKeyboard/Sources/PlantUMLKeyboard/PlantUMLSymbol.swift index 1263533..b63fc75 100644 --- a/PlantUMLKeyboard/Sources/PlantUMLKeyboard/PlantUMLSymbol.swift +++ b/PlantUMLKeyboard/Sources/PlantUMLKeyboard/PlantUMLSymbol.swift @@ -8,7 +8,7 @@ import UIKit import LineEditor -struct Symbol : Decodable, Identifiable, CustomStringConvertible, LineEditorKeyboardSymbol { +public struct Symbol : Decodable, Identifiable, CustomStringConvertible, LineEditorKeyboardSymbol { enum CodingKeys: String, CodingKey { case id @@ -16,14 +16,14 @@ struct Symbol : Decodable, Identifiable, CustomStringConvertible, LineEditorKeyb case additionalValues = "additional" case type } - var description: String { value } + public var description: String { value } - var id:String + public var id:String private var _value:String? - private(set) var additionalValues:[String]? - var type = "string" + public private(set) var additionalValues:[String]? + public var type = "string" - var value: String { + public var value: String { get { _value ?? id } } @@ -31,13 +31,13 @@ struct Symbol : Decodable, Identifiable, CustomStringConvertible, LineEditorKeyb // get { _additionalValues } // } - init( id:String, value:String? = nil, additionalValues: [String]? = nil) { + public init( id:String, value:String? = nil, additionalValues: [String]? = nil) { self.id = id self._value = value self.additionalValues = additionalValues } - init(from decoder: Decoder) throws { + public init(from decoder: Decoder) throws { let container = try decoder.container(keyedBy: CodingKeys.self )