Skip to content
Draft
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
49 changes: 48 additions & 1 deletion react-native-purchases-ui/ios/PaywallViewWrapper.m
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ @interface PaywallViewWrapper ()

@property(strong, nonatomic) RCPaywallViewController *paywallViewController;
@property(nonatomic) BOOL addedToHierarchy;
@property(nonatomic) BOOL isInLayoutUpdate;

@end

Expand All @@ -38,15 +39,58 @@ - (instancetype)initWithPaywallViewController:(RCPaywallViewController *)paywall
return self;
}


- (void)reactSetFrame:(CGRect)frame
{
NSLog(@"RNPaywalls - reactSetFrame: %@", NSStringFromCGRect(frame));

[super reactSetFrame: frame];

// Only trigger layout if we're not already in a layout update to prevent infinite loops
if (!self.isInLayoutUpdate) {
[self setNeedsLayout];
// Use dispatch_async to break potential synchronous loops
dispatch_async(dispatch_get_main_queue(), ^{
if (!self.isInLayoutUpdate) {
[self layoutIfNeeded];
}
});
}
}

- (void)setBounds:(CGRect)bounds {
CGRect oldBounds = self.bounds;
[super setBounds:bounds];

// Only trigger layout if bounds actually changed and we're not in a layout update
if (!self.isInLayoutUpdate && !CGRectEqualToRect(oldBounds, bounds)) {
[self setNeedsLayout];
dispatch_async(dispatch_get_main_queue(), ^{
if (!self.isInLayoutUpdate) {
[self layoutIfNeeded];
}
});
}
}

- (void)setFrame:(CGRect)frame {
CGRect oldFrame = self.frame;
[super setFrame:frame];

// Only trigger layout if frame actually changed and we're not in a layout update
if (!self.isInLayoutUpdate && !CGRectEqualToRect(oldFrame, frame)) {
[self setNeedsLayout];
dispatch_async(dispatch_get_main_queue(), ^{
if (!self.isInLayoutUpdate) {
[self layoutIfNeeded];
}
});
}
}

- (void)layoutSubviews {
// Set flag to prevent infinite layout loops
self.isInLayoutUpdate = YES;

[super layoutSubviews];

CGSize size = self.bounds.size;
Expand Down Expand Up @@ -74,6 +118,9 @@ - (void)layoutSubviews {
self.addedToHierarchy = YES;
}
}

// Clear flag after layout is complete
self.isInLayoutUpdate = NO;
}

- (void)setOptions:(NSDictionary *)options {
Expand Down