Giter Club home page Giter Club logo

permissionsswiftui's People

Contributors

binzinz avatar charlessnow avatar connyhald avatar delvinwidjaja avatar derech1e avatar e-001 avatar fnazarios avatar forgot avatar halilibrahimoztekin avatar itsliamdowd avatar jevonmao avatar khuffie avatar n3v1 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

permissionsswiftui's Issues

[Action] Write unit tests for the new, redesigned code base for above 80% coverage

Overview

An overview description of this task, along with a reference to the actual bug or feature issue like: tracking feature #72.

Action items

  • Step 1...
  • Step 2...
  • Step 3...

Visual References

Put all the instructional images, visuals, and prototypes here for reference.

Special Instructions

Add special instructions, warnings, previous issues, and other related stuff here, if applicable.

[Action] - Refactor all view properties into proper MVVM view model

Overview

An overview description of this task, along with a reference to the actual bug or feature issue like: tracking feature #72.

Action items

  • Step 1...
  • Step 2...
  • Step 3...

Visual References

Put all the instructional images, visuals, and prototypes here for reference.

Special Instructions

Add special instructions, warnings, previous issues, and other related stuff here, if applicable.

[Action] - Allow some kind of data model to customize behaviors

Overview

A Redditor suggested that we provide a data model to be passed in to customize behaviors. When developers need to customize multiple, complex behaviors of PermissionsSwiftUI, they will have to write a stack of messy modifiers. However, a PermissionStore model that can be extracted into a view model will allow more efficient and cleaner customization. Tracking #20.

Reference code snippet 1 and code snippet 2 for a direct comparison.

Action items

  • Mark PermissionStore as public. Extract the shared and mutableShared into a private extension, not accessible by API.
  • Make JMPermission's authorized property private, inaccessible from API.
  • Add a new function to PermissionStore that updates the entire model in shared property
  • Add new view modifier APIs under ../JMPermission API/MainModifiers.swift
  • Implement logic in the modifier's method, update PermissionStore source of truth
  • DOCUMENT every single new public API added
  • Create new Xcode test app to test, run unit test (only if required), commit, and pull request.

Visual References

Code Snippets

Currently, this is how you would customize PermissionsSwiftUI components:

        .JMModal(showModal: $showModal,
                 for: [.health(healthPermissions),.calendar,
                       .bluetooth,.locationAlways, .microphone],
                 autoDismiss: true,
                 onAppear: {
                    
                 },
                 onDisappear: {
                    
                 })
        .changeHeaderTo("New Header!")
        .changeHeaderDescriptionTo("PermissionsSwiftUI is the best iOS library!")
        .changeBottomDescriptionTo("PermissionsSwiftUI is the best iOS library!")
        .setPermissionComponent(for: .health(healthPermissions), image: AnyView, title: String?, description: String?)
        .setPermissionComponent(for: .calendar, image: AnyView, title: String?, description: String?)
        .setPermissionComponent(for: .bluetooth, image: AnyView, title: String?, description: String?)
        .setPermissionComponent(for: .locationAlways, image: AnyView, title: String?, description: String?)
        .setPermissionComponent(for: .microphone, image: AnyView, title: String?, description: String?)

This is the ideal result, a data model that supplement the modifier method:

    let model: PermissionStore = {
        var model = PermissionStore()
        model.permissions = [.camera, .health]
        model.mainTexts.headerText = "Some title"
        model.mainTexts.headerDescription = "Some description to be shown"
        model.mainTexts.bottomDescription = "Some description to be shown"
        model.healthPermission = JMPermission(imageIcon: AnyView(Image(systemName: "heart.fill")),
                                              title: "Health",
                                              description: "Allow to access your health information",
                                              authorized: false)
        return model
    }
    ......
    
    .JMModal(showModal: $showModal, forModel: model)

Special Instructions

N/A

Update to platform iOS 14

Is your feature request related to a problem? Please describe.
I am building an app for iOS 14 but this package is only available for iOS 13.

Describe the solution you'd like
Update this package for use with iOS 14 in Package.swift.

Describe alternatives you've considered
No alternatives yet.

Additional context
N/A.

[Refactor] Simplify custom text and image modifiers

