Skip to content

fix: OverKeyboardView rotation (fabric) #918

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

Merged
merged 2 commits into from
Apr 18, 2025
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,11 @@ class OverKeyboardHostView(
private var windowManager: WindowManager = reactContext.getSystemService(Context.WINDOW_SERVICE) as WindowManager
private var hostView: OverKeyboardRootViewGroup = OverKeyboardRootViewGroup(reactContext)

internal var stateWrapper: StateWrapper? = null
var stateWrapper: StateWrapper?
get() = hostView.stateWrapper
set(stateWrapper) {
hostView.stateWrapper = stateWrapper
}

init {
hostView.eventDispatcher = dispatcher
Expand Down Expand Up @@ -92,24 +96,14 @@ class OverKeyboardHostView(
PixelFormat.TRANSLUCENT,
)

stretchTo(fullScreen = true)
windowManager.addView(hostView, layoutParams)
}

fun hide() {
if (hostView.isAttached) {
windowManager.removeView(hostView)
stretchTo(fullScreen = false)
}
}

private fun stretchTo(fullScreen: Boolean) {
val displaySize = reactContext.getDisplaySize()
val newStateData: WritableMap = WritableNativeMap()
newStateData.putDouble("screenWidth", if (fullScreen) displaySize.x.toFloat().dp else 0.0)
newStateData.putDouble("screenHeight", if (fullScreen) displaySize.y.toFloat().dp else 0.0)
stateWrapper?.updateState(newStateData)
}
}

@SuppressLint("ViewConstructor")
Expand All @@ -120,6 +114,7 @@ class OverKeyboardRootViewGroup(
private val jsTouchDispatcher: JSTouchDispatcher = JSTouchDispatcher(this)
private var jsPointerDispatcher: JSPointerDispatcherCompat? = null
internal var eventDispatcher: EventDispatcher? = null
internal var stateWrapper: StateWrapper? = null
internal var isAttached = false

init {
Expand All @@ -131,13 +126,27 @@ class OverKeyboardRootViewGroup(
// region life cycles
override fun onAttachedToWindow() {
super.onAttachedToWindow()
val displaySize = reactContext.getDisplaySize()
stretchTo(width = displaySize.x, height = displaySize.y)
isAttached = true
}

override fun onDetachedFromWindow() {
super.onDetachedFromWindow()
stretchTo(width = 0, height = 0)
isAttached = false
}

override fun onSizeChanged(
width: Int,
height: Int,
oldWidth: Int,
oldHeight: Int,
) {
super.onSizeChanged(width, height, oldWidth, oldHeight)
stretchTo(width, height)
}

// endregion

// region Touch events handling
Expand Down Expand Up @@ -216,4 +225,14 @@ class OverKeyboardRootViewGroup(
reactContext.reactApplicationContext.handleException(RuntimeException(t))
}
// endregion

private fun stretchTo(
width: Int,
height: Int,
) {
val newStateData: WritableMap = WritableNativeMap()
newStateData.putDouble("screenWidth", width.toFloat().dp)
newStateData.putDouble("screenHeight", height.toFloat().dp)
stateWrapper?.updateState(newStateData)
}
}