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

Merged
merged 1 commit into from
Feb 4, 2025
Merged
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
feat: add support for customizable scroll indicators in PdfView compo…
…nent

- Added `showsHorizontalScrollIndicator` and `showsVerticalScrollIndicator` props to PdfView.js for better user control over scroll indicators.
- Refactored RNPDFPdfView.mm to streamline the handling of scroll indicator visibility using a new `setScrollIndicators` method, improving code maintainability.
xinyucoding committed Jan 11, 2025
commit d1f7fc35e89534f6b0eb7bd16aff985532c85f12
4 changes: 4 additions & 0 deletions PdfView.js
Original file line number Diff line number Diff line change
@@ -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) {
53 changes: 19 additions & 34 deletions ios/RNPDFPdf/RNPDFPdfView.mm
Original file line number Diff line number Diff line change
@@ -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"])) {
@@ -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