Skip to content

Commit

Permalink
feat: complete 'Save Custom Keyboard state' feature
Browse files Browse the repository at this point in the history
issue #7
  • Loading branch information
bsorrentino committed Jan 9, 2023
1 parent 98e6d07 commit af060cd
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 15 deletions.
10 changes: 8 additions & 2 deletions PlantUML/PlantUMLContentView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,12 @@ import LineEditor
// case row(id: String)
// }

typealias PlantUMLLineEditorView = LineEditorView<SyntaxStructure,PlantUMLKeyboardView>
typealias PlantUMLLineEditorView = LineEditorView<SyntaxStructure,Symbol>

struct PlantUMLContentView: View {
@Environment(\.editMode) private var editMode
@Environment(\.openURL) private var openURL
@State var keyboardTab: String = "general"

@EnvironmentObject private var diagram: PlantUMLDiagramObject

Expand All @@ -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()
Expand Down
12 changes: 7 additions & 5 deletions PlantUMLKeyboard/Sources/PlantUMLKeyboard/PlantUMLKeyboard.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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<String>, onHide: @escaping () -> Void, onPressSymbol: @escaping (Symbol) -> Void) {
self._selectedTab = selectedTab
self.onHide = onHide
self.onPressSymbol = onPressSymbol
}
Expand All @@ -17,14 +18,15 @@ public struct PlantUMLKeyboardView: LineEditorKeyboard {

ZStack(alignment: .topLeading) {

TabView {
TabView( selection: $selectedTab ) {

ForEach( plantUMLSymbols ) { group in
ContentView( group )
.tabItem {
Label( group.name, systemImage: "list.dash")
.labelStyle(.titleOnly)
}
tag( group.name )

}
}
Expand Down Expand Up @@ -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)
}
}
16 changes: 8 additions & 8 deletions PlantUMLKeyboard/Sources/PlantUMLKeyboard/PlantUMLSymbol.swift
Original file line number Diff line number Diff line change
Expand Up @@ -8,36 +8,36 @@
import UIKit
import LineEditor

struct Symbol : Decodable, Identifiable, CustomStringConvertible, LineEditorKeyboardSymbol {
public struct Symbol : Decodable, Identifiable, CustomStringConvertible, LineEditorKeyboardSymbol {

enum CodingKeys: String, CodingKey {
case id
case value
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 }
}

// var additionalValues: [String]? {
// 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 )

Expand Down

0 comments on commit af060cd

Please sign in to comment.