Skip to content
Open
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
46 changes: 45 additions & 1 deletion ios/RCTDirectedScrollView/DirectedScrollViewManager.m
Original file line number Diff line number Diff line change
Expand Up @@ -13,17 +13,50 @@ @interface DirectedScrollView : RCTScrollView

@property (nonatomic, weak) id <DirectedScrollViewDelegate> delegate;

@property (nonatomic, assign) BOOL verticalBounceEnabled;
@property (nonatomic, assign) BOOL horizontalBounceEnabled;

@end

@implementation DirectedScrollView

#pragma mark - ScrollView delegate

@synthesize verticalBounceEnabled = _verticalBounceEnabled;
@synthesize horizontalBounceEnabled = _horizontalBounceEnabled;

// Tried to overwrite getter to manager default value
- (BOOL) verticalBounceEnabled {
return _verticalBounceEnabled ? _verticalBounceEnabled : TRUE;
}
- (BOOL) horizontalBounceEnabled {
return _horizontalBounceEnabled ? _horizontalBounceEnabled : TRUE;
}


- (void)scrollViewDidScroll:(UIScrollView *)scrollView
{
[super scrollViewDidScroll:scrollView];
UIView *contentView = [self contentView];

RCTLogInfo(@"verticalBounceEnabled -> %d", _verticalBounceEnabled);
RCTLogInfo(@"horizontalBounceEnabled -> %d", _horizontalBounceEnabled);

if(!_verticalBounceEnabled) {
if (scrollView.contentInset.bottom <= 0) {
[scrollView setContentInset:UIEdgeInsetsMake(scrollView.contentInset.top,scrollView.contentInset.right,0,scrollView.contentInset.left)];
} else if (scrollView.contentOffset.y < 0) {
[scrollView setContentOffset:CGPointMake(scrollView.contentOffset.x, 0) animated: false];
}
}
if(!_horizontalBounceEnabled) {
if (scrollView.contentOffset.x >= scrollView.contentSize.width - scrollView.frame.size.width) {
[scrollView setContentOffset:CGPointMake(scrollView.contentSize.width - scrollView.frame.size.width, scrollView.contentOffset.y) animated: false];
} else if (scrollView.contentOffset.y < 0) {
[scrollView setContentOffset:CGPointMake(0, scrollView.contentOffset.y) animated: false];
}
}

for (UIView *subview in contentView.reactSubviews)
{
DirectedScrollViewChild *scrollableChild = (DirectedScrollViewChild*)subview;
Expand Down Expand Up @@ -97,7 +130,6 @@ -(void)scrollViewDidEndDragging {
[self.bridge.eventDispatcher sendDeviceEventWithName:@"scrollViewDidEndDragging" body:nil];
}


// RCTScrollView properties

RCT_EXPORT_VIEW_PROPERTY(bounces, BOOL)
Expand Down Expand Up @@ -159,4 +191,16 @@ -(void)scrollViewDidEndDragging {
}];
}

RCT_CUSTOM_VIEW_PROPERTY(verticalBounceEnabled, BOOL, DirectedScrollView)
{
// Failed to set property
view.verticalBounceEnabled = json;
}

RCT_CUSTOM_VIEW_PROPERTY(horizontalBounceEnabled, BOOL, DirectedScrollView)
{
// Failed to set property
view.horizontalBounceEnabled = json;
}

@end