If possible, we should refactor over 40 modifiers for customizing the title and description of individual permissions into 1 single modifier. Ex. .setPermissionTextTo(for permission:[Enum], to title:String) The enum should reflect a type for all permissions.
However, we won't fix this until ready for a major release. This will cause major API changes.

[BUG] - restrictDismissal not working

Hello,

My app got rejected because the X button in the modal doesn't work. Looking at 1.3.0, I see restrictDismissal is a setting that's available.

Unfortunately, it doesn't seem to work.

Here's my code:

                .JMModal(
                    showModal: $appState.showPermissionsDialogue,
                    
                    for: [.locationAlways, .calendar, .reminders, .health(categories: .init(read: HealthKitHelper.shared.permissionGroups.allTypes, write: HealthKitHelper.shared.permissionGroups.toWrite) )],
                    autoDismiss: true,
                    autoCheckAuthorization: true,
                    restrictDismissal: false,
                    onAppear: {},
                    onDisappear: {
                        EventsHelper.shared.getAuthorizationStatus()
                        
                    }
                )

Closure to deliver back permission authorization status

Is your feature request related to a problem? Please describe.
It will be really helpful if there can be a closure to deliver back the results of the permission request. I might want to program certain actions to take place after the permission request, and I want to know what permissions are denied, and what permissions are allowed, along with any error in the process.

Describe the solution you'd like
Ideal closure would be integrated with the onDisappear, pass back a structure of JMResult which encapsulates each individual permission's authorization status, and error if any error were to occur.

Describe alternatives you've considered
N/A

Additional context
Ideal implementation:

        .JMAlert(showModal: $showModal,
                 for: [.camera, .locationAlways],
                 autoDismiss: true,
                 onAppear: {},
                 onDisappear: {(result: [JMResult], error: Error) in
                    guard error == nil else {print(error)}
                    if cameraAuth = result[0].authorizationStatus
                 })
    }

Use generics to replace AnyView

Using AnyView is bad practice, and if it can be replaced (and I believe it can in this case) it should be. With just a few changes, MainView.swift would be modified to look like this:

struct MainView<BodyView: View>: View {
    private var showModal: Binding<Bool>
    private var bodyView: BodyView
    init(for bodyView: BodyView, show showModal: Binding<Bool>) {
        self.bodyView = bodyView
        self.showModal = showModal
    }

    var body: some View {
        bodyView
            .sheet(isPresented: showModal, content: {
                ModalView(showModal: showModal)
            })
            
    }
}

AnyView is used in many places and most (if not all) of them can be replaced with generics. This won't break anyone's existing code either, the type will not be MainView, it will be MainView<AnyView>. AnyView should be switched for generics in JMPermission (for the imageIcon) as well. This helps SwiftUI update views more efficiently and prevents always casting the image to AnyView like is currently in the README:

.setPermissionComponent(for: .camera, 
                        image: AnyView(Image(systemName: "camera.fill")), 
                        title: "Camcorder",
                        description: "App needs to record videos")

[Action] Finish implementing common interface for modal and alert modifier API

Overview

An overview description of this task, along with a reference to the actual bug or feature issue like: tracking feature #72.

Action items

  • Step 1...
  • Step 2...
  • Step 3...

Visual References

Put all the instructional images, visuals, and prototypes here for reference.

Special Instructions

Add special instructions, warnings, previous issues, and other related stuff here, if applicable.

Unsafe Flags - Can't build any longer

Describe the bug
Here is the alert I get when trying to build:
The package product 'PermissionsSwiftUI' cannot be used as a dependency of this target because it uses unsafe build flags.
This happens when updating to versions 1.4.0 or 1.4.1.
Version 1.3.0 still builds.

To Reproduce
Steps to reproduce the behavior:
Just build & run

Expected behavior
A clear and concise description of what you expected to happen.

Screenshots
If applicable, add screenshots to help explain your problem.

Desktop (please complete the following information):

  • OS: [iOS 14]

Additional context
Add any other context about the problem here.

[Action] Prepare for next version release. Write new documentation, update existing README, and migration guide

Overview

An overview description of this task, along with a reference to the actual bug or feature issue like: tracking feature #72.

