paescebu / customkeyboardkit Goto Github PK
View Code? Open in Web Editor NEWCreating custom In App Keyboards with SwiftUI has never been easier!
License: GNU General Public License v3.0
Creating custom In App Keyboards with SwiftUI has never been easier!
License: GNU General Public License v3.0
The library doesn't work for latest version of SwiftUI-Introspect
(0.10.0)
I'm working on an app that requires to display substantial amount of TextField inputs to user on a single page (think 30+ in a grid that can be visible all at once). While utalizing default keyboard and quickly entering / deleting values in each of the fields, everything works as expected.
Once I switched to using my custom keyboard via attaching .customKeyboard
to each of the text fields, I started noticing big performance issues.
Opening custom keyboard on first textfield works as expected, then things start to degrade rapidly when opening custom keyboards and entering values in more and more fields. Typing becomes laggy, animations suffer.
Is there any chance that every time a custom keyboard is shown, it never gets offloaded from memory / rendering tree when another TextField is focused, thus accumulating something over time that could be causing these rendering issues?
I know swift introspect library also adds some views on top of this to perform it's functionality, maybe that might play a role here as well?
There is a strange padding on the top of the keyboard. Is there any way to remove it?
Simplified Code
extension TextField {
func useDecimalPickerStyle() -> some View {
self.customKeyboard(.decimalPicker)
}
}
extension CustomKeyboard {
static var decimalPicker: CustomKeyboard {
CustomKeyboardBuilder { textDocumentProxy, submit, playSystemFeedback in
DecimalPicker(handler:textDocumentProxy)
}
}
}
struct DecimalPicker: View {
var body: some View {
VStack(alignment:.leading) {
HStack {
Button(action: {
}) {
Text(self.isWheel ? "キーボード入力に切り替える" : "ピッカー入力に切り替える").foregroundColor(Color.blue).font(Font.system(size: 18))
}
.padding()
Spacer()
Button(action: {
}) {
Text("完了").foregroundColor(Color.blue).font(Font.system(size: 18))
}
.padding()
}.background(Color(red: 245/255, green: 245/255, blue: 245/255))
}
.background(Color.white)
}
}
in custom keyboard has no delete button, case change button & no dismiss or done button
I've attempted to use a GeometryReader for a little bit more fine-tuned control over the keyboard and have not had any success. I tried outside and inside of the .customKeyboard modifier within a view, and both screw it up as to be completely unrecognizable.
Thanks for your hard work on this library, it's really useful!
I wonder if you can add an onDismiss
callback when custom keyboard dismissed?
When I click on other text fields (with default keyboard) while typing with custom keyboard, I need to handle something before dismissal and change the text.
Let me know if you need more details, thanks.
In our case the design calls for a text field with optional custom options (in custom keyboard), with a switch keyboard button in accessory view.
Just FYI:
Call of textDocumentProxy.insertText("\n")
should be used to confirm typing. This could help to get rid of .onSubmitCustomKeyboard
closure implementation and switch back to native .onSubmit
.
Started using CustomKeyboardKit today and it's a really pleasant library to work with! I was wondering if you would be open to possibility of relaxing version requirement of swiftui-introspect
dependency from exact
to "next major" or at least "next minor"?
Mainly, working in a project right now that uses latest version of this dependency 1.1.3
so it would be nice to share between libraries.
Alternatively, would you be open / what would it take to completely remove dependency on swiftui-introspect
? If this is a viable idea, I'd be down to having a stab at this, with some help (i.e. bullet points of what needs to be done).
Hello there! First off, thanks for your work on this package :)
I've been poking around with the library, and have found that when supplying the axis argument to a TextField
, the custom keyboard no longer shows, falling back on the standard keyboard.
I created a repo which should clearly demonstrate the issue: https://github.com/fraune/CustomKeyboardKit_TextFieldAxis_BugDemo
I forked this repo to see if I could figure it out myself, but I don't have as much experience with introspect. I'd love to hear if you have some thoughts on how we can work through this issue.
Cheers,
–Fraune
I am attempting to implement something a "Shift" key so that I can shift over to so alternate characters being shown by clicking it. However, anytime I try and use a state variable from within the custom keyboard it fails completely. I tested my code in a simple view and it worked fine, but not within the custom keyboard modifier.
`struct KeyboardView: View {
@State private var isShiftHeld = false
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)
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()
}
}) {
Text(isShiftHeld ? fullAltTexts[index] : fullTexts[index])
.frame(width: 60, height: 60)
.foregroundColor(.white)
.background(.blue)
.cornerRadius(8)
}
.padding()
}
}
.padding()
}
}
#Preview {
KeyboardView()
}`
There is a problem when I add to the project with package Dependencies
Hi 👋
Not sure if issues is correct place to ask this, as it is more of a question, but is it possible to somehow define which feedback sound needs to be played? As of now, it seems like "Input" sound is the only available option, but playing around with ios default keyboard there are 3 distinctive sounds for
Would it be possible to add an argument to playSystemFeedback
function that allows to define which sound should be played for custom keyboards?
This is such a help....thank you so much for posting it. You're absolutely right to say it is the easiest way to add a custom keyboard to SwiftUI.
I've been having one issue: only one onSubmitCustomKeyboard
is called, even if I have multiple instances with a few different text fields. I thought at first it might be something in my code, so here's what I did to check: I started a new project in Xcode, installed the package, and copied the code of your sample yesnt
keyboard. Then I only slightly modified your sample implementation:
struct ContentView: View {
@State var text1: String = ""
@State var text2: String = ""
@State var text3: String = ""
var body: some View {
VStack {
Text("Textfield #1:")
TextField("", text: $text1)
.customKeyboard(.yesnt)
.onSubmitCustomKeyboard {
print("Textfield #1 submit")
}
.textFieldStyle(RoundedBorderTextFieldStyle())
Text("Textfield #2")
TextField("", text: $text2)
.customKeyboard(.yesnt)
.onSubmitCustomKeyboard {
print("Textfield #2 submit")
}
.textFieldStyle(RoundedBorderTextFieldStyle())
Text("Textfield #3")
TextField("", text: $text3)
.customKeyboard(.yesnt)
.onSubmitCustomKeyboard {
print("Textfield #3 submit")
}
.textFieldStyle(RoundedBorderTextFieldStyle())
}
}
}
When run, only the first onSubmitCustomKeyboard
is ever called ("Textfield #1 submit"), even when submit?()
is called in Textfield #2 or Textfield #3.
Is that how it is supposed to work? In my own actual project, for some reason it is oddly calling the third instance of onSubmitCustomKeyboard
every time, and I can't make sense of why.
Hi @paescebu,
Sorry to bother you again.
I want to create a custom number keyboard which has calculator function, so I need to store some states for operator or result.
Is there any way I can access textDocumentProxy from TextField code block?
Code example:
struct NumberTextField: View {
@Binding var amountText: String
let placeholder: String?
let isAmountEditing: FocusState<Bool>.Binding
let onEditingChanged: (Bool) -> Void
// Some states for calculation
@State private var number = Double.zero
@State private var buttonType = AHNumberButtonType.none
@State private var operation = AHOperationType.none
@State private var isInputting = false
var body: some View {
TextField("", text: $amountText, onEditingChanged: onEditingChanged)
.customKeyboard(.numberPad)
.onInputChanged { textDocumentProxy, submit, playSystemFeedback in
// I want to access textDocumentProxy from here and do some calculation
}
.multilineTextAlignment(.trailing)
.focused(isAmountEditing)
}
}
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.