Menu

The skip-kit framework is available at https://github.com/skiptools/skip-kit.git, which can be checked out and tested with skip test once Skip is installed.

SkipKit

This Skip module enhances the SkipUI package with commonly-used features.

Camera and Media selection

The View.withMediaPicker(type:isPresented:selectedImageURL:) extension function can be used to enable the acquisition of an image from either the system camera or the user’s media library.

On iOS, this camera selector will be presented in a fullScreenCover view, whereas the media library browser will be presented in a sheet. In both cases, a standad UIImagePickerController will be used to acquire the media.

On Android, the camera and library browser will be activated through an Intent after querying for the necessary permissions.

Following is an example of implementing a media selection button that will bring up the system user interface.

import SkipKit

/// A button that enables the selection of media from the library or the taking of a photo.
///
/// The selected/captured image will be communicated through the `selectedImageURL` binding,
/// which can be observed with `onChange` to perform an action when the media URL is acquired.
struct MediaButton : View {
    let type: MediaPickerType // either .camera or .library
    @Binding var selectedImageURL: URL?
    @State private var showPicker = false

    var body: some View {
        Button(type == .camera ? "Take Photo" : "Select Media") {
            showPicker = true // activate the media picker
        }
        .withMediaPicker(type: .camera, isPresented: $showPicker, selectedImageURL: $selectedImageURL)
    }
}

Permissions

In order to access the device’s photos or media library, you will need to declare the permissions in the app’s metadata.

On iOS this can be done by editing the Darwin/AppName.xcconfig file and adding the lines:

INFOPLIST_KEY_NSCameraUsageDescription = "This app needs to access the camera";
INFOPLIST_KEY_NSPhotoLibraryUsageDescription = "This app needs to access the photo library.";

On Android, the app/src/main/AndroidManifest.xml file will need to be edited to include permissions as follows:

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools">
    <uses-feature
        android:name="android.hardware.camera"
        android:required="false" />
    <uses-feature
        android:name="android.hardware.camera.autofocus"
        android:required="false" />

    <uses-permission android:name="android.permission.CAMERA" />
    <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />

    <application>…</application>
</manifest>

Building

This project is a free Swift Package Manager module that uses the Skip plugin to transpile Swift into Kotlin.

Building the module requires that Skip be installed using Homebrew with brew install skiptools/skip/skip. This will also install the necessary build prerequisites: Kotlin, Gradle, and the Android build tools.

Testing

The module can be tested using the standard swift test command or by running the test target for the macOS destination in Xcode, which will run the Swift tests as well as the transpiled Kotlin JUnit tests in the Robolectric Android simulation environment.

Parity testing can be performed with skip test, which will output a table of the test results for both platforms.