Skip to content
Closed
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
25 changes: 21 additions & 4 deletions ios/RNPDFPdf/RNPDFPdfView.mm
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ @implementation RNPDFPdfView
RCTBridge *_bridge;
PDFDocument *_pdfDocument;
PDFView *_pdfView;
UIView *_pdfClipView;
PDFOutline *root;
float _fixScaleFactor;
bool _initialed;
Expand Down Expand Up @@ -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) {
Expand All @@ -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
Expand Down Expand Up @@ -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];
Expand Down Expand Up @@ -537,11 +548,11 @@ - (void)didSetProps:(NSArray<NSString *> *)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) {
Expand All @@ -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;
}
}


Expand All @@ -569,6 +585,7 @@ - (void)dealloc{

_pdfDocument = Nil;
_pdfView = Nil;
_pdfClipView = Nil;

//Remove notifications
[[NSNotificationCenter defaultCenter] removeObserver:self name:@"PDFViewDocumentChangedNotification" object:nil];
Expand Down