about summary refs log tree commit diff
path: root/modules
diff options
context:
space:
mode:
authorHazem Ali <y3m@hotmail.com>2024-11-11 00:10:09 +0200
committerGitHub <noreply@github.com>2024-11-10 22:10:09 +0000
commit9a10af7117ff2c818a137241a5b4271c2a882f10 (patch)
treef59c0f8fbd9c55080b6c281cdeea750e879a4b42 /modules
parentb4412f333381504f6e93ebbfb3f2b9fa9dab892d (diff)
downloadvoidsky-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.swift13
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()
+          }
       }
     }
   }