Skip to content

Commit d0a45c2

Browse files
authored
fix(android): clear focus on dismiss to prevent auto-focus transfer (#649)
* fix(android): clear focus on dismiss to prevent auto-focus transfer Closes #647 * chore: update changelog * chore: add input to example sheet
1 parent 702afb8 commit d0a45c2

3 files changed

Lines changed: 11 additions & 0 deletions

File tree

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,10 @@
22

33
## Unreleased
44

5+
### 🐛 Bug fixes
6+
7+
- **Android**: Fixed focused input in sheet causing auto-focus on main screen input after dismiss. ([#649](https://github.com/lodev09/react-native-true-sheet/pull/649) by [@lodev09](https://github.com/lodev09))
8+
59
## 3.10.0
610

711
### 🎉 New features

android/src/main/java/com/lodev09/truesheet/TrueSheetViewController.kt

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -757,6 +757,11 @@ class TrueSheetViewController(private val reactContext: ThemedReactContext) :
757757
private fun dismissKeyboard() {
758758
isKeyboardDismissProgrammatic = true
759759
KeyboardUtils.dismiss(reactContext)
760+
761+
// Clear focus from any focused view within the sheet to prevent
762+
// Android from auto-focusing the next focusable view on the main
763+
// screen when the sheet is removed from the hierarchy.
764+
sheetView?.findFocus()?.clearFocus()
760765
}
761766

762767
fun handleBackPress() {

example/shared/src/components/sheets/BasicSheet.tsx

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import { Button } from '../Button';
99
import { ButtonGroup } from '../ButtonGroup';
1010
import { Spacer } from '../Spacer';
1111
import { Header } from '../Header';
12+
import { Input } from '../Input';
1213

1314
interface BasicSheetProps extends TrueSheetProps {
1415
onNavigateToModal?: () => void;
@@ -119,6 +120,7 @@ export const BasicSheet = forwardRef((props: BasicSheetProps, ref: Ref<TrueSheet
119120
<Button text="Auto" onPress={() => resize(0)} />
120121
</ButtonGroup>
121122
<Spacer />
123+
<Input />
122124
<ButtonGroup>
123125
<Button text="Child Sheet" onPress={presentChild} />
124126
<Button text="PromptSheet" onPress={presentPromptSheet} />

0 commit comments

Comments
 (0)