Skip to content

Commit

Permalink
Merge pull request #64 from skiptools/ondismissfix
Browse files Browse the repository at this point in the history
Fix onDismiss not always being called on sheet dismiss
  • Loading branch information
aabewhite authored Sep 25, 2024
2 parents 74cd349 + 40e785e commit 142b095
Showing 1 changed file with 13 additions and 3 deletions.
16 changes: 13 additions & 3 deletions Sources/SkipUI/SkipUI/Layout/Presentation.swift
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,8 @@ let overlayPresentationCornerRadius = 16.0
}

let sheetState = rememberModalBottomSheetState(skipPartiallyExpanded: true)
if isPresented.get() || sheetState.isVisible {
let isCurrentlyPresented = isPresented.get()
if isCurrentlyPresented || sheetState.isVisible {
let contentView = ComposeBuilder.from(content)
let topInset = remember { mutableStateOf(0.dp) }
let topInsetPx = with(LocalDensity.current) { topInset.value.toPx() }
Expand Down Expand Up @@ -173,11 +174,20 @@ let overlayPresentationCornerRadius = 16.0
}
}
}
if !isPresented.get() {

// When our isPresented binding flips from true to false, hide the sheet if needed and invoke onDismiss
let wasPresented = remember { mutableStateOf(isCurrentlyPresented) }
let onDismissState = rememberUpdatedState(onDismiss)
if isCurrentlyPresented {
wasPresented.value = true
} else {
LaunchedEffect(true) {
if sheetState.targetValue != SheetValue.Hidden {
sheetState.hide()
onDismiss?()
}
if wasPresented.value {
wasPresented.value = false
onDismissState.value?()
}
}
}
Expand Down

0 comments on commit 142b095

Please sign in to comment.