Skip to content

Commit

Permalink
feat: integrate use case to show a custom keyboard - #1
Browse files Browse the repository at this point in the history
  • Loading branch information
bsorrentino committed Sep 7, 2022
1 parent a6e9c2f commit e8a80f9
Show file tree
Hide file tree
Showing 5 changed files with 188 additions and 45 deletions.
42 changes: 40 additions & 2 deletions PlantUML.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@
objects = {

/* Begin PBXBuildFile section */
A077460F28C7D818007C5C13 /* PlantUMLTextField.swift in Sources */ = {isa = PBXBuildFile; fileRef = A077460E28C7D818007C5C13 /* PlantUMLTextField.swift */; };
A077461628C7F25C007C5C13 /* PlantUMLKeyboard in Frameworks */ = {isa = PBXBuildFile; productRef = A077461528C7F25C007C5C13 /* PlantUMLKeyboard */; };
A0A42A76289ABC2D00E929EB /* PlantUMLDiagramView.swift in Sources */ = {isa = PBXBuildFile; fileRef = A0A42A75289ABC2D00E929EB /* PlantUMLDiagramView.swift */; };
A0A42A77289ABC2D00E929EB /* PlantUMLDiagramView.swift in Sources */ = {isa = PBXBuildFile; fileRef = A0A42A75289ABC2D00E929EB /* PlantUMLDiagramView.swift */; };
A0A42A79289AC37C00E929EB /* PlantUMLDiagramObject.swift in Sources */ = {isa = PBXBuildFile; fileRef = A0A42A78289AC37C00E929EB /* PlantUMLDiagramObject.swift */; };
Expand Down Expand Up @@ -108,9 +110,14 @@
/* End PBXContainerItemProxy section */

/* Begin PBXFileReference section */
A077460D28C7D49D007C5C13 /* PlantUMLKeyboard */ = {isa = PBXFileReference; lastKnownFileType = wrapper; path = PlantUMLKeyboard; sourceTree = "<group>"; };
A077460E28C7D818007C5C13 /* PlantUMLTextField.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = PlantUMLTextField.swift; sourceTree = "<group>"; };
A077461028C7DF19007C5C13 /* PlantUMLKeyboard */ = {isa = PBXFileReference; lastKnownFileType = wrapper; path = PlantUMLKeyboard; sourceTree = "<group>"; };
A077461128C7DF74007C5C13 /* PlantUMLKeyboard */ = {isa = PBXFileReference; lastKnownFileType = wrapper; path = PlantUMLKeyboard; sourceTree = "<group>"; };
A077461728C7F279007C5C13 /* PlantUMLKeyboard */ = {isa = PBXFileReference; lastKnownFileType = wrapper; path = PlantUMLKeyboard; sourceTree = "<group>"; };
A0A42A75289ABC2D00E929EB /* PlantUMLDiagramView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = PlantUMLDiagramView.swift; sourceTree = "<group>"; };
A0A42A78289AC37C00E929EB /* PlantUMLDiagramObject.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = PlantUMLDiagramObject.swift; sourceTree = "<group>"; };
A0A42A7B289AD9FA00E929EB /* README.md */ = {isa = PBXFileReference; lastKnownFileType = net.daringfireball.markdown; path = README.md; sourceTree = "<group>"; };
A0A42A7B289AD9FA00E929EB /* README.md */ = {isa = PBXFileReference; lastKnownFileType = net.daringfireball.markdown; name = README.md; path = ../README.md; sourceTree = "<group>"; };
A0C1657C289FD315004EB5C7 /* SwiftPlantUMLView.playground */ = {isa = PBXFileReference; lastKnownFileType = file.playground; path = SwiftPlantUMLView.playground; sourceTree = "<group>"; xcLanguageSpecificationIdentifier = xcode.lang.swift; };
A0D3C64628984A0E000838D7 /* PlantUML.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = PlantUML.app; sourceTree = BUILT_PRODUCTS_DIR; };
A0D3C64928984A0E000838D7 /* PlantUMLApp.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = PlantUMLApp.swift; sourceTree = "<group>"; };
Expand Down Expand Up @@ -156,6 +163,7 @@
isa = PBXFrameworksBuildPhase;
buildActionMask = 2147483647;
files = (
A077461628C7F25C007C5C13 /* PlantUMLKeyboard in Frameworks */,
);
runOnlyForDeploymentPostprocessing = 0;
};
Expand All @@ -176,18 +184,37 @@
/* End PBXFrameworksBuildPhase section */