Action items

  • Step 1...
  • Step 2...
  • Step 3...

Visual References

Put all the instructional images, visuals, and prototypes here for reference.

Special Instructions

Add special instructions, warnings, previous issues, and other related stuff here, if applicable.

[Feature] - Make transition animation for JMAlert smoother

Is your feature request related to a problem? Please describe.
The popup animation for JMAlert is not smooth and fluid like Apple's native alert, especially when closing it.

Describe the solution you'd like
Custom implementation of AnyTransition.

[Feature] - Automatically check if permission already granted, and only show alert if not granted

Is your feature request related to a problem? Please describe.
No.

Describe the solution you'd like
When developers are using the powerful feature of PermissionsSwiftUI in their iOS app, they might want to show the JMModal only on first app launch. Or, they might only want to show the JMAlert for camera permission right before user needs to use the camera. However, the alert and modal should not pop up, if permission is already granted.

Describe alternatives you've considered
Currently, without a built in auto permission authorization check, developers will have to implement their own authorization checking. That means importing all the related Apple modules, and interfacing with things like HealthKit and EventKit which defeats the purpose of PermissionsSwiftUI.

Additional context
This issue is tracked by #28

[BUG] - Using .JMModal with .sheet cause modal not to show

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

I'm using .JMModal on my login view and also in this view I have .sheet but .JMModal won't show when I have .sheet.
If I delete that lines of code, then .JMModal show perfectly.

Screen Shot 2021-03-31 at 11 09 24 PM

Screenshots
If applicable, add screenshots to help explain your problem.

Desktop (please complete the following information):

  • OS: [e.g. iOS] MacOS 11.2.3
  • Browser [e.g. chrome, safari] Safari
  • Version [e.g. 22]

Smartphone (please complete the following information):

  • Device: [e.g. iPhone6] iPhone 8, Simulator (iPhone 12 Pro)
  • OS: [e.g. iOS8.1] iOS 14.5
  • Browser [e.g. stock browser, safari] safari
  • Version [e.g. 22]

Additional context
Add any other context about the problem here.

Add ability to customize accent colour

The default colour is blue for PermissionsSwiftUI, which doesn't quite work with my app's design.

For the permission images, I can pass in custom images and provide them with my preferred accent colour.

For the buttons, there seems to be no way to customize them. I see in the source code "ButtonStatusColor", but as it's not a public class I cannot extend it and over-ride it.

Being able to pass in an accent colour that when calling .JMModal would be great!

[BUG] - Health authorization read only crash

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

PermissionSwiftUI 1.4.1
*** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: 'Must request authorization for at least one data type'

To Reproduce

let readData = Set([HKObjectType.workoutType(),
                                    HKObjectType.quantityType(forIdentifier: .stepCount)!,
                                    HKObjectType.quantityType(forIdentifier: .distanceWalkingRunning)!,
                                    HKObjectType.quantityType(forIdentifier: .activeEnergyBurned)!
                                    ,HKObjectType.quantityType(forIdentifier: .appleStandTime)!
                                    ])

.JMModal(showModal:$showPermission,for:[.locationAlways,.health(categories: .init(read: readData)),.notification])

Expected behavior
A clear and concise description of what you expected to happen.

in mapPermissionAuthorizationStatus, input is Set<HKSampleType>, however I'm using HKObjectType and it cause error

***Update:
Tried with HKSampleType but still crash as I click to allow permission of Health.

*** update:
tried to downcast to PermissionSwiftUI 1.3.0, everything working fine!

[Action] - JMModal custom configurations are not working

Overview

An overview description of this task, along with a reference to the actual bug or feature issue like: tracking feature #72.

Action items

  • Step 1...
  • Step 2...
  • Step 3...

Visual References

Put all the instructional images, visuals, and prototypes here for reference.

Special Instructions

Add special instructions, warnings, previous issues, and other related stuff here, if applicable.

Social media promotion checklist

  • Post on my personal Instagram
  • Post on my personal Twitter
  • Reddit preview video - Swift
  • Reddit preview video - SwiftUI
  • Reddit preview video - iOS Developer
  • Reddit promo post - Swift
  • Reddit promo post - SwiftUI
  • Reddit promo post - iOS Developer
  • Project Hunt
  • Beta Page
  • Email the Redditor who talked about a SwiftUI lecture session
  • Hackathons
  • HackerNews (Sunday)

