From d9e0714379591801faa2b7fccffdd882b7d76244 Mon Sep 17 00:00:00 2001 From: Kishan Jadav Date: Sat, 3 Jan 2026 09:29:44 +0000 Subject: [PATCH 1/2] feat(ios): support for corner radius --- ios/RNPDFPdf/RNPDFPdfView.mm | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) diff --git a/ios/RNPDFPdf/RNPDFPdfView.mm b/ios/RNPDFPdf/RNPDFPdfView.mm index 15c9b05f..b32dd6c0 100644 --- a/ios/RNPDFPdf/RNPDFPdfView.mm +++ b/ios/RNPDFPdf/RNPDFPdfView.mm @@ -221,6 +221,10 @@ - (void)updateLayoutMetrics:(const facebook::react::LayoutMetrics &)layoutMetric _initialed = YES; [self didSetProps:mProps]; + + if (self.layer.cornerRadius > 0) { + [self applyCornerRadius:_pdfView radius:self.layer.cornerRadius]; + } } - (void)handleCommand:(const NSString *)commandName args:(const NSArray *)args @@ -532,11 +536,30 @@ - (void)didSetProps:(NSArray *)changedProps } _pdfView.backgroundColor = [UIColor clearColor]; + if (self.layer.cornerRadius > 0) { + [self applyCornerRadius:_pdfView radius:self.layer.cornerRadius]; + } + [_pdfView layoutDocumentView]; [self setNeedsDisplay]; } } +- (void)applyCornerRadius:(UIView *)view radius:(CGFloat)radius { + view.layer.cornerRadius = self.layer.cornerRadius; + view.layer.masksToBounds = YES; + + // Recursively apply the corner radius to the subviews, otherwise those will take precendence + if ([view isKindOfClass:[UIScrollView class]]) { + view.layer.cornerRadius = radius; + view.layer.masksToBounds = YES; + view.clipsToBounds = YES; + } + + for (UIView *subview in view.subviews) { + [self applyCornerRadius:subview radius:radius]; + } +} - (void)reactSetFrame:(CGRect)frame { @@ -550,6 +573,10 @@ - (void)reactSetFrame:(CGRect)frame _initialed = YES; [self didSetProps:mProps]; + + if (self.layer.cornerRadius > 0) { + [self applyCornerRadius:_pdfView radius:self.layer.cornerRadius]; + } } From ac79a13de495745e9cb94fe73fca2b0ff62b146f Mon Sep 17 00:00:00 2001 From: Kishan Jadav Date: Sat, 3 Jan 2026 10:13:30 +0000 Subject: [PATCH 2/2] tweak ios corner radius to use a clipping view --- ios/RNPDFPdf/RNPDFPdfView.mm | 40 ++++++++++++++---------------------- 1 file changed, 15 insertions(+), 25 deletions(-) diff --git a/ios/RNPDFPdf/RNPDFPdfView.mm b/ios/RNPDFPdf/RNPDFPdfView.mm index b32dd6c0..e1e60f45 100644 --- a/ios/RNPDFPdf/RNPDFPdfView.mm +++ b/ios/RNPDFPdf/RNPDFPdfView.mm @@ -66,6 +66,7 @@ @implementation RNPDFPdfView RCTBridge *_bridge; PDFDocument *_pdfDocument; PDFView *_pdfView; + UIView *_pdfClipView; PDFOutline *root; float _fixScaleFactor; bool _initialed; @@ -212,7 +213,8 @@ - (void)updateLayoutMetrics:(const facebook::react::LayoutMetrics &)layoutMetric { // Fabric equivalent of `reactSetFrame` method [super updateLayoutMetrics:layoutMetrics oldLayoutMetrics:oldLayoutMetrics]; - _pdfView.frame = CGRectMake(0, 0, layoutMetrics.frame.size.width, layoutMetrics.frame.size.height); + _pdfClipView.frame = CGRectMake(0, 0, layoutMetrics.frame.size.width, layoutMetrics.frame.size.height); + _pdfView.frame = _pdfClipView.bounds; NSMutableArray *mProps = [_changedProps mutableCopy]; if (_initialed) { @@ -223,7 +225,8 @@ - (void)updateLayoutMetrics:(const facebook::react::LayoutMetrics &)layoutMetric [self didSetProps:mProps]; if (self.layer.cornerRadius > 0) { - [self applyCornerRadius:_pdfView radius:self.layer.cornerRadius]; + _pdfClipView.layer.cornerRadius = self.layer.cornerRadius; + _pdfClipView.layer.masksToBounds = YES; } } @@ -281,8 +284,12 @@ - (void)initCommonProps _initialed = NO; _changedProps = NULL; - [self addSubview:_pdfView]; + _pdfClipView = [[UIView alloc] initWithFrame:self.bounds]; + _pdfClipView.backgroundColor = [UIColor clearColor]; + _pdfClipView.clipsToBounds = YES; + [self addSubview:_pdfClipView]; + [_pdfClipView addSubview:_pdfView]; // register notification NSNotificationCenter *center = [NSNotificationCenter defaultCenter]; @@ -536,35 +543,16 @@ - (void)didSetProps:(NSArray *)changedProps } _pdfView.backgroundColor = [UIColor clearColor]; - if (self.layer.cornerRadius > 0) { - [self applyCornerRadius:_pdfView radius:self.layer.cornerRadius]; - } - [_pdfView layoutDocumentView]; [self setNeedsDisplay]; } } -- (void)applyCornerRadius:(UIView *)view radius:(CGFloat)radius { - view.layer.cornerRadius = self.layer.cornerRadius; - view.layer.masksToBounds = YES; - - // Recursively apply the corner radius to the subviews, otherwise those will take precendence - if ([view isKindOfClass:[UIScrollView class]]) { - view.layer.cornerRadius = radius; - view.layer.masksToBounds = YES; - view.clipsToBounds = YES; - } - - for (UIView *subview in view.subviews) { - [self applyCornerRadius:subview radius:radius]; - } -} - - (void)reactSetFrame:(CGRect)frame { [super reactSetFrame:frame]; - _pdfView.frame = CGRectMake(0, 0, frame.size.width, frame.size.height); + _pdfClipView.frame = CGRectMake(0, 0, frame.size.width, frame.size.height); + _pdfView.frame = _pdfClipView.bounds; NSMutableArray *mProps = [_changedProps mutableCopy]; if (_initialed) { @@ -575,7 +563,8 @@ - (void)reactSetFrame:(CGRect)frame [self didSetProps:mProps]; if (self.layer.cornerRadius > 0) { - [self applyCornerRadius:_pdfView radius:self.layer.cornerRadius]; + _pdfClipView.layer.cornerRadius = self.layer.cornerRadius; + _pdfClipView.layer.masksToBounds = YES; } } @@ -596,6 +585,7 @@ - (void)dealloc{ _pdfDocument = Nil; _pdfView = Nil; + _pdfClipView = Nil; //Remove notifications [[NSNotificationCenter defaultCenter] removeObserver:self name:@"PDFViewDocumentChangedNotification" object:nil];