1

I have an overlay button in my SheetView which dismisses it:

    .overlay(
        Button {
            presentationMode.wrappedValue.dismiss()
        } label: {
            Image(systemName: "xmark")
        }
        .foregroundColor(.primaryAppColor)
        .font(.system(.title3, design: .rounded).weight(.light))
        .padding(.top, 20)
        .padding(.trailing, 20)
        , alignment: .topTrailing
    )

Whenever I press the button, nothing happens. However, if I remove the padding modifiers, it works for some reason. Any ideas why that is happening?

It also works if I remove this TabView from my view:

TabView(selection: $selectedTab) {
                
                // Connectors tab
                EVChargerAllConnectionsView(connections: evCharger.connections)
                    .padding(.horizontal, 15)
                    .tag(0)

                // Community tab
                EVChargerAllCommentsView(userComments: evCharger.userComments)
                    .padding(.horizontal, 15)
                    .tag(1)

                // Usage tab
                EVChargerUsageView(usageType: evCharger.usageType, operatorInfo: evCharger.operatorInfo)
                    .padding(.horizontal, 15)
                    .tag(2)

                // Address tab
                EVChargerAddressView(addressInfo: evCharger.addressInfo)
                    .padding(.horizontal, 15)
                    .tag(3)

                // Operator tab
                EVChargerOperatorView(operatorInfo: evCharger.operatorInfo)
                    .padding(.horizontal, 15)
                    .tag(4)
                
            } //: TAB VIEW
            .tabViewStyle(.page(indexDisplayMode: .never))

Here is my whole view:

import SwiftUI

struct EVChargerView: View {

//MARK: - PROPERTIES
@Environment(\.presentationMode) var presentationMode

@State private var selectedTab: Int = 0

@State private var showPhotosView: Bool = false

public let evCharger: EVChargerModel

private let tabs: [String] = [
    "Connectors",
    "Community",
    "Usage",
    "Address",
    "Operator"
]

//MARK: - BODY
var body: some View {
    
    ZStack {
        
        // Sets the background color
        Color.backgroundColor
            .ignoresSafeArea()
        
        VStack(alignment: .center, spacing: 10) {
            
            EVChargerPhotosView(mediaItems: evCharger.mediaItems)
                .frame(height: 250)
                .onTapGesture {
                    showPhotosView.toggle()
                }
                .sheet(isPresented: $showPhotosView) {
                    EVChargerPhotosView(mediaItems: evCharger.mediaItems, fillImages: false)
                }
            
            EVChargerTabView(
                tabTitles: tabs,
                selectedTab: $selectedTab
            )
            .padding(.horizontal, 15)
            
            TabView(selection: $selectedTab) {
                
                // Connectors tab
                EVChargerAllConnectionsView(connections: evCharger.connections)
                    .padding(.horizontal, 15)
                    .tag(0)

                // Community tab
                EVChargerAllCommentsView(userComments: evCharger.userComments)
                    .padding(.horizontal, 15)
                    .tag(1)

                // Usage tab
                EVChargerUsageView(usageType: evCharger.usageType, operatorInfo: evCharger.operatorInfo)
                    .padding(.horizontal, 15)
                    .tag(2)

                // Address tab
                EVChargerAddressView(addressInfo: evCharger.addressInfo)
                    .padding(.horizontal, 15)
                    .tag(3)

                // Operator tab
                EVChargerOperatorView(operatorInfo: evCharger.operatorInfo)
                    .padding(.horizontal, 15)
                    .tag(4)
                
            } //: TAB VIEW
            .tabViewStyle(.page(indexDisplayMode: .never))
            
        } //: VSTACK
        
    } //: ZSTACK
    .onAppear {
        selectedTab = 0
    }
    //TODO: - FIX X BUTTON ON THE TOP RIGHT SCREEN TO DISMISS THE VIEW. WHENEVER I REMOVE THE PADDING IN THE BUTTON, THE BUTTON WORKS.
    .overlay(
        Button {
            presentationMode.wrappedValue.dismiss()
        } label: {
            Image(systemName: "xmark")
        }
        .foregroundColor(.primaryAppColor)
        .font(.system(.title3, design: .rounded).weight(.light))
        .padding(.top, 20)
        .padding(.trailing, 20)
        , alignment: .topTrailing
    )
    
} //: BODY

} //: STRUCT

0 Answers0