Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[BUG] - iOS 15, dismissal is not working, if the showModal toggles within onAppear function of the view. #101

Open
sapoepsilon opened this issue Oct 17, 2021 · 11 comments
Assignees
Labels
confirmed bug A bug behavior that has been confirmed by maintainers good first issue Good for newcomers help wanted Extra attention is needed

Comments

@sapoepsilon
Copy link

Describe the bug
A clear and concise description of what the bug is.

This bug only present on iOS 15. When, the showModal boolean is set to true in .onAppear. It is not possible to dismiss the modal, unless restrictDismissal is set to false.
To Reproduce
Steps to reproduce the behavior:
Great example would be:

struct Dashboard: View {
   @State private var showModal: Bool = false
   var body: Some View {
          VStack {
             //some code
   }.onAppear {
         showModal = true
    }
}

Expected behavior
A clear and concise description of what you expected to happen.
Modal with permissions will disappear when the "close" button is pressed

Screenshots
If applicable, add screenshots to help explain your problem.
Attached GIF recording of the issue
ios15BUG
*Desktop (please complete the following information):

  • OS: iOS 15
  • Browser [e.g. chrome, safari]
  • Version [e.g. 22]

Smartphone (please complete the following information):

  • Device: [e.g. iPhone6]
  • OS: [e.g. iOS8.1]
  • Browser [e.g. stock browser, safari]
  • Version [e.g. 22]

Additional context
Add any other context about the problem here.
The issue is present in the simulator and in the physical device.

@sapoepsilon sapoepsilon added the possible bug Something isn't working label Oct 17, 2021
@sapoepsilon sapoepsilon changed the title [BUG] - [BUG] - iOS 15, dismissal is not working, if the showModal toggles within onAppear function of the view. Oct 17, 2021
@jevonmao
Copy link
Owner

jevonmao commented Nov 6, 2021

omg my apologies i completely forgot about this 🤦‍♂️ this bug needs to be fixed ASAP i will get to it this weekend

@sapoepsilon
Copy link
Author

@jevonmao Hey, I am not really sure if you have fixed the problem yet. But, the issue is not present in
.JMMALERT()
just a heads up.

@jevonmao
Copy link
Owner

jevonmao commented Dec 5, 2021

@sapoepsilon thank you letting me know that the bug is only for modal. I'm still working on fixing it. Thank you and the community for all the understanding.

@jevonmao
Copy link
Owner

@sapoepsilon This is the code I tried to reproduce with, and it seems like the bug isn't present on Xcode 13.1 simulator. Is there something I'm missing?

import SwiftUI
import PermissionsSwiftUINotification
import PermissionsSwiftUIHealth
import HealthKit

@available(iOS 13.0, *)
struct ContentView: View {
    @State private var showModal: Bool = false
    let healths = Set([HKObjectType.workoutType()])
    var body: some View {
        VStack {
            Text("Hello World")
        }
        .JMModal(showModal: $showModal, for: [.health(categories: .init(readAndWrite: healths)), .notification], restrictDismissal: true)
        .onAppear {
            showModal = true
        }
    }
}

@sapoepsilon
Copy link
Author

sapoepsilon commented Dec 20, 2021

Hey, it is still present in my code, when switched it from .JMAlert to .JMModal.

I have no clue what's causing this, but my code structure is something like this:

import SwiftUI
import PermissionsSwiftUINotification
import PermissionsSwiftUIHealth
import HealthKit


struct ContentView: View {
    @State private var showModal: Bool = false
    let healths = Set([HKObjectType.workoutType()])
    var body: some View {
ZStack {
        GeometryReader { geo in
          ZStack {
              Text("Hello World")
          }
          }
}
        .JMModal(showModal: $showModal, for: [.health(categories: .init(readAndWrite: healths)), .notification], restrictDismissal: true)
        .onAppear {
            showModal = true
        }
    }
}

If this won't trigger it, then probably something in my code is triggering this behavior. Weirdly enough this bug is not present with the .JMAlert.

I will continue to debug, and let you know what exactly is causing this behavior

@konradgalczynski07
Copy link

As far as I can see the problem occurs when the JMModal is hooked into nested views.
In such a scenario, I found some strange behavior, for example that if it is pinned to a NavigationView, the modal is only removed if the user clicks the "Allowed" button again after allowing permissions.

navigationView

Or when hooked into a nested view it allows to disappear by scrolling down.

innerView

Pulling the JMModal up in your view hierarchy should help.

@jevonmao Displaying JMModal sheet always on a topmost view controller instead of a bodyView would be a possible solution.

@jevonmao
Copy link
Owner

Way to go @konradgalczynski07 ! Thanks you so much for debugging the strange behavior. Pulling the modifier up top of view hierarchy (i'm not sure if there is a reason to nest it anyway) will be the best solution for now until we figure out a fix in PermissionsSwiftUI.

@jevonmao jevonmao added confirmed bug A bug behavior that has been confirmed by maintainers help wanted Extra attention is needed and removed possible bug Something isn't working labels Dec 30, 2021
@jevonmao jevonmao added the good first issue Good for newcomers label Mar 25, 2022
@Dave181295
Copy link

Hello, any news to fix the bug friend? it's still happening for iOS16+
need to tap multiples times on the allowed permission

@erikhric
Copy link

I had to switch to cocoapods version and I started seeing this - I ask for 2 permissions but alert is dismissed after allowing only one.

@jevonmao
Copy link
Owner

jevonmao commented Aug 7, 2023

@erikhric The alert is dismissed after only one allow? Do you mind elaborating on the bug you are facing? If this is separate from the dismissal bug in this issue, and unfixable by pulling out the modifier to higher view hierarchy, I will open a new issue and look into this separately.

@jevonmao
Copy link
Owner

jevonmao commented Aug 7, 2023

@Dave181295 Can you share the code where this bug still appears?
I tried to reproduce cases of calling JMModal within nested view, as well as attached to a NavigationView. Neither was reproducible on 16.4.

Code used:

NavigationView {
            ScrollView {
                Button(action: {}, label: {
                    Text("Test button")
                })
                .JMModal(showModal: $showPermissions, for: [.siri])
            }
            .navigationTitle("Test")
            .onAppear {
                showPermissions = true
            }
        }

@jevonmao jevonmao self-assigned this Aug 7, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
confirmed bug A bug behavior that has been confirmed by maintainers good first issue Good for newcomers help wanted Extra attention is needed
Projects
None yet
Development

No branches or pull requests

5 participants