Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: When using enablePaging={true} and horizontal={true}, showsHorizontalScrollIndicator={false} does not work. #904

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
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
4 changes: 4 additions & 0 deletions PdfView.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,8 @@ export default class PdfView extends Component {
singlePage: PropTypes.bool,
onPageSingleTap: PropTypes.func,
onScaleChanged: PropTypes.func,
showsHorizontalScrollIndicator: PropTypes.bool,
showsVerticalScrollIndicator: PropTypes.bool,
};

static defaultProps = {
Expand All @@ -62,6 +64,8 @@ export default class PdfView extends Component {
},
onScaleChanged: (scale) => {
},
showsHorizontalScrollIndicator: true,
showsVerticalScrollIndicator: true,
};

constructor(props) {
Expand Down
53 changes: 19 additions & 34 deletions ios/RNPDFPdf/RNPDFPdfView.mm
Original file line number Diff line number Diff line change
Expand Up @@ -479,40 +479,8 @@ - (void)didSetProps:(NSArray<NSString *> *)changedProps
}
}

if (_pdfDocument && ([changedProps containsObject:@"path"] || [changedProps containsObject:@"showsHorizontalScrollIndicator"])) {
if (_showsHorizontalScrollIndicator) {
for (UIView *subview in _pdfView.subviews) {
if ([subview isKindOfClass:[UIScrollView class]]) {
UIScrollView *scrollView = (UIScrollView *)subview;
scrollView.showsHorizontalScrollIndicator = YES;
}
}
} else {
for (UIView *subview in _pdfView.subviews) {
if ([subview isKindOfClass:[UIScrollView class]]) {
UIScrollView *scrollView = (UIScrollView *)subview;
scrollView.showsHorizontalScrollIndicator = NO;
}
}
}
}

if (_pdfDocument && ([changedProps containsObject:@"path"] || [changedProps containsObject:@"showsVerticalScrollIndicator"])) {
if (_showsVerticalScrollIndicator) {
for (UIView *subview in _pdfView.subviews) {
if ([subview isKindOfClass:[UIScrollView class]]) {
UIScrollView *scrollView = (UIScrollView *)subview;
scrollView.showsVerticalScrollIndicator = YES;
}
}
} else {
for (UIView *subview in _pdfView.subviews) {
if ([subview isKindOfClass:[UIScrollView class]]) {
UIScrollView *scrollView = (UIScrollView *)subview;
scrollView.showsVerticalScrollIndicator = NO;
}
}
}
if (_pdfDocument && ([changedProps containsObject:@"path"] || [changedProps containsObject:@"showsHorizontalScrollIndicator"] || [changedProps containsObject:@"showsVerticalScrollIndicator"])) {
[self setScrollIndicators:self horizontal:_showsHorizontalScrollIndicator vertical:_showsVerticalScrollIndicator depth:0];
}

if (_pdfDocument && ([changedProps containsObject:@"path"] || [changedProps containsObject:@"scrollEnabled"])) {
Expand Down Expand Up @@ -928,6 +896,23 @@ - (BOOL)gestureRecognizer:(UIGestureRecognizer *)gestureRecognizer shouldRecogni
return !_singlePage;
}

- (void)setScrollIndicators:(UIView *)view horizontal:(BOOL)horizontal vertical:(BOOL)vertical depth:(int)depth {
// max depth, prevent infinite loop
if (depth > 10) {
return;
}

if ([view isKindOfClass:[UIScrollView class]]) {
UIScrollView *scrollView = (UIScrollView *)view;
scrollView.showsHorizontalScrollIndicator = horizontal;
scrollView.showsVerticalScrollIndicator = vertical;
}

for (UIView *subview in view.subviews) {
[self setScrollIndicators:subview horizontal:horizontal vertical:vertical depth:depth + 1];
}
}

@end

#ifdef RCT_NEW_ARCH_ENABLED
Expand Down