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