From b4f4b88ead1c9f44cb935685be36cab2cebb1788 Mon Sep 17 00:00:00 2001 From: Jovanni Lo Date: Tue, 13 Oct 2026 23:12:55 +0800 Subject: [PATCH 1/2] fix(ios): hide the presenter's keyboard under a custom-dimmed sheet --- ios/TrueSheetViewController.mm | 24 +++++++++++++++++++++++- 1 file changed, 23 insertions(+), 1 deletion(-) diff --git a/ios/TrueSheetViewController.mm b/ios/TrueSheetViewController.mm index 127fd49c..638160f3 100644 --- a/ios/TrueSheetViewController.mm +++ b/ios/TrueSheetViewController.mm @@ -16,6 +16,7 @@ #import "utils/BlurUtil.h" #import "utils/GestureUtil.h" #import "utils/PlatformUtil.h" +#import "utils/UIView+FirstResponder.h" #import "utils/WindowUtil.h" #import @@ -103,6 +104,7 @@ @implementation TrueSheetViewController { CADisplayLink *_interactivePositionLink; __weak TrueSheetViewController *_parentSheetController; + __weak UIView *_presenterFirstResponder; UIView *_anchorView; @@ -451,6 +453,10 @@ - (BOOL)useCustomDimming { return self.dimmed && (self.dimColor != nil || self.dimOpacity != nil); } +- (BOOL)isDimmedAtEveryDetent { + return self.dimmed && [self.dimmedDetentIndex integerValue] == 0; +} + // Like the system dim, fades in between the detent below `dimmedDetentIndex` and the dimmed detent. - (CGFloat)dimAlphaForIndex:(CGFloat)index { if (![self useCustomDimming]) { @@ -515,6 +521,15 @@ - (void)viewWillAppear:(BOOL)animated { [self setupDimView]; + // UIKit hides the presenter's keyboard under a sheet dimmed at every detent and + // brings it back on dismiss, but custom dimming leaves the native sheet undimmed. + if ([self useCustomDimming] && [self isDimmedAtEveryDetent]) { + UIView *firstResponder = [presenter.view findFirstResponder]; + if ([firstResponder resignFirstResponder]) { + _presenterFirstResponder = firstResponder; + } + } + dispatch_async(dispatch_get_main_queue(), ^{ NSInteger index = self.currentDetentIndex; CGFloat position = self.currentPosition; @@ -758,6 +773,13 @@ - (void)emitWillDismissEvents { [self.delegate viewControllerWillBlur]; [self.delegate viewControllerWillDismiss]; [_parentSheetController.delegate viewControllerWillFocus]; + + // Restored once the dismiss commits, like UIKit's own keyboard preservation. + UIView *firstResponder = _presenterFirstResponder; + _presenterFirstResponder = nil; + if (!self.presentingViewController.isBeingDismissed) { + [firstResponder becomeFirstResponder]; + } } } @@ -1388,7 +1410,7 @@ - (void)setupSheetDetents { if ([self useCustomDimming]) { sheet.largestUndimmedDetentIdentifier = sheet.detents.lastObject.identifier; - } else if (self.dimmed && [self.dimmedDetentIndex integerValue] == 0) { + } else if ([self isDimmedAtEveryDetent]) { sheet.largestUndimmedDetentIdentifier = nil; } else { sheet.largestUndimmedDetentIdentifier = UISheetPresentationControllerDetentIdentifierLarge; From 39d4af65ffb131d57bf774792b1ee85d1dc28049 Mon Sep 17 00:00:00 2001 From: Jovanni Lo Date: Tue, 13 Oct 2026 23:13:17 +0800 Subject: [PATCH 2/2] docs: update changelog entry for #925 --- CHANGELOG.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index b6a7cbc4..9a743094 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -18,7 +18,7 @@ - Added `detentBackgrounds` with color strings or color/blur objects, native iOS transitions, and cross-fades elsewhere. ([#876](https://github.com/lodev09/react-native-true-sheet/pull/876) by [@lodev09](https://github.com/lodev09)) - Added `dismissThreshold` on Android and Web. Set it to `'short'` to dismiss on a short drag or fling, like Compose Material3's sheet. ([#880](https://github.com/lodev09/react-native-true-sheet/pull/880) by [@lodev09](https://github.com/lodev09)) - Support Expo SDK 58 and React Native 0.88. The Expo Router `Sheet` navigator works on Router 58, and reopening a sheet on iOS no longer shows a blank screen. ([#896](https://github.com/lodev09/react-native-true-sheet/pull/896) by [@lodev09](https://github.com/lodev09)) -- Added `dimColor` and `dimOpacity` to customize the color and opacity of the dim behind the sheet. ([#911](https://github.com/lodev09/react-native-true-sheet/pull/911), [#919](https://github.com/lodev09/react-native-true-sheet/pull/919) by [@IjzerenHein](https://github.com/IjzerenHein), [@nickcernera](https://github.com/nickcernera) and [@lodev09](https://github.com/lodev09)) +- Added `dimColor` and `dimOpacity` to customize the color and opacity of the dim behind the sheet. ([#911](https://github.com/lodev09/react-native-true-sheet/pull/911), [#919](https://github.com/lodev09/react-native-true-sheet/pull/919), [#925](https://github.com/lodev09/react-native-true-sheet/pull/925) by [@IjzerenHein](https://github.com/IjzerenHein), [@nickcernera](https://github.com/nickcernera) and [@lodev09](https://github.com/lodev09)) ### 🐛 Bug fixes