Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
24 changes: 23 additions & 1 deletion ios/TrueSheetViewController.mm
Original file line number Diff line number Diff line change
Expand Up @@ -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 <React/RCTLog.h>
Expand Down Expand Up @@ -103,6 +104,7 @@ @implementation TrueSheetViewController {
CADisplayLink *_interactivePositionLink;

__weak TrueSheetViewController *_parentSheetController;
__weak UIView *_presenterFirstResponder;

UIView *_anchorView;

Expand Down Expand Up @@ -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]) {
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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];
}
}
}

Expand Down Expand Up @@ -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;
Expand Down
Loading