Skip to content

Commit 0febe90

Browse files
committed
Fix "Popup doesn't close on $isPresenter is toggled false";
1 parent 5724e89 commit 0febe90

File tree

2 files changed

+10
-3
lines changed

2 files changed

+10
-3
lines changed

.gitignore

+1
Original file line numberDiff line numberDiff line change
@@ -126,3 +126,4 @@ fastlane/test_output
126126
iOSInjectionProject/
127127

128128
# End of https://www.gitignore.io/api/swift,macos,carthage,cocoapods
129+
.idea/

Source/FullscreenPopup.swift

+9-3
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,8 @@ public struct FullscreenPopup<Item: Equatable, PopupContent: View>: ViewModifier
5151
/// Trigger popup showing/hiding animations and...
5252
@State private var shouldShowContent = false
5353

54+
@State private var shouldClosePopup = false
55+
5456
/// ... once hiding animation is finished remove popup from the memory using this flag
5557
@State private var showContent = false
5658

@@ -110,6 +112,7 @@ public struct FullscreenPopup<Item: Equatable, PopupContent: View>: ViewModifier
110112
if isBoolMode {
111113
main(content: content)
112114
.onChange(of: isPresented) { newValue in
115+
shouldClosePopup = !newValue
113116
// minimum time to represent
114117
DispatchQueue.main.asyncAfter(deadline: .now() + 0.03) {
115118
appearAction(sheetPresented: newValue)
@@ -205,9 +208,11 @@ public struct FullscreenPopup<Item: Equatable, PopupContent: View>: ViewModifier
205208
shouldShowContent: shouldShowContent,
206209
showContent: showContent,
207210
positionIsCalculatedCallback: {
208-
shouldShowContent = true // this will cause currentOffset change thus triggering the sliding showing animation
209-
opacity = 1 // this will cause cross disolving animation for background color
210-
setupAutohide()
211+
if !shouldClosePopup {
212+
shouldShowContent = true // this will cause currentOffset change thus triggering the sliding showing animation
213+
opacity = 1 // this will cause cross disolving animation for background color
214+
setupAutohide()
215+
}
211216
},
212217
animationCompletedCallback: onAnimationCompleted,
213218
dismissCallback: { source in
@@ -225,6 +230,7 @@ public struct FullscreenPopup<Item: Equatable, PopupContent: View>: ViewModifier
225230
showContent = true // immediately load popup body
226231
// shouldShowContent is set after popup's frame is calculated, see positionIsCalculatedCallback
227232
} else {
233+
shouldClosePopup = true
228234
dispatchWorkHolder.work?.cancel()
229235
shouldShowContent = false // this will cause currentOffset change thus triggering the sliding hiding animation
230236
opacity = 0

0 commit comments

Comments
 (0)