Giter VIP home page Giter VIP logo

Comments (3)

l3rosiah avatar l3rosiah commented on May 27, 2024 2

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.

paescebu avatar paescebu commented on May 27, 2024 1

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.

paescebu avatar paescebu commented on May 27, 2024

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)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.