package com.reactnativekeyboardcontroller.managers import com.facebook.react.bridge.Arguments import com.facebook.react.common.MapBuilder import com.facebook.react.uimanager.ThemedReactContext import com.reactnativekeyboardcontroller.events.FocusedInputLayoutChangedEvent import com.reactnativekeyboardcontroller.events.FocusedInputSelectionChangedEvent import com.reactnativekeyboardcontroller.events.FocusedInputTextChangedEvent import com.reactnativekeyboardcontroller.events.KeyboardTransitionEvent import com.reactnativekeyboardcontroller.extensions.emitEvent import com.reactnativekeyboardcontroller.listeners.WindowDimensionListener import com.reactnativekeyboardcontroller.views.EdgeToEdgeReactViewGroup class KeyboardControllerViewManagerImpl { private var listener: WindowDimensionListener? = null private var listenerContext: ThemedReactContext? = null fun createViewInstance(reactContext: ThemedReactContext): EdgeToEdgeReactViewGroup { if (listener == null || listenerContext !== reactContext) { listener?.detachListener() listener = WindowDimensionListener(reactContext) listener?.attachListener() listenerContext = reactContext } return EdgeToEdgeReactViewGroup(reactContext) } fun invalidate() { listener?.detachListener() listener = null listenerContext = null } fun synchronizeFocusedInputLayout(view: EdgeToEdgeReactViewGroup) { view.callback?.layoutObserver?.syncUpLayout() view.reactContext.emitEvent("KeyboardController::layoutDidSynchronize", Arguments.createMap()) } fun setEnabled( view: EdgeToEdgeReactViewGroup, enabled: Boolean, ) { view.active = enabled } fun setStatusBarTranslucent( view: EdgeToEdgeReactViewGroup, isStatusBarTranslucent: Boolean, ) { view.setStatusBarTranslucent(isStatusBarTranslucent) } fun setNavigationBarTranslucent( view: EdgeToEdgeReactViewGroup, isNavigationBarTranslucent: Boolean, ) { view.setNavigationBarTranslucent(isNavigationBarTranslucent) } fun setPreserveEdgeToEdge( view: EdgeToEdgeReactViewGroup, isPreservingEdgeToEdge: Boolean, ) { view.setPreserveEdgeToEdge(isPreservingEdgeToEdge) } fun setEdgeToEdge(view: EdgeToEdgeReactViewGroup) { view.setEdgeToEdge() } fun getExportedCustomDirectEventTypeConstants(): MutableMap { val map: MutableMap = MapBuilder.of( KeyboardTransitionEvent.Move.value, MapBuilder.of("registrationName", "onKeyboardMove"), KeyboardTransitionEvent.Start.value, MapBuilder.of("registrationName", "onKeyboardMoveStart"), KeyboardTransitionEvent.End.value, MapBuilder.of("registrationName", "onKeyboardMoveEnd"), KeyboardTransitionEvent.Interactive.value, MapBuilder.of("registrationName", "onKeyboardMoveInteractive"), FocusedInputLayoutChangedEvent.EVENT_NAME, MapBuilder.of("registrationName", "onFocusedInputLayoutChanged"), FocusedInputTextChangedEvent.EVENT_NAME, MapBuilder.of("registrationName", "onFocusedInputTextChanged"), FocusedInputSelectionChangedEvent.EVENT_NAME, MapBuilder.of("registrationName", "onFocusedInputSelectionChanged"), ) return map } companion object { const val NAME = "KeyboardControllerView" } }