Skip to content

Latest commit

 

History

History

FB13705157

Folders and files

NameName
Last commit message
Last commit date

parent directory

..
 
 
 
 
 
 
 
 
 
 

Sheet background flashes when changing detents

Basic Information

Which platform is most relevant for your report?

iOS

Which technology does your report involve?

SwiftUI

What type of feedback are you reporting?

Incorrect/Unexpected Behavior

What build does the issue occur on?

iOS 17.4 Seed 3 (21E5200d)

Where does the issue occur?

On device

Description

  • Run the given code.
  • Drag the sheet up and down.
  • Notice that the background of the sheet flashes, when the background is partially transparent.
  • I would expect the background of the sheet not to flash.
  • Moving the SheetView into ContentView seems to reduce the chances of it happening, but doesn't solve the problem.
  • Can use SwiftUIIntrospect as a workaround.

Evidence

Visual

Demo Workaround
Demo GIF Workaround GIF

Code

import SwiftUI
struct ContentView: View {
@State private var presented = true
var body: some View {
Button("Present") {
presented = true
}
.sheet(isPresented: $presented) {
SheetView()
}
.frame(maxWidth: .infinity, maxHeight: .infinity)
.background(Color.red)
}
}
struct SheetView: View {
@State private var detent: PresentationDetent = .medium
var body: some View {
Text("Sheet")
.presentationBackground(.regularMaterial)
.presentationDetents([.medium, .large], selection: $detent)
}
}
#Preview {
ContentView()
}

import SwiftUI
import SwiftUIIntrospect
struct ContentView: View {
@State private var presented = true
var body: some View {
Button("Present") {
presented = true
}
.sheet(isPresented: $presented) {
SheetView()
}
.frame(maxWidth: .infinity, maxHeight: .infinity)
.background(Color.red)
}
}
struct SheetView: View {
@State private var detent: PresentationDetent = .medium
var body: some View {
Text("Sheet")
.presentationBackground(.regularMaterial)
.presentationDetents([.medium, .large], selection: $detent)
.introspect(.sheet, on: .iOS(.v17)) { sheet in
sheet.presentedViewController.view.backgroundColor = .clear
}
}
}
#Preview {
ContentView()
}