Skip to content

Commit 3fb7b12

Browse files
authored
fix(ios): custom grabber missing tap-to-cycle-detent behavior (#571)
* feat(ios): tap custom grabber to cycle detents Closes #568 * chore: update changelog * chore: fix changelog category
1 parent b1ad3be commit 3fb7b12

4 files changed

Lines changed: 38 additions & 1 deletion

File tree

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
### 🐛 Bug fixes
66

7+
- **iOS**: Fixed custom grabber missing tap-to-cycle-detent behavior. ([#571](https://github.com/lodev09/react-native-true-sheet/pull/571) by [@lodev09](https://github.com/lodev09))
78
- **Android**: Fixed pull to refresh not working for short ScrollViews. ([#570](https://github.com/lodev09/react-native-true-sheet/pull/570) by [@lodev09](https://github.com/lodev09))
89

910
## 3.9.7

ios/TrueSheetViewController.mm

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -743,10 +743,33 @@ - (void)setupGrabber {
743743
[_grabberView applyConfiguration];
744744
_grabberView.hidden = !showGrabber;
745745

746+
__weak __typeof(self) weakSelf = self;
747+
_grabberView.onTap = ^{
748+
[weakSelf handleGrabberTap];
749+
};
750+
746751
[self.view bringSubviewToFront:_grabberView];
747752
} else {
748753
self.sheet.prefersGrabberVisible = showGrabber;
749754
_grabberView.hidden = YES;
755+
_grabberView.onTap = nil;
756+
}
757+
}
758+
759+
- (void)handleGrabberTap {
760+
NSInteger detentCount = _detents.count;
761+
if (detentCount == 0) return;
762+
763+
NSInteger currentIndex = self.currentDetentIndex;
764+
if (currentIndex < 0) return;
765+
766+
NSInteger nextIndex = (currentIndex + 1) % detentCount;
767+
if (nextIndex == 0 && detentCount == 1 && self.dismissible) {
768+
[self.presentingViewController dismissViewControllerAnimated:YES completion:nil];
769+
} else {
770+
[self.sheet animateChanges:^{
771+
[self resizeToDetentIndex:nextIndex];
772+
}];
750773
}
751774
}
752775

ios/core/TrueSheetGrabberView.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,9 @@ NS_ASSUME_NONNULL_BEGIN
3434
/// Whether the grabber color adapts to the background (default: YES)
3535
@property (nonatomic, strong, nullable) NSNumber *adaptive;
3636

37+
/// Called when the grabber is tapped
38+
@property (nonatomic, copy, nullable) void (^onTap)(void);
39+
3740
/// Adds the grabber view to a parent view with proper constraints
3841
- (void)addToView:(UIView *)parentView;
3942

ios/core/TrueSheetGrabberView.mm

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,9 +51,11 @@ - (BOOL)isAdaptive {
5151
#pragma mark - Setup
5252

5353
- (void)setupView {
54-
self.userInteractionEnabled = NO;
5554
self.clipsToBounds = YES;
5655

56+
UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(handleTap)];
57+
[self addGestureRecognizer:tap];
58+
5759
_vibrancyView = [[UIVisualEffectView alloc] initWithEffect:nil];
5860
_vibrancyView.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight;
5961
[self addSubview:_vibrancyView];
@@ -64,6 +66,14 @@ - (void)setupView {
6466
[_vibrancyView.contentView addSubview:_fillView];
6567
}
6668

69+
#pragma mark - Actions
70+
71+
- (void)handleTap {
72+
if (_onTap) {
73+
_onTap();
74+
}
75+
}
76+
6777
#pragma mark - Public
6878

6979
- (void)addToView:(UIView *)parentView {

0 commit comments

Comments
 (0)