Skip to content

Commit

Permalink
Final Documentation (#10)
Browse files Browse the repository at this point in the history
  • Loading branch information
vsanthanam committed Jul 9, 2023
1 parent fd2b1a1 commit 03493a4
Show file tree
Hide file tree
Showing 12 changed files with 252 additions and 83 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
[![Package Releases](https://img.shields.io/github/v/release/vsanthanam/SafariView)](https://github.com/vsanthanam/SafariView/releases)
[![Build Statis](https://img.shields.io/github/actions/workflow/status/vsanthanam/SafariView/xcodebuild-build-test.yml)](https://github.com/vsanthanam/SafariView/actions)
[![Swift Version](https://img.shields.io/badge/swift-5.8-critical)](https://swift.org)
[![Supported Platforms](https://img.shields.io/badge/platform-iOS%2012-lightgrey)](https://developer.apple.com)
[![Supported Platforms](https://img.shields.io/badge/platform-iOS%2016-lightgrey)](https://developer.apple.com)

A SwiftUI wrapper around `SFSafariViewController`

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// SafariView
// EnvironmentValues.swift
// Environment.swift
//
// MIT License
//
Expand Down Expand Up @@ -27,90 +27,64 @@ import SwiftUI

public extension EnvironmentValues {

/// The configuration used for ``SafariView``
/// The additional activies to include the share sheet displayed inside a ``SafariView``
///
/// You can retrieve this value for the currnet scope using the @Environment property wrapper
/// You can retrieve this value for the currnet scope using the `@Environment` property wrapper
///
/// ```swift
/// struct MyView: View {
///
/// @Environment(\.safariViewConfiguration)
/// var safariViewConriguration
/// @Environment(\.safariViewIncludedActivities)
/// var safariViewIncludedActivities
///
/// }
/// ```
///
/// This property is equivelent to `SFSafariViewController`'s `.preferredControlTintColor` property
var safariViewConfiguration: SafariView.Configuration {
get { self[SafariViewConfigurationEnvironmentKey.self] }
set { self[SafariViewConfigurationEnvironmentKey.self] = newValue }
/// `
var safariViewIncludedActivities: SafariView.IncludedActivities {
get { self[SafariViewIncludedActivitiesEnvironmentKey.self] }
set { self[SafariViewIncludedActivitiesEnvironmentKey.self] = newValue }
}

/// The control tint color used for ``SafariView``
/// The activity types to exclude from the share sheet displayed inside a ``SafariView``
///
/// You can retrieve this value for the currnet scope using the @Environment property wrapper
/// You can retrieve this value for the currnet scope using the `@Environment` property wrapper
///
/// ```swift
/// struct MyView: View {
///
/// @Environment(\.safariViewControlTintColor)
/// var safariControlTintColor
/// @Environment(\.safariViewExcludedActivityTypes)
/// var safariViewExcludedActivityTypes
///
/// }
/// ```
///
/// This property is equivelent to `SFSafariViewController`'s `.preferredControlTintColor` property
var safariViewExcludedActivityTypes: SafariView.ExcludedActivityTypes {
get { self[SafariViewExcludedActivityTypesEnvironmentKey.self] }
set { self[SafariViewExcludedActivityTypesEnvironmentKey.self] = newValue }
}

}

extension EnvironmentValues {

var safariViewConfiguration: SafariView.Configuration {
get { self[SafariViewConfigurationEnvironmentKey.self] }
set { self[SafariViewConfigurationEnvironmentKey.self] = newValue }
}

var safariViewControlTintColor: Color {
get { self[SafariViewControlTintColorEnvironmentKey.self] }
set { self[SafariViewControlTintColorEnvironmentKey.self] = newValue }
}

/// The bar tint color used for ``SafariView``
///
/// You can retrieve this value for the currnet scope using the @Environment property wrapper
///
/// ```swift
/// struct MyView: View {
/// @Environment(\.safariViewControlBarColor)
/// var safariBarTintColor
/// }
/// ```
///
/// This property is equivelent to `SFSafariViewController`'s `.preferredBarTintColor` property
var safariViewBarTintColor: Color? {
get { self[SafariViewBarTintColorEnvironmentKey.self] }
set { self[SafariViewBarTintColorEnvironmentKey.self] = newValue }
}

/// Set the safari view's dismiss button style
///
/// You can retrieve this value for the currnet scope using the @Environment property wrapper
///
/// ```swift
/// struct MyView: View {
///
/// @Environment(\.safariViewDismissButtonStyle)
/// var safariViewDismissButtonStyle
///
/// }
/// ```
///
/// This property is equivelent to `SFSafariViewController`'s `.dismissButtonStyle` property
var safariViewDismissButtonStyle: SafariView.DismissButtonStyle {
get { self[SafariViewDismissButtonStyleEnvironmentKey.self] }
set { self[SafariViewDismissButtonStyleEnvironmentKey.self] = newValue }
}

var safariViewIncludedActivities: SafariView.IncludedActivities {
get { self[SafariViewIncludedActivitiesEnvironmentKey.self] }
set { self[SafariViewIncludedActivitiesEnvironmentKey.self] = newValue }
}

var safariViewExcludedActivityTypes: SafariView.ExcludedActivityTypes {
get { self[SafariViewExcludedActivityTypesEnvironmentKey.self] }
set { self[SafariViewExcludedActivityTypesEnvironmentKey.self] = newValue }
}

}

private struct SafariViewConfigurationEnvironmentKey: EnvironmentKey {
Expand Down
17 changes: 16 additions & 1 deletion Sources/SafariView/ExcludedActivityTypes.swift
Original file line number Diff line number Diff line change
Expand Up @@ -28,13 +28,17 @@ import UIKit

public extension SafariView {

/// A struct used to exclude activity types from a SafariView
/// A struct used to exclude activity types from the share sheet of a ``SafariView``.
struct ExcludedActivityTypes: ExpressibleByArrayLiteral {

/// Exclude activity types conditionally, based on the URL and/or page title.
/// - Parameter excludedActivityTypes: Closure used to exclude activity types
public init(_ excludedActivityTypes: @escaping (URL, String?) -> [UIActivity.ActivityType]) {
self.excludedActivityTypes = excludedActivityTypes
}

/// Exclude activity types using a predefined list
/// - Parameter excludedActivityTypes: A list of activity types to exclude from the share sheet
public init(_ excludedActivityTypes: [UIActivity.ActivityType] = []) {
self.excludedActivityTypes = { _, _ in excludedActivityTypes }
}
Expand All @@ -49,8 +53,19 @@ public extension SafariView {

// MARK: - ExpressiblyByArrayLiteral

/// The type of the elements of an array literal.
public typealias ArrayLiteralElement = UIActivity.ActivityType

/// Creates an `ExcludedActivityTypes` containing the elements of the given array literal
///
/// Do not call this initializer directly. It is used by the compiler when you use an array literal. Instead, create a new `ExcludedActivityTypes` using an array literal as its value by enclosing a comma-separated list of values in square brackets. You can use an array literal anywhere an `ExcludedActivityTypes` is expected by the type context. For example:
///
/// ```swift
/// let excluded: SafariView.ExcludedActivityTypes = [.addToReadingList, .airDrop, .print, .sharePlay]
/// ```
///
/// In this example, the assignment to the `excluded` constant calls this array literal initializer behind the scenes.
/// - Parameter elements: A variadic list of activity types.
public init(arrayLiteral elements: ArrayLiteralElement...) {
self.init { _, _ in elements }
}
Expand Down
16 changes: 16 additions & 0 deletions Sources/SafariView/IncludedActivities.swift
Original file line number Diff line number Diff line change
Expand Up @@ -28,14 +28,19 @@ import UIKit

public extension SafariView {

/// A struct used to include custom activities in the share sheet of a ``SafariView``
struct IncludedActivities: ExpressibleByArrayLiteral {

// MARK: - Initializers

/// Include activities conditionally, based on the URL and/or page title.
/// - Parameter includedActivities: Closure used to provide activitues
public init(_ includedActivities: @escaping (_ url: URL, _ pageTitle: String?) -> [UIActivity]) {
self.includedActivities = includedActivities
}

/// Include activities using a predefined list
/// - Parameter includedActivities: A list of activities to include in the share sheet
public init(_ includedActivities: [UIActivity]) {
self.includedActivities = { _, _ in includedActivities }
}
Expand All @@ -50,8 +55,19 @@ public extension SafariView {

// MARK: - ExpressiblyByArrayLiteral

/// The type of the elements of an array literal.
public typealias ArrayLiteralElement = UIActivity

/// Creates an `IncludedActivities` containing the elements of the given array literal
///
/// Do not call this initializer directly. It is used by the compiler when you use an array literal. Instead, create a new `IncludedActivities` using an array literal as its value by enclosing a comma-separated list of values in square brackets. You can use an array literal anywhere an `IncludedActivities` is expected by the type context. For example:
///
/// ```swift
/// let included: SafariView.IncludedActivities = [someActivity, someOtherActivity]
/// ```
///
/// In this example, the assignment to the `included` constant calls this array literal initializer behind the scenes.
/// - Parameter elements: A variadic list of activities.
public init(arrayLiteral elements: ArrayLiteralElement...) {
self.init { _, _ in elements }
}
Expand Down
Loading

0 comments on commit 03493a4

Please sign in to comment.