diff --git a/ios/RNPDFPdf/RNPDFPdfView.mm b/ios/RNPDFPdf/RNPDFPdfView.mm index 15c9b05f..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) { @@ -221,6 +223,11 @@ - (void)updateLayoutMetrics:(const facebook::react::LayoutMetrics &)layoutMetric _initialed = YES; [self didSetProps:mProps]; + + if (self.layer.cornerRadius > 0) { + _pdfClipView.layer.cornerRadius = self.layer.cornerRadius; + _pdfClipView.layer.masksToBounds = YES; + } } - (void)handleCommand:(const NSString *)commandName args:(const NSArray *)args @@ -277,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]; @@ -537,11 +548,11 @@ - (void)didSetProps:(NSArray *)changedProps } } - - (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) { @@ -550,6 +561,11 @@ - (void)reactSetFrame:(CGRect)frame _initialed = YES; [self didSetProps:mProps]; + + if (self.layer.cornerRadius > 0) { + _pdfClipView.layer.cornerRadius = self.layer.cornerRadius; + _pdfClipView.layer.masksToBounds = YES; + } } @@ -569,6 +585,7 @@ - (void)dealloc{ _pdfDocument = Nil; _pdfView = Nil; + _pdfClipView = Nil; //Remove notifications [[NSNotificationCenter defaultCenter] removeObserver:self name:@"PDFViewDocumentChangedNotification" object:nil];