Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Reload the keyboard using the in-keyboard settings #103

Open
rogomantik opened this issue Aug 27, 2016 · 3 comments
Open

Reload the keyboard using the in-keyboard settings #103

rogomantik opened this issue Aug 27, 2016 · 3 comments

Comments

@rogomantik
Copy link

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

@joshim5
Copy link

joshim5 commented Dec 30, 2016

Have you figured this out?

@joshim5
Copy link

joshim5 commented Dec 30, 2016

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!)
            }
        }
    }
}

@rogomantik
Copy link
Author

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants