Skip to content

Commit

Permalink
Fix momentum scroll bug on iOS (#6473)
Browse files Browse the repository at this point in the history
Closes #4325
  • Loading branch information
yogevbd authored Aug 17, 2020
1 parent ec2b0a0 commit cb74af5
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 0 deletions.
4 changes: 4 additions & 0 deletions lib/ios/RNNComponentViewController.m
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
#import "RNNComponentViewController.h"
#import "UIView+Utils.h"

@implementation RNNComponentViewController

Expand Down Expand Up @@ -36,6 +37,9 @@ - (void)viewDidAppear:(BOOL)animated {
- (void)viewDidDisappear:(BOOL)animated {
[super viewDidDisappear:animated];
[self componentDidDisappear];

// Fix's momentum scroll bug https://github.com/wix/react-native-navigation/issues/4325
[self.view stopMomentumScrollViews];
}

- (void)loadView {
Expand Down
2 changes: 2 additions & 0 deletions lib/ios/Utils/UIView+Utils.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,6 @@ typedef NS_ENUM(NSInteger, ViewType) {

- (ViewType)viewType;

- (void)stopMomentumScrollViews;

@end
11 changes: 11 additions & 0 deletions lib/ios/Utils/UIView+Utils.m
Original file line number Diff line number Diff line change
Expand Up @@ -21,4 +21,15 @@ - (ViewType)viewType {
return ViewTypeOther;
}

- (void)stopMomentumScrollViews {
if ([self isKindOfClass:[UIScrollView class]]){
UIScrollView* scrollView = (UIScrollView*)self;
[scrollView setContentOffset:scrollView.contentOffset animated:NO];
} else {
for (UIView *subview in self.subviews) {
[subview stopMomentumScrollViews];
}
}
}

@end

0 comments on commit cb74af5

Please sign in to comment.