[Action] - Debug location permission that is not working

Overview

An overview description of this task, along with a reference to the actual bug or feature issue like: tracking feature #72.

Action items

  • Step 1...
  • Step 2...
  • Step 3...

Visual References

Put all the instructional images, visuals, and prototypes here for reference.

Special Instructions

Add special instructions, warnings, previous issues, and other related stuff here, if applicable.

Use if #available version checking to conditionally create the tracking permission case

Currently, the PermissionModel enum includes tracking as an accessible enum case for all versions (13.0). However, the tracking permission is only available in iOS 14+, thus it does not make sense to show a tracking permission in targets below 14.0.

Need to figure out a way to conditionally include the tracking enum case. The requestPermission method also need to have a version check if the current enum case is tracking.

[Action] - Refactor JMHealthPermissionManager to avoid a force unwrap in intializers

Overview

An overview description of this task, along with a reference to the actual bug or feature issue like: tracking feature #72.

Action items

  • Step 1...
  • Step 2...
  • Step 3...

Visual References

Put all the instructional images, visuals, and prototypes here for reference.

Special Instructions

Add special instructions, warnings, previous issues, and other related stuff here, if applicable.

[Action] - Create a structure to encapsulate health permission read, write, and both

Overview

We should use a struct to encapsulate health permission case in PermissionType enum's associated value.

Because health permission is special and involves specific read and write permissions, the associated values for the health enum case can have different possibilities. Swift does not allow enum overloading, so its best to use a structure to encapsulate the information. Reference code snippets in Visual References section.

Action items

  • Create new structure for encapsulating
  • Modify PermissionType enum
  • Modify related permission manager code to get information from new struct
  • Run all unit tests, write new tests (as required)
  • Commit & PR!

Visual References

The current declaration for health permission case looks like this:

case health(toShare: Set<HKSampleType>, read: Set<HKSampleType>)

Both toShare and read are non-optional associated values. However, this unnecessarily complicates situations where developers want read and write permission for all the enum cases.
Currently, there is no flexibility and toShare and read parameter must have values, even if they duplicate

//Duplicated code for toShare and read parameters
[.health(toShare: Set([HKSampleType.quantityType(forIdentifier: .activeEnergyBurned)!]),
                                              read: Set([HKSampleType.quantityType(forIdentifier: .activeEnergyBurned)!]))]

This is the goal:

