Comments (3)
Wow thank you so much for that example! That's super helpful and working exactly how I want! I was trying to set it all up within the .customKeyboard {} closure similar to the README example which is where my issues were stemming from. This is much more clear and clean. As I mentioned in my other comment I'm still learning so I appreciate all the help I can get! I'll go ahead and close the issue- thank you again for the help and for putting together this awesome project! It makes it so easy!
from customkeyboardkit.
Very happy to help :)
No issues, experience comes with practice. But what you faced initially is a limitation of my library that I haven't come around yet to find a solution for. Theoretically your expectation was correct and what you wanted to work, should have worked. Definitely not your fault.
from customkeyboardkit.
Hi @l3rosiah.
I tried your code and it seems to work fine on my machine (iOS17.0 Simulator). Heres my full example (I already passed the textDocument Proxy etc. to give you a hint of how the textfield receives the Characters :) )
struct ContentView: View {
@State private var value: String = "Test"
var body: some View {
TextField("", text: $value)
.customKeyboard(.firstKeyboard)
}
}
extension CustomKeyboard {
static var firstKeyboard: CustomKeyboard {
CustomKeyboardBuilder { proxy, onSubmit, feedback in
KeyboardView(textProxy: proxy, onSubmit: onSubmit, systemFeedbackHandler: feedback)
}
}
}
struct KeyboardView: View {
@State private var isShiftHeld = false
let textProxy: UITextDocumentProxy?
let onSubmit: CustomKeyboard.SubmitHandler?
let systemFeedbackHandler: CustomKeyboard.SystemFeedbackHandler?
let fullTexts = ["SHIFT", "A", "B", "C", "D", "E", "", "7", "8", "9", "F", "G", "H", "I", "J", "K", "", "4", "5", "6", "L", "M", "N", "O", "P", "Q", "", "1", "2", "3", "R", "S", "T", "U", "V", "W", "", "-", "0", ".", "X", "Y", "Z", ":", "(", ")", "", "CANCEL", "SPACE", "ENTER"]
let fullAltTexts = ["SHIFT", "A", "B", "C", "D", "E", "", "&", "@", ":", "F", "G", "H", "I", "J", "K", "", "%", "$", "!", "L", "M", "N", "O", "P", "Q", "", "*", ",", "?", "R", "S", "T", "U", "V", "W", "", "+", "=", "#", "X", "Y", "Z", ":", "[", "]", "", "CANCEL", "SPACE", "ENTER"]
let fullGrid = Array(repeating: GridItem(), count: 10)
init(textProxy: UITextDocumentProxy? = nil, onSubmit: CustomKeyboard.SubmitHandler? = nil, systemFeedbackHandler: CustomKeyboard.SystemFeedbackHandler? = nil) {
self.textProxy = textProxy
self.onSubmit = onSubmit
self.systemFeedbackHandler = systemFeedbackHandler
}
init() {
self.textProxy = nil
self.onSubmit = nil
self.systemFeedbackHandler = nil
}
var body: some View {
Text(isShiftHeld ? "true" : "false")
LazyVGrid(columns: fullGrid) {
ForEach(fullTexts.indices, id: \.self) { index in
Button(action: {
if index == 0 {
isShiftHeld.toggle()
} else if fullTexts[index] == "ENTER" {
onSubmit?()
} else {
textProxy?.insertText(isShiftHeld ? fullAltTexts[index] : fullTexts[index])
}
systemFeedbackHandler?()
}) {
Text(isShiftHeld ? fullAltTexts[index] : fullTexts[index])
.frame(width: 60, height: 60)
.foregroundColor(.white)
.background(.blue)
.cornerRadius(8)
}
.padding()
}
}
.padding()
}
}
#Preview {
KeyboardView()
}
See video:
https://github.com/paescebu/CustomKeyboardKit/assets/59558722/106eeff2-e26c-4687-aa01-88693665156c
Let me know if the issues persist :)
from customkeyboardkit.
Related Issues (18)
- Package Dependencies HOT 3
- Only calls one 'onSubmitCustomKeyboard' HOT 6
- Modifying state during view update HOT 3
- Missing important keys HOT 2
- SwiftUI-Introspect dependency outdate HOT 4
- Add onDismiss callback when keyboard dismissed HOT 10
- Access textDocumentProxy from TextField code block HOT 7
- Use of "\n" instead of custom onSubmitCustomKeyboard block HOT 9
- SwiftUI: Conditionally switch between custom / system keyboard HOT 4
- SwiftUI GeometryReader not Working with .customKeyboard HOT 5
- Custom keyboard does not show when axis argument is provided (iOS 16+) HOT 3
- Possibility to "relax" exact version of swiftui-introspect library? HOT 2
- [Question] playing different feedback sounds i.e input and delete HOT 2
- Performance issues with "many" custom keyboard elements HOT 15
- Strange padding above the CustomKeyboard HOT 4
- Question: Can this be used when creating a custom keyboard extension? HOT 1
- iOS 14.0 support
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from customkeyboardkit.