Skip to content

Commit 1048f52

Browse files
authored
fix: resolve view crash (#1444)
## 📜 Description Fixed `IllegalViewOperationException` crash on Android. ## 💡 Motivation and Context Original code has been introduced in #1355 and further started to be used in #1352 Now if view is not found it throws an unhandled exception and crashes the app. In reality we already handle "view not found" exception, so we should just add a proper try/catch block to handle this error correctly in Kotlin code 🤞 Closes #1443 ## 📢 Changelog <!-- High level overview of important changes --> <!-- For example: fixed status bar manipulation; added new types declarations; --> <!-- If your changes don't affect one of platform/language below - then remove this platform/language --> ### Android - wrap `resolveView` with `catch (e: IllegalViewOperationException)`; ## 🤔 How Has This Been Tested? Tested via e2e pipeline. ## 📝 Checklist - [x] CI successfully passed - [x] I added new mocks and corresponding unit-tests if library API was changed
1 parent 9a5761d commit 1048f52

1 file changed

Lines changed: 11 additions & 1 deletion

File tree

android/src/main/java/com/reactnativekeyboardcontroller/modules/KeyboardControllerModuleImpl.kt

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,14 +8,18 @@ import com.facebook.react.bridge.Arguments
88
import com.facebook.react.bridge.Promise
99
import com.facebook.react.bridge.ReactApplicationContext
1010
import com.facebook.react.bridge.UiThreadUtil
11+
import com.facebook.react.uimanager.IllegalViewOperationException
1112
import com.reactnativekeyboardcontroller.extensions.dp
1213
import com.reactnativekeyboardcontroller.extensions.screenLocation
1314
import com.reactnativekeyboardcontroller.extensions.uiManager
1415
import com.reactnativekeyboardcontroller.extensions.windowSoftInputMode
1516
import com.reactnativekeyboardcontroller.interactive.KeyboardAnimationController
17+
import com.reactnativekeyboardcontroller.log.Logger
1618
import com.reactnativekeyboardcontroller.traversal.FocusedInputHolder
1719
import com.reactnativekeyboardcontroller.traversal.ViewHierarchyNavigator
1820

21+
private val TAG = KeyboardControllerModuleImpl::class.qualifiedName
22+
1923
class KeyboardControllerModuleImpl(
2024
private val mReactContext: ReactApplicationContext,
2125
) {
@@ -89,7 +93,13 @@ class KeyboardControllerModuleImpl(
8993
promise: Promise,
9094
) {
9195
UiThreadUtil.runOnUiThread {
92-
val view = uiManager?.resolveView(viewTag.toInt())
96+
val view =
97+
try {
98+
uiManager?.resolveView(viewTag.toInt())
99+
} catch (e: IllegalViewOperationException) {
100+
Logger.w(TAG, "Could not resolve view for tag ${viewTag.toInt()}", e)
101+
null
102+
}
93103
if (view == null) {
94104
promise.reject("E_VIEW_NOT_FOUND", "Could not find view for tag")
95105
return@runOnUiThread

0 commit comments

Comments
 (0)