diff options
author | Hazem Ali <y3m@hotmail.com> | 2024-11-11 00:10:09 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2024-11-10 22:10:09 +0000 |
commit | 9a10af7117ff2c818a137241a5b4271c2a882f10 (patch) | |
tree | f59c0f8fbd9c55080b6c281cdeea750e879a4b42 /modules | |
parent | b4412f333381504f6e93ebbfb3f2b9fa9dab892d (diff) | |
download | voidsky-9a10af7117ff2c818a137241a5b4271c2a882f10.tar.zst |
Fix Retain Cycles in SheetViewController (#6202)
* Fix retain cycle in SheetViewController.swift * Fix retain cycles
Diffstat (limited to 'modules')
-rw-r--r-- | modules/bottom-sheet/ios/SheetViewController.swift | 13 |
1 files changed, 8 insertions, 5 deletions
diff --git a/modules/bottom-sheet/ios/SheetViewController.swift b/modules/bottom-sheet/ios/SheetViewController.swift index a8b8f0c05..90d0fed0d 100644 --- a/modules/bottom-sheet/ios/SheetViewController.swift +++ b/modules/bottom-sheet/ios/SheetViewController.swift @@ -64,11 +64,14 @@ class SheetViewController: UIViewController { func updateDetents(contentHeight: CGFloat, preventExpansion: Bool) { if let sheet = self.sheetPresentationController { - sheet.animateChanges { - self.setDetents(contentHeight: contentHeight, preventExpansion: preventExpansion) - if #available(iOS 16.0, *) { - sheet.invalidateDetents() - } + // Capture `self` weakly to prevent retain cycles. + // Also, capture `sheet` weakly to avoid potential strong references held by animateChanges. + sheet.animateChanges { [weak self, weak sheet] in + guard let weakSelf = self, let weakSheet = sheet else { return } + weakSelf.setDetents(contentHeight: contentHeight, preventExpansion: preventExpansion) + if #available(iOS 16.0, *) { + weakSheet.invalidateDetents() + } } } } |