diff --git a/PdfView.js b/PdfView.js index 277b4026..02b09c5f 100644 --- a/PdfView.js +++ b/PdfView.js @@ -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 = { @@ -62,6 +64,8 @@ export default class PdfView extends Component { }, onScaleChanged: (scale) => { }, + showsHorizontalScrollIndicator: true, + showsVerticalScrollIndicator: true, }; constructor(props) { diff --git a/ios/RNPDFPdf/RNPDFPdfView.mm b/ios/RNPDFPdf/RNPDFPdfView.mm index af94cb78..cddec766 100644 --- a/ios/RNPDFPdf/RNPDFPdfView.mm +++ b/ios/RNPDFPdf/RNPDFPdfView.mm @@ -479,40 +479,8 @@ - (void)didSetProps:(NSArray *)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"])) { @@ -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