PermissionsSwiftUI icon indicating copy to clipboard operation
PermissionsSwiftUI copied to clipboard

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

Open sapoepsilon opened this issue 4 years ago • 11 comments

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 avatar Oct 17 '21 20:10 sapoepsilon

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

jevonmao avatar Nov 06 '21 07:11 jevonmao

@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.

sapoepsilon avatar Dec 05 '21 11:12 sapoepsilon

@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 avatar Dec 05 '21 20:12 jevonmao

@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
        }
    }
}

jevonmao avatar Dec 19 '21 01:12 jevonmao

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

sapoepsilon avatar Dec 20 '21 06:12 sapoepsilon

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.

konradgalczynski07 avatar Dec 30 '21 22:12 konradgalczynski07

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 avatar Dec 30 '21 23:12 jevonmao

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

Dave181295 avatar Apr 20 '23 21:04 Dave181295

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.

erikhric avatar Apr 25 '23 13:04 erikhric

@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 avatar Aug 07 '23 17:08 jevonmao

@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 avatar Aug 07 '23 17:08 jevonmao