Present modal in SwiftUI in full screen mode and prevent closing it

1.6k views Asked by At

I have a SplashView that acts as a starting view and opens the game screen in modals.

I just tried to open the game in an iPad instead of iPhone and the views look all weird.

When I switch to the game screen the screen is presented as a small screen in the middle and I can swipe it out to close it. Other screens from the logic are stacked on this screen.

How can I prevent the stacking and have all screen in full screen, similar to when I open it on an iPhone and prevent moving them by swiping?

example of 2 stacked screens on the starting screen

  .sheet(isPresented: $isPlayerDashboardModal) {
                if let playerState = PlayerViewModel.createNewGameData(name: playerName) {
                    let playerViewModel = PlayerViewModel(player: playerState)
                    CityView(viewModel: playerViewModel)
                }
            }.frame(minWidth: DeviceTypes.ScreenSize.width, idealWidth: DeviceTypes.ScreenSize.width, maxWidth: DeviceTypes.ScreenSize.width, minHeight: DeviceTypes.ScreenSize.height, idealHeight: DeviceTypes.ScreenSize.height, maxHeight: DeviceTypes.ScreenSize.height, alignment: .center)
            

I set the frame to max already, but this does not seem to do anything.

1

There are 1 answers

0
Nathanael Tse On BEST ANSWER

replace .sheet with .fullScreenCover to ensure that window is full screen and cannot be closed via pulling it down. To hide the statusbar on iPad include: .statusBar(hidden: true) before the final view closure.