Skip to content

SlideOverCard Disappears Immediately After Presentation #34

@Andrew87E

Description

@Andrew87E

Description:

I am encountering an issue where the card disappears immediately after it is presented. The showPickCard state is set to true, but the card is not staying visible on the screen.
This is an issue with the most current version of SlideOverCard (3.0.1) only. Downgrading to version 2.1.0 resolves the issue.

Here is a minimal reproducible example to demonstrate the problem:

Steps to Reproduce:

  • Define a dictionary to hold the content and sound details for different cards.
  • Use a state variable showPickCard to control the presentation of the SlideOverCard.
  • Call the showCard function to set the state and present the card.
  • Observe that the card disappears immediately after appearing.

Example Code:

import SwiftUI
import SlideOverCard

enum PickCardType {
    case firstCard, secondCard
}

struct ContentView: View {
    @StateObject var settingsController = SettingsController()
    @StateObject var soundController = SoundController()

    @State private var pickCard: PickCardType = .firstCard
    @State private var showPickCard: Bool = false {
        didSet {
            print("showPickCard: \(showPickCard)") // output: showPickCard: true (never gets set to false)
        }
    }

    private var pickCardDetails: [PickCardType: (content: AnyView, sound: SoundType)] {
        [
            .firstCard: (content: AnyView(FirstCardView(firstCardProp: $showPickCard).environmentObject(settingsController)), sound: .info),
            .secondCard: (content: AnyView(SecondCard(secondCardProp: $showPickCard)), sound: .info),
        ]
    }

    @MainActor
    private func showCard(_ which: PickCardType) {
        if showAlert == true { Thread.sleep(forTimeInterval: 0.4) }
        pickCard = which
        showPickCard = true
    }

    var body: some View {
        VStack {
            Button("Show First Card") {
                showCard(.firstCard)
            }
            .padding()

            Button("Show Second Card") {
                showCard(.secondCard)
            }
            .padding()
        }
        .slideOverCard(isPresented: $showPickCard, style: SOCStyle(cornerRadius: 20, continuous: true, innerPadding: 4, outerPadding: 10, dimmingOpacity: 0.5, style: .regularMaterial)) {
            pickCardDetails[pickCard]!.content
                .environment(\.colorScheme, .dark)
                .onAppear {
                    soundController.playSound(pickCardDetails[pickCard]!.sound)
                    print("pickCard: \(pickCard)") // output: pickCard: firstCard
                    print("showPickCard: \(showPickCard)") // output: showPickCard: true
                }
                .onDisappear {
                    print("pickCard: \(pickCard)") // output: pickCard: firstCard
                    print("showPickCard: \(showPickCard)") // output: showPickCard: true
                }
        }
    }
}

struct FirstCardView: View {
    @Binding var firstCardProp: Bool
    var body: some View {
        Text("First Card")
    }
}

struct SecondCard: View {
    @Binding var secondCardProp: Bool
    var body: some View {
        Text("Second Card")
    }
}

Observed Behavior:

When attempting to present the SlideOverCard, the card briefly appears and then disappears immediately. The showPickCard state remains true, but the card does not stay visible on the screen.

Expected Behavior:

The SlideOverCard should remain visible when the showPickCard state is true until the state is set to false.

Additional Information:

SlideOverCard version: 3.0.1
Swift version: 5.10
Xcode version: 15.4 (15F31d)
Platform: iPad

Logs:

Here are some relevant logs demonstrating the state changes:

showPickCard set to: true
Attempting to show card: firstCard
showPickCard during appear: true
SlideOverCard appeared with card: firstCard
SlideOverCard disappeared with card: firstCard
showPickCard during disappear: true

Please let me know if any additional information is needed. Thank you for looking into this issue!

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions