KeyboardKit / KeyboardKitPro

KeyboardKit Pro helps you create custom keyboards for iOS and iPadOS.
https://keyboardkit.com
Other
112 stars 8 forks source link

Programmatic toggling of toolbar not working consistently #16

Open t14-consulting opened 4 weeks ago

t14-consulting commented 4 weeks ago

I have experienced that programmatic toggling works only intermittently.

I can illustrate the problem by using the demo app (v8.7 and Keyboardkit Pro 8.8.6) and trying to toggle the toolbar every second using a timer. I would expect the toolbar to toggle every second, but nothing happens even though the toggle variable is changing.

To reproduce the issue, change the demo app as follows: Change KeyboardViewController by adding: model and timer: class Model: ObservableObject { @Published var isToolbarToggled: Bool = true } class KeyboardViewController: KeyboardInputViewController { @ObservedObject var model = Model() var timer: Timer?

setup the time override func viewDidLoad() { ... timer = Timer.scheduledTimer(withTimeInterval: 1.0, repeats: true) { [weak self] _ in print("DEBUG: \(Date()) scheduledTime toggled=\(self!.model.isToolbarToggled)") self!.model.isToolbarToggled.toggle() } }

Pass the isToolbarToggled to DemoToolbarView setupPro( withLicenseKey: KeyboardApp.demoApp.licenseKey ?? "", licenseConfiguration: setupServices, // Specified below view: { controller in DemoKeyboardView(controller: controller, isToolbarToggled: self.$model.isToolbarToggled) } )

Change DemoToolbarView to accept the parameter: struct DemoKeyboardView: View { ... @Binding var isToolbarToggled: Bool ... var body: some View { KeyboardView( state: controller.state, services: keyboardServices, buttonContent: { $0.view }, buttonView: { $0.view }, emojiKeyboard: { $0.view }, toolbar: { params in // <- All view builders has parameters with more information DemoToolbar( controller: controller, toolbar: params.view, theme: $theme, isToggled: $isToolbarToggled ) } ) } }

Change DemoToolbar to accept the parameter: struct DemoToolbar<Toolbar: View>: View { ... @Binding var isToggled: Bool ... var body: some View { try? Keyboard.ToggleToolbar( isToggled: $isToggled, toolbar: autocompleteToolbar, toggledToolbar: menuToolbar ) .tint(.primary) } }

image

danielsaidi commented 4 weeks ago

Hi @t14-consulting

Thank you for the bug report - I'll look into this in a 8.9.x patch update.