fix: Optimize BottomSheetTextInputComponent to Prevent Redundant Shar… #2165
+24,251
−8,610
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
PR Description
Motivation
Currently, the
BottomSheetTextInputComponent
updates the shared valueshouldHandleKeyboardEvents.value
on every focus and blur event without checking if an update is actually needed. This leads to a cascade of reanimated worklet executions, which, in turn, overloads the UI thread. On Android devices, this heavy processing can cause ANR (Application Not Responding) issues.This PR aims to mitigate those issues by preventing unnecessary updates. By adding guard clauses that only update the shared value when its state actually changes, we can reduce the frequency of reanimated reactions and lighten the load on the UI thread, resulting in a smoother experience—especially on Android.
Changes
The
onFocus
andonBlur
callbacks in theBottomSheetTextInputComponent
have been updated to check the current state ofshouldHandleKeyboardEvents.value
before performing any update. This prevents redundant updates that trigger a cascade of worklet executions.Code Snippet
Testing
Confirmed that
shouldHandleKeyboardEvents.value
is only updated when its state needs to change.Verified that TextInput focus and blur events trigger the correct updates.
Observed a reduction in unnecessary reanimated worklet executions, helping to mitigate ANR issues on Android.
Feedback and suggestions are welcome!