//Overloading HKAccess initializer
[.health(HKAccess(read: ..., write: ...)]
[.health(HKAccess(write: ...)]
[.health(HKAccess(readAndWrite: ...)]

Special Instructions

N/A

[Action] - Create new enum for selecting permission type in customizing components

Overview

Currently, the one and only PermissionType enum is used to designate a specific type of iOS system permission. However, the health permission require an associated value to be passed in, and lead to unnecessary complications when customizing the health component. Please see visual references section. No tracking issue.

Action items

  • Create new enum (name it meaningfully)
  • Add a conformance to shared enum protocol, and define default value for currentPermission so it can be extracted
  • Replace the PermissionType usage in custom modifiers with the new enum
  • Create test Xcode project to test, run unit test, commit and PR!

Visual References

For example, here I use a JMAlert popup with health and camera permission. I customize health permission with a title.

//Here the associated value is used to specify types of health permission.
.JMAlert(showModal: .constant(true),
         for: [.health(([HKSampleType.quantityType(forIdentifier: .activeEnergyBurned)!])),
               .camera])
//There is no point in passing in the entire HKSample type here again. Too much clutter.
.setPermissionComponent(for: .health([HKSampleType.quantityType(forIdentifier: .activeEnergyBurned)!]),
                        title: "My New Title")

Special Instructions

Easy task here. I highly recommend you contribute, even if you barely have any experience with Swift or SwiftUI.

[Action] - Automatically check if permission already granted, and only show alert if not granted

Overview

The JMModal might be shown once at initial launch, and the JMAlert should only show if permission is not granted. PermissionsSwiftUI will awkwardly show a pop-up every single time. There needs to be an automatic checking for permission granted status before built into PermissionsSwiftUI. Tracking #26

Action items

  • Expose authorization status in permission managers
  • Expose a property for access in PermissionType
  • Add new parameter for auto checking in public API
  • Check for authorization, and display PermissionsSwiftUI view accordingly
  • DOCUMENT every single new API added
  • Create new Xcode test app to test, write unit tests, commit, and pull request.

Visual References

Put all the instructional images, visuals, and prototypes here for reference.

Special Instructions

⚠️ One potential problem I see:
First, Apple's APIs for permission authorization status checking are asynchronous. It might introduce a delay to the PermissionsSwiftUI modal or alert.

✅ ❌ Be sure to write new unit tests, and ensure all unit tests pass.

[Action] Fix initializer default implementation in PermissionManagerProtocol

Overview

An overview description of this task, along with a reference to the actual bug or feature issue like: tracking feature #72.

Action items

  • Step 1...
  • Step 2...
  • Step 3...

Visual References

Put all the instructional images, visuals, and prototypes here for reference.

Special Instructions

Add special instructions, warnings, previous issues, and other related stuff here, if applicable.

[BUG] - For Health permissions, read and write permissions are switched.

I was getting the following error when trying to authorize HealthKit permissions:

Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: 'Authorization to share the following types is disallowed: HKQuantityTypeIdentifierAppleExerciseTime, HKQuantityTypeIdentifierAppleStandTime'
I was pretty sure that I was initializing HKAccess with the correct permissions for read and write (aka toShare).

Digging into the code, In HMHealthPermissionManager.requestPermission, line 93 and 94 are as follows:

        healthStore.requestAuthorization(toShare: Set(healthPermission?.readPermissions ?? []),
                                         read: Set(healthPermission?.writePermissions ?? [])) { authorized, error in

"toShare" should be looking at the .writePermissions, not the readPermissions, so it should be:

        healthStore.requestAuthorization(toShare: Set(healthPermission?.writePermissions ?? []),
                                         read: Set(healthPermission?.readPermissions ?? [])) { authorized, error in

Btw: it would be good to add documentation on how to request health permissions in the README, I had to dig into the source code to figure it out :)

[Action] Add media player (Apple Music) permission

Overview

Suggested by Gilles through email. Add the media player (Apple Music) permission into PermissionsSwiftUI's supported permissions. The media player permission is needed to play music through Apple Music.

Action items

  • Create new permission manager class and related functions implementation
  • Create public API for new permission
  • Run all unit tests, write tests
  • Commit & PR!

Visual References

Media Player Framework
Permission description

Special Instructions

To contributors: please hold off on taking this issue for now. I am in progress of MAJOR refactoring that will change a lot of the code base. The refactoring should be finished by 3/25.

[BUG] - On click of Allow push notifications fails

Hi, I've set up my iOS app to ask for permissions like so:
.JMModal(showModal: self.$showModal, for: [.locationAlways, .notification])
Allowing location successfully changes button to allowed, but allowing push notifications does not change the button to allowed, therefore, I cannot exit the modal.

However, I do see printouts in my appDelegate's didRegisterForRemoteNotificationsWithDeviceToken: saying that I have successfully registered? Everytime I click allow I see the button. I only see the Apple alert for allowing push notifications the very first time. But, button does not change to allowed.

To Reproduce
Steps to reproduce the behavior:

  1. Show JMModal with .locationAlways and .notification
  2. Allow Notifications
  3. See error

push notifications should change button to allowed and be able to dismiss.

Desktop (please complete the following information):

  • OS: iOS
  • Version 1.4

Smartphone (please complete the following information):

  • Device: iPhone 12 Pro device

Additional context
Add any other context about the problem here.

[Action] - Fix awkward "compute once only" property in ModalMainView and PermissionSection

Overview

An overview description of this task, along with a reference to the actual bug or feature issue like: tracking feature #72.

Action items

  • Step 1...
  • Step 2...
  • Step 3...

Visual References

Put all the instructional images, visuals, and prototypes here for reference.

Special Instructions

Add special instructions, warnings, previous issues, and other related stuff here, if applicable.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.