/* Begin PBXGroup section */
A077460C28C7D49D007C5C13 /* Packages */ = {
isa = PBXGroup;
children = (
A077460D28C7D49D007C5C13 /* PlantUMLKeyboard */,
A077461028C7DF19007C5C13 /* PlantUMLKeyboard */,
A077461128C7DF74007C5C13 /* PlantUMLKeyboard */,
A077461728C7F279007C5C13 /* PlantUMLKeyboard */,
);
name = Packages;
sourceTree = "<group>";
};
A077461228C7EF6A007C5C13 /* Frameworks */ = {
isa = PBXGroup;
children = (
);
name = Frameworks;
sourceTree = "<group>";
};
A0D3C63D28984A0E000838D7 = {
isa = PBXGroup;
children = (
A077460C28C7D49D007C5C13 /* Packages */,
A0EF7AF128C40A6300660F09 /* PlantUMLKeyboard */,
A0C1657C289FD315004EB5C7 /* SwiftPlantUMLView.playground */,
A0A42A7B289AD9FA00E929EB /* README.md */,
A0D3C71D28987D94000838D7 /* SwiftPlantUML.playground */,
A0D3C6A72898770F000838D7 /* SwiftPlantUMLFramework */,
A0D3C64828984A0E000838D7 /* PlantUML */,
A0D3C65C28984A10000838D7 /* PlantUMLTests */,
A0D3C66628984A11000838D7 /* PlantUMLUITests */,
A0D3C64728984A0E000838D7 /* Products */,
A077461228C7EF6A007C5C13 /* Frameworks */,
);
sourceTree = "<group>";
};
Expand All @@ -206,6 +233,7 @@
children = (
A0D3C64928984A0E000838D7 /* PlantUMLApp.swift */,
A0D3C64B28984A0E000838D7 /* PlantUMLDocument.swift */,
A077460E28C7D818007C5C13 /* PlantUMLTextField.swift */,
A0D3C64D28984A0E000838D7 /* PalntUMLEditorView.swift */,
A0A42A75289ABC2D00E929EB /* PlantUMLDiagramView.swift */,
A0A42A78289AC37C00E929EB /* PlantUMLDiagramObject.swift */,
Expand Down Expand Up @@ -235,6 +263,7 @@
A0D3C66628984A11000838D7 /* PlantUMLUITests */ = {
isa = PBXGroup;
children = (
A0A42A7B289AD9FA00E929EB /* README.md */,
A0D3C66728984A11000838D7 /* PlantUMLUITests.swift */,
A0D3C66928984A11000838D7 /* PlantUMLUITestsLaunchTests.swift */,
);
Expand Down Expand Up @@ -320,6 +349,7 @@
);
name = PlantUML;
packageProductDependencies = (
A077461528C7F25C007C5C13 /* PlantUMLKeyboard */,
);
productName = PlantUML;
productReference = A0D3C64628984A0E000838D7 /* PlantUML.app */;
Expand Down Expand Up @@ -440,6 +470,7 @@
A0A42A79289AC37C00E929EB /* PlantUMLDiagramObject.swift in Sources */,
A0D3C6F92898770F000838D7 /* String+Extensions.swift in Sources */,
A0D3C64A28984A0E000838D7 /* PlantUMLApp.swift in Sources */,
A077460F28C7D818007C5C13 /* PlantUMLTextField.swift in Sources */,
A0D3C6F32898770F000838D7 /* PlantUMLScript.swift in Sources */,
A0D3C70E2898770F000838D7 /* PlantUMLPresenting.swift in Sources */,
A0D3C71A2898770F000838D7 /* NoLogger.swift in Sources */,
Expand Down Expand Up @@ -837,6 +868,13 @@
defaultConfigurationName = Release;
};
/* End XCConfigurationList section */

/* Begin XCSwiftPackageProductDependency section */
A077461528C7F25C007C5C13 /* PlantUMLKeyboard */ = {
isa = XCSwiftPackageProductDependency;
productName = PlantUMLKeyboard;
};
/* End XCSwiftPackageProductDependency section */
};
rootObject = A0D3C63E28984A0E000838D7 /* Project object */;
}
75 changes: 39 additions & 36 deletions PlantUML/PalntUMLEditorView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -6,29 +6,14 @@
//

import SwiftUI
import PlantUMLKeyboard

// [Managing Focus in SwiftUI List Views](https://peterfriese.dev/posts/swiftui-list-focus/)
enum Focusable: Hashable {
case none
case row(id: String)
}

struct PlantUMLTextField: View {
@State var value: String

var onChange: ( String ) -> Void

var body: some View {
TextField( "", text: $value )
.textInputAutocapitalization(.never)
.font(Font.system(size: 15).monospaced())
.submitLabel(.done)
.onChange(of: value
, perform: onChange )

}

}
struct PalntUMLEditorView: View {
@Environment(\.editMode) private var editMode
@Environment(\.openURL) private var openURL
Expand All @@ -40,6 +25,40 @@ struct PalntUMLEditorView: View {

@State private var isPreviewVisible = false

@State private var showKeyboard = false

var body: some View {
ZStack(alignment: .bottom) {

GeometryReader { _ in
HStack {
PlantUMLEditorView()
if !isPreviewVisible {
PlantUMLDiagramView( url: diagram.buildURL() )
}
}
.toolbar {
ToolbarItemGroup(placement: .navigationBarLeading) {
PreviewButton()
}
ToolbarItemGroup(placement: .navigationBarTrailing) {
EditButton()
SaveButton()
}
}
}

if( showKeyboard ) {

PlantUMLKeyboardView(
show: Binding.constant(true),
value:Binding.constant("")
)
}
}

}

func SaveButton() -> some View {

Button( action: saveToDocument ) {
Expand All @@ -64,6 +83,7 @@ struct PalntUMLEditorView: View {
// .foregroundColor(.orange)
// })
}

func AddCloneButton( theItem item: SyntaxStructure ) -> some View {

return Button {
Expand All @@ -75,7 +95,6 @@ struct PalntUMLEditorView: View {
}
}


func AddAboveButton( theItem item: SyntaxStructure? = nil ) -> some View {

return Button {
Expand Down Expand Up @@ -112,7 +131,9 @@ struct PalntUMLEditorView: View {
AddCloneButton( theItem: item )
}
}
PlantUMLTextField( value: item.rawValue, onChange: updateItem )
PlantUMLTextField( value: item.rawValue,
showKeyboard: $showKeyboard,
onChange: updateItem )
.focused($focusedItem, equals: .row(id: item.id))
.onSubmit(of: .text) {
// openURL( diagram.buildURL() )
Expand All @@ -135,24 +156,6 @@ struct PalntUMLEditorView: View {

}

var body: some View {
HStack {
PlantUMLEditorView()
if !isPreviewVisible {
PlantUMLDiagramView( url: diagram.buildURL() )
}
}
.toolbar {
ToolbarItemGroup(placement: .navigationBarLeading) {
PreviewButton()
}
ToolbarItemGroup(placement: .navigationBarTrailing) {
EditButton()
SaveButton()
}
}

}

}

Expand Down
81 changes: 79 additions & 2 deletions PlantUML/PlantUMLTextField.swift
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,92 @@
//

import SwiftUI
import PlantUMLKeyboard

fileprivate struct PlantUMLTextField_old: View {
@State var value: String

var onChange: ( String ) -> Void

var body: some View {
TextField( "", text: $value )
.textInputAutocapitalization(.never)
.font(Font.system(size: 15).monospaced())
.submitLabel(.done)
.onChange(of: value
, perform: onChange )

}

}

struct PlantUMLTextField: View {
@State var value: String
@Binding var showKeyboard: Bool

@FocusState private var isFocused: Bool

var onChange: ( String ) -> Void


var body: some View {
Text(/*@START_MENU_TOKEN@*/"Hello, World!"/*@END_MENU_TOKEN@*/)

VStack {

HStack(spacing: 15){

TextField( "", text: $value )
.textInputAutocapitalization(.never)
.font(Font.system(size: 15).monospaced())
.submitLabel(.done)
.focused($isFocused)
.onChange(of: value, perform: onChange )

if( isFocused ) {
ShowKeyboardAccessoryButton
}
}

}
// .background(Color("Color")
// .animation(.easeInOut(duration: 2), value: 1.0)
.edgesIgnoringSafeArea(.all)
.onAppear {

NotificationCenter.default.addObserver(forName: UIResponder.keyboardWillChangeFrameNotification,
object: nil,
queue: .main) { (_) in
self.showKeyboard = false
}
}

}
}

extension PlantUMLTextField {

var ShowKeyboardAccessoryButton: some View {

Button(action: {

print( "show keyboard")

if let rootViewController = getRootViewController() {
rootViewController.view.endEditing(true)
}

self.showKeyboard.toggle()

}) {

Image(systemName: "smiley").foregroundColor(.black.opacity(0.5))
}
}
}


struct PlantUMLTextField_Previews: PreviewProvider {
static var previews: some View {
PlantUMLTextField()
PlantUMLTextField(value: "test", showKeyboard: .constant(false), onChange: { (v) in } )
}
}
3 changes: 3 additions & 0 deletions PlantUML4iPad.xcworkspace/contents.xcworkspacedata

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit e8a80f9

Please sign in to comment.