Skip to content

Commit 31ee990

Browse files
committed
fix: OverKeyboardView rotation (fabric)
1 parent c44e7e7 commit 31ee990

File tree

1 file changed

+30
-11
lines changed

1 file changed

+30
-11
lines changed

android/src/main/java/com/reactnativekeyboardcontroller/views/overlay/OverKeyboardViewGroup.kt

Lines changed: 30 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,11 @@ class OverKeyboardHostView(
3030
private var windowManager: WindowManager = reactContext.getSystemService(Context.WINDOW_SERVICE) as WindowManager
3131
private var hostView: OverKeyboardRootViewGroup = OverKeyboardRootViewGroup(reactContext)
3232

33-
internal var stateWrapper: StateWrapper? = null
33+
var stateWrapper: StateWrapper?
34+
get() = hostView.stateWrapper
35+
set(stateWrapper) {
36+
hostView.stateWrapper = stateWrapper
37+
}
3438

3539
init {
3640
hostView.eventDispatcher = dispatcher
@@ -92,24 +96,14 @@ class OverKeyboardHostView(
9296
PixelFormat.TRANSLUCENT,
9397
)
9498

95-
stretchTo(fullScreen = true)
9699
windowManager.addView(hostView, layoutParams)
97100
}
98101

99102
fun hide() {
100103
if (hostView.isAttached) {
101104
windowManager.removeView(hostView)
102-
stretchTo(fullScreen = false)
103105
}
104106
}
105-
106-
private fun stretchTo(fullScreen: Boolean) {
107-
val displaySize = reactContext.getDisplaySize()
108-
val newStateData: WritableMap = WritableNativeMap()
109-
newStateData.putDouble("screenWidth", if (fullScreen) displaySize.x.toFloat().dp else 0.0)
110-
newStateData.putDouble("screenHeight", if (fullScreen) displaySize.y.toFloat().dp else 0.0)
111-
stateWrapper?.updateState(newStateData)
112-
}
113107
}
114108

115109
@SuppressLint("ViewConstructor")
@@ -120,6 +114,7 @@ class OverKeyboardRootViewGroup(
120114
private val jsTouchDispatcher: JSTouchDispatcher = JSTouchDispatcher(this)
121115
private var jsPointerDispatcher: JSPointerDispatcherCompat? = null
122116
internal var eventDispatcher: EventDispatcher? = null
117+
internal var stateWrapper: StateWrapper? = null
123118
internal var isAttached = false
124119

125120
init {
@@ -131,13 +126,27 @@ class OverKeyboardRootViewGroup(
131126
// region life cycles
132127
override fun onAttachedToWindow() {
133128
super.onAttachedToWindow()
129+
val displaySize = reactContext.getDisplaySize()
130+
stretchTo(width = displaySize.x, height = displaySize.y)
134131
isAttached = true
135132
}
136133

137134
override fun onDetachedFromWindow() {
138135
super.onDetachedFromWindow()
136+
stretchTo(width = 0, height = 0)
139137
isAttached = false
140138
}
139+
140+
override fun onSizeChanged(
141+
w: Int,
142+
h: Int,
143+
oldw: Int,
144+
oldh: Int,
145+
) {
146+
super.onSizeChanged(w, h, oldw, oldh)
147+
stretchTo(width = w, height = h)
148+
}
149+
141150
// endregion
142151

143152
// region Touch events handling
@@ -216,4 +225,14 @@ class OverKeyboardRootViewGroup(
216225
reactContext.reactApplicationContext.handleException(RuntimeException(t))
217226
}
218227
// endregion
228+
229+
private fun stretchTo(
230+
width: Int,
231+
height: Int,
232+
) {
233+
val newStateData: WritableMap = WritableNativeMap()
234+
newStateData.putDouble("screenWidth", width.toFloat().dp)
235+
newStateData.putDouble("screenHeight", height.toFloat().dp)
236+
stateWrapper?.updateState(newStateData)
237+
}
219238
}

0 commit comments

Comments
 (0)