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

Refactor to support multi-package architecture #143

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

MeLlamoPablo
Copy link

Overview

This PR splits the multiple supported permissions across different packages, allowing users to only install the packages for the permissions they need. This comes with the upside that we won't reference unnecessary iOS libraries and we will no longer trigger AppStore Connect automated alerts. Even though those alerts can be disregarded, it feels wrong to do so, and they can be confusing (especially for newbie iOS devs like me!)

Fixes #103

Migration path

This PR introduces a breaking change, but it is pretty minimal. Developers must complete the following steps:

  1. Install the packages they need
  2. Import the Permission.xxx symbols

This should be pretty painless, as Android Studio features context actions for both steps.

Code walkthrough

This refactor introduces evolves the existing concept of iOS pemission delegates into multiplatform permission delegates. A "permission delegate" is now an object that contains
platform-specific logic to request the permission and retrieve its state. For iOS, this is platform code calling iOS-specific APIs. For Android, this is simply a list of Manifest.permission values.

The iOS code is pretty much untouched in this PR, as it already was structured in an isolated way. On the other hand, the Android code was moved from PermissionsControllerImpl into android-specific delegates.

A permission now contains a reference to its platform-dependant delegate:

internal expect val cameraDelegate: PermissionDelegate

object CameraPermission : Permission {
    override val delegate get() = cameraDelegate
}

The Permission enum is transformed into an empty object, and each permission-specific package extends it to ease the migration path:

val Permission.Companion.CAMERA get() = CameraPermission

Thank you @Alex009 for this brilliant suggestion!

Now, both Android's and iOS' PermissionController are not aware of which permissions exist anymore. Instead we pass a Permission object which contains the delegate, and the controller interacts with the delegate to request the permission or retrieve its state.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

AppStore connect rejects due to undescribed permissions
1 participant