Skip to content

Commit 89120e5

Browse files
authored
fix(ios): defer scroll-to-responder with dispatch_async (#592)
* fix(ios): defer scroll-to-responder with dispatch_async * chore: update changelog
1 parent c5b9708 commit 89120e5

3 files changed

Lines changed: 12 additions & 10 deletions

File tree

CHANGELOG.md

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,15 +2,14 @@
22

33
## Unreleased
44

5-
## 3.10.0-beta.0
6-
75
### 🎉 New features
86

97
- Add accessibility support to grabber view with VoiceOver/TalkBack actions and state descriptions. ([#587](https://github.com/lodev09/react-native-true-sheet/pull/587) by [@lodev09](https://github.com/lodev09))
108
- Add `scrollingExpandsSheet` option to `scrollableOptions`. ([#585](https://github.com/lodev09/react-native-true-sheet/pull/585) by [@lodev09](https://github.com/lodev09))
119

1210
### 🐛 Bug fixes
1311

12+
- **iOS**: Fixed keyboard scroll positioning when sheet auto-expands from a smaller detent. ([#592](https://github.com/lodev09/react-native-true-sheet/pull/592) by [@lodev09](https://github.com/lodev09))
1413
- **iOS**: Fixed position change not emitting when detent or index changed. ([#584](https://github.com/lodev09/react-native-true-sheet/pull/584) by [@lodev09](https://github.com/lodev09))
1514
- **Android**: Use RN `BackHandler` for back press detection for reliability across Android versions. ([#580](https://github.com/lodev09/react-native-true-sheet/pull/580) by [@lodev09](https://github.com/lodev09))
1615

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ export const PromptSheet = forwardRef((props: PromptSheetProps, ref: Ref<TrueShe
4444
<TrueSheet
4545
ref={sheetRef}
4646
name="prompt-sheet"
47-
detents={[1]}
47+
detents={[0.75, 1]}
4848
scrollable
4949
scrollableOptions={{ keyboardScrollOffset: FOOTER_HEIGHT + SPACING }}
5050
backgroundBlur="dark"

ios/TrueSheetContentView.mm

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -216,15 +216,18 @@ - (void)keyboardWillShow:(CGFloat)height duration:(NSTimeInterval)duration curve
216216
animations:^{
217217
[self setScrollViewContentInset:height
218218
indicatorInset:self->_originalIndicatorBottomInset + height];
219-
220-
if (firstResponder) {
221-
CGRect responderFrame = [firstResponder convertRect:firstResponder.bounds
222-
toView:self->_pinnedScrollView.scrollView];
223-
responderFrame.size.height += self.keyboardScrollOffset;
224-
[self->_pinnedScrollView.scrollView scrollRectToVisible:responderFrame animated:NO];
225-
}
226219
}
227220
completion:nil];
221+
222+
// Defer scroll until the next run loop so content insets are applied first
223+
if (firstResponder) {
224+
dispatch_async(dispatch_get_main_queue(), ^{
225+
CGRect responderFrame = [firstResponder convertRect:firstResponder.bounds
226+
toView:self->_pinnedScrollView.scrollView];
227+
responderFrame.size.height += self.keyboardScrollOffset;
228+
[self->_pinnedScrollView.scrollView scrollRectToVisible:responderFrame animated:YES];
229+
});
230+
}
228231
}
229232

230233
- (void)keyboardWillHide:(NSTimeInterval)duration curve:(UIViewAnimationOptions)curve {

0 commit comments

Comments
 (0)