tasty-imitation-keyboard icon indicating copy to clipboard operation
tasty-imitation-keyboard copied to clipboard

Reload the keyboard using the in-keyboard settings

Open rogomantik opened this issue 8 years ago • 3 comments

Hi, I put an option in the settings to change the keyboard characters to switch from qwerty to azerty I made a

func myKeyboard() -> Keyboard {
let myKeyboard = Keyboard()
if        preference.isQwerty      {
build qwerty
}else{
build azerty
}
return my keyboard
}

and a

class MyKB: KeyboardViewController {
override init(nibName nibNameOrNil: String?, bundle nibBundleOrNil: NSBundle?) {        
        super.init(nibName: nibNameOrNil, bundle: nibBundleOrNil)  
        self.keyboard = myKeyboard() //seems to be set only here
    }
    required init?(coder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
...

I overriden createSettings and @IBAction override func toggleSettings()

the value of preference.isQwerty is set correctly but I do not know what command to use to change the characters at the close of the settings and where call it

I tried to write self.keyboard = myKeyboard() after changing the setting but does not works

*If I hit the globe button and change the keyboard when appears again is set and works correctly

do you have any advice?

thanks

rogomantik avatar Aug 27 '16 21:08 rogomantik

Have you figured this out?

joshim5 avatar Dec 30 '16 20:12 joshim5

You need to modify the actual views of the keys. The Keyboard class only points to the Keys. Changing the Keyboard will not change the views. I have also overriden toggleSettings(). In my case, I added an extra instance variable to the key class called letter. From there, I ran the following code in my toggleSettings() function:

let pages : [Page] = self.keyboard.pages
for page in pages {
    let rows : [[Key]] = page.rows
    for row in rows {
        for key in row {
            if key.letter != nil {
                key.setLetter(key.letter!)
            }
        }
    }
}

joshim5 avatar Dec 30 '16 21:12 joshim5

I checked a lot of forks and made a func and use a bool to track the changes in settings

class KeyboardViewController: UIInputViewController {

 func rebootKeyboard() {
        //if #NSUserDefaults group#.boolForKey("rebootKeyboard") {

            // call to function to set new letters arrays
            
            self.keyboard = mKeyboard()    //  mKeyboard() -> Keyboard (create all the keys and pages with updated values)
            self.forwardingView.resetTrackedViews()
            self.shiftStartingState = nil
            self.shiftWasMultitapped = false
            
            self.layout?.rasterizeKeys(true)
            self.forwardingView.removeSubviews()
            
            self.keyboardHeight = self.heightForOrientation(self.currentInterfaceOrientation, withTopBanner: false)
            
            self.constraintsAdded = false
            self.setupLayout()
            #NSUserDefaults group#.setBool(false, forKey: "rebootKeyboard") //reset the bool
            #NSUserDefaults group#.synchronize()
        //}
   }
    
}

I call it this way

class TheKeybo: KeyboardViewController {

@IBAction override func toggleSettings() { //
       [...]
      
        if #NSUserDefaults group#.boolForKey("rebootKeyboard") {
           rebootKeyboard() //called only if settings changed
       }
       
       [...]    
}
}

I use it in a published app but i get some crashes on the extension but only 1 crash each

PlugInKit: -[PKService run] CoreText: bool TAATMorphSubtableMorx::FetchInitialClass(TRunGlue&, CFRange, TRunGlue::TGlyph&, long&, TAATMorphSubtable::GlyphState&) QuartzCore: CA::Render::copy_elements(void*, CGPathElement const*) QuartzCore: CA::Transaction::add_deleted_id(unsigned long, unsigned int, unsigned int) CoreFoundation: __exceptionPreprocess CoreGraphics: (anonymous namespace)::adaptor::callback(void*, CGPathElementType, CGPoint const*) libswiftCore.dylib: DYLD-STUB$$objc_msgSend + 0

and others - i do not use full access

rogomantik avatar Dec 31 '16 11:12 rogomantik