Skip to content

Commit

Permalink
Prevent unintended scrolls on native navigation
Browse files Browse the repository at this point in the history
  • Loading branch information
isidoro98 committed Nov 17, 2022
1 parent 6cd100a commit 24ce8b5
Showing 1 changed file with 8 additions and 3 deletions.
11 changes: 8 additions & 3 deletions React/Views/ScrollView/RCTScrollView.m
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
#import "UIView+Private.h"
#import "UIView+React.h"
#import "UIResponder+FirstResponder.h"
#import "RCTInputAccessoryView.h"

/**
* Include a custom scroll view subclass because we want to limit certain
Expand Down Expand Up @@ -308,6 +309,8 @@ - (void)_keyboardWillChangeFrame:(NSNotification *)notification
}

double duration = [notification.userInfo[UIKeyboardAnimationDurationUserInfoKey] doubleValue];
if (duration == 0) return;

UIViewAnimationCurve curve =
(UIViewAnimationCurve)[notification.userInfo[UIKeyboardAnimationCurveUserInfoKey] unsignedIntegerValue];
CGRect beginFrame = [notification.userInfo[UIKeyboardFrameBeginUserInfoKey] CGRectValue];
Expand All @@ -333,14 +336,16 @@ - (void)_keyboardWillChangeFrame:(NSNotification *)notification
// What value should be used? Should it be customizable with a prop?
CGFloat textFieldBottom = textFieldFrame.origin.y + textFieldFrame.size.height + 32;
CGFloat contentDiff = textFieldBottom - endFrame.origin.y;
if (textFieldBottom > endFrame.origin.y) {
if (textFieldBottom > endFrame.origin.y && endFrame.origin.y < beginFrame.origin.y) {
if (self.inverted) {
newContentOffset.y -= contentDiff;
} else {
newContentOffset.y += contentDiff;
}
}
} else {
} else {
return;
}
} else if ([firstResponder isKindOfClass: [UITextField class]] || [firstResponder isKindOfClass: [RCTInputAccessoryView class]]) {
CGFloat contentDiff = endFrame.origin.y - beginFrame.origin.y;
if (self.inverted) {
newContentOffset.y += contentDiff;
Expand Down

0 comments on commit 24ce8b5

Please sign in to comment.