Mijick / PopupView

Popups presentation made simple (SwiftUI)
MIT License
1.08k stars 42 forks source link

Cant used GeometryReader #66

Closed KavinduDissanayake closed 4 months ago

KavinduDissanayake commented 7 months ago

When I wrap using GeometryReader ,I got results like below image

Code Snippet

'struct BottomPopup_NoCornerRadius: BottomPopup {
    func configurePopup(popup: BottomPopupConfig) -> BottomPopupConfig { popup.cornerRadius(0) }
    func createContent() -> some View {
        GeometryReader{ geo in
            VStack(alignment: .leading, spacing: 0) {
                Text("Test")
                createTitle()
                Spacer.height(16)
                createDescription()
                Spacer.height(36)
                createButtons()
            }
            .padding(.top, 32)
            .padding(.bottom, 12)
            .padding(.horizontal, 28)
        }
        }

}
@FulcrumOne 

Demo: Simulator Screenshot - iPhone 15 - 2023-12-29 at 01 55 09

KavinduDissanayake commented 6 months ago

@FulcrumOne Any Update ?

FulcrumOne commented 4 months ago

hey @KavinduDissanayake,

Unfortunately this appears to be a SwiftUI bug that we cannot fix - we suggest you calculate the height of your content by yourself and set it at the end of the view:

    func createContent() -> some View {
        GeometryReader{ geo in
            VStack(alignment: .leading, spacing: 0) {
                Text("Test")
                createTitle()
                Spacer.height(16)
                createDescription()
                Spacer.height(36)
                createButtons()
            }
            .padding(.top, 32)
            .padding(.bottom, 12)
            .padding(.horizontal, 28)
            .calculateHeight($contentHeight)
        }
        .frame(height: contentHeight)
    }

Sorry for the delay and have a nice weekend!

P.S. The best choice for calculating content height seems to be the archorPreference function.