Skip to content

Commit

Permalink
💥 Reduce visibility for experience actions and traits
Browse files Browse the repository at this point in the history
  • Loading branch information
mmaatttt committed Aug 17, 2023
1 parent 0c4c4e5 commit 9698559
Show file tree
Hide file tree
Showing 10 changed files with 37 additions and 37 deletions.
4 changes: 2 additions & 2 deletions Sources/AppcuesKit/Appcues.swift
Original file line number Diff line number Diff line change
Expand Up @@ -226,7 +226,7 @@ public class Appcues: NSObject {
/// Register a trait that modifies an `Experience`.
/// - Parameter trait: Trait to register.
@objc
public func register(trait: AppcuesExperienceTrait.Type) {
internal func register(trait: AppcuesExperienceTrait.Type) {
guard #available(iOS 13.0, *) else { return }

traitRegistry.register(trait: trait)
Expand All @@ -235,7 +235,7 @@ public class Appcues: NSObject {
/// Register an action that can be activated in an `Experience`.
/// - Parameter action: Action to register.
@objc
public func register(action: AppcuesExperienceAction.Type) {
internal func register(action: AppcuesExperienceAction.Type) {
guard #available(iOS 13.0, *) else { return }

actionRegistry.register(action: action)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import Foundation

/// A type that describes an action that can be triggered from an `Experience`.
@objc
public protocol AppcuesExperienceAction {
internal protocol AppcuesExperienceAction {

/// The name of the action.
///
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import UIKit

/// A protocol that defines the methods to adopt to respond to changes in an ``AppcuesExperienceContainerViewController``.
@objc
public protocol AppcuesExperienceContainerEventHandler: AnyObject {
internal protocol AppcuesExperienceContainerEventHandler: AnyObject {

/// Tells the delegate that the container will appear.
///
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import UIKit

/// A `UIViewController` which contains step view controllers to display an `Experience`.
@objc
public protocol AppcuesExperienceContainer {
internal protocol AppcuesExperienceContainer {

/// The delegate object for the experience step container.
var eventHandler: AppcuesExperienceContainerEventHandler? { get set }
Expand All @@ -28,4 +28,4 @@ public protocol AppcuesExperienceContainer {
}

/// A convenience typealias for a `UIViewController` that is also an ``AppcuesExperienceContainer``.
public typealias AppcuesExperienceContainerViewController = AppcuesExperienceContainer & UIViewController
internal typealias AppcuesExperienceContainerViewController = AppcuesExperienceContainer & UIViewController
Original file line number Diff line number Diff line change
Expand Up @@ -10,17 +10,17 @@ import Foundation

/// Maintains page state metadata for an ``AppcuesExperienceContainerViewController``.
@objc
public class AppcuesExperiencePageMonitor: NSObject {
internal class AppcuesExperiencePageMonitor: NSObject {

// Using closures as observers is ok from a memory management perspective because the lifecycle of any Trait
// observing the experience controller and the experience controller itself should be the same.
private var observers: [(Int, Int) -> Void] = []

/// The number of pages in the ``AppcuesExperienceContainerViewController``.
@objc public let numberOfPages: Int
@objc internal let numberOfPages: Int

/// The current page in the ``AppcuesExperienceContainerViewController``.
@objc public private(set) var currentPage: Int
@objc internal private(set) var currentPage: Int

/// Creates an instance of a page monitor.
/// - Parameters:
Expand All @@ -35,7 +35,7 @@ public class AppcuesExperiencePageMonitor: NSObject {
/// Adds the specified closure to the list of closures to invoke when the ``currentPage`` value changes.
/// - Parameter closure: The closure to invoke.
@objc
public func addObserver(closure: @escaping (_ currentIndex: Int, _ oldIndex: Int) -> Void) {
internal func addObserver(closure: @escaping (_ currentIndex: Int, _ oldIndex: Int) -> Void) {
observers.append(closure)
}

Expand All @@ -44,7 +44,7 @@ public class AppcuesExperiencePageMonitor: NSObject {
///
/// Setting a value equal to the current state will not notify observers.
@objc
public func set(currentPage: Int) {
internal func set(currentPage: Int) {
let previousPage = self.currentPage
guard currentPage != previousPage else { return }
self.currentPage = currentPage
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,11 @@ import Foundation

/// An object that decodes instances of a plugin configuration from an Experience JSON model.
@objc
public class AppcuesExperiencePluginConfiguration: NSObject {
internal class AppcuesExperiencePluginConfiguration: NSObject {

/// Context in which a plugin can be applied.
@objc
public enum Level: Int {
internal enum Level: Int {
/// A plugin defined on an entire experience.
case experience
/// A plugin defined on a group of steps in an experience.
Expand All @@ -26,12 +26,12 @@ public class AppcuesExperiencePluginConfiguration: NSObject {
private var decoder: PluginDecoder

/// The context where the plugin was defined.
public let level: Level
internal let level: Level

/// The instance of the Appcues SDK where the plugin is being applied.
public weak var appcues: Appcues?
internal weak var appcues: Appcues?

internal let renderContext: RenderContext
let renderContext: RenderContext

init(_ decoder: PluginDecoder, level: Level, renderContext: RenderContext, appcues: Appcues?) {
self.decoder = decoder
Expand All @@ -43,7 +43,7 @@ public class AppcuesExperiencePluginConfiguration: NSObject {
/// Returns a value of the type you specify, decoded from a JSON object.
/// - Parameter type: The type of the value to decode from the supplied plugin decoder.
/// - Returns: A value of the specified type, if the decoder can parse the data.
public func decode<T: Decodable>(_ type: T.Type) -> T? {
internal func decode<T: Decodable>(_ type: T.Type) -> T? {
return decoder.decode(type)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import UIKit

/// A type that describes a trait of an `Experience`.
@objc
public protocol AppcuesExperienceTrait {
internal protocol AppcuesExperienceTrait {

/// The name of the trait.
///
Expand All @@ -30,7 +30,7 @@ public protocol AppcuesExperienceTrait {

/// A trait that modifies the `UIViewController` that encapsulates the contents of a specific step in the experience.
@objc
public protocol AppcuesStepDecoratingTrait: AppcuesExperienceTrait {
internal protocol AppcuesStepDecoratingTrait: AppcuesExperienceTrait {

/// Modify the view controller for a step.
/// - Parameter stepController: The `UIViewController` to modify.
Expand All @@ -44,7 +44,7 @@ public protocol AppcuesStepDecoratingTrait: AppcuesExperienceTrait {
/// experience step(s) being presented. The returned controller must call the ``AppcuesExperienceContainerEventHandler``
/// methods at the appropriate times.
@objc
public protocol AppcuesContainerCreatingTrait: AppcuesExperienceTrait {
internal protocol AppcuesContainerCreatingTrait: AppcuesExperienceTrait {

/// Create the container controller for experience step(s).
/// - Parameter stepControllers: Array of controllers being presented.
Expand All @@ -63,7 +63,7 @@ public protocol AppcuesContainerCreatingTrait: AppcuesExperienceTrait {

/// A trait that modifies the container view controller created by an ``AppcuesContainerCreatingTrait``.
@objc
public protocol AppcuesContainerDecoratingTrait: AppcuesExperienceTrait {
internal protocol AppcuesContainerDecoratingTrait: AppcuesExperienceTrait {

/// Modify a container view controller.
/// - Parameter containerController: The `AppcuesExperienceContainerViewController` to modify.
Expand All @@ -86,7 +86,7 @@ public protocol AppcuesContainerDecoratingTrait: AppcuesExperienceTrait {

/// A trait that modifies the backdrop `UIView` that may be included in the presented experience.
@objc
public protocol AppcuesBackdropDecoratingTrait: AppcuesExperienceTrait {
internal protocol AppcuesBackdropDecoratingTrait: AppcuesExperienceTrait {

/// Modify the backdrop view.
/// - Parameter backdropView: The `UIView` to modify.
Expand All @@ -112,7 +112,7 @@ public protocol AppcuesBackdropDecoratingTrait: AppcuesExperienceTrait {

/// A trait that creates a `UIViewController` that wraps the ``AppcuesExperienceContainerViewController``.
@objc
public protocol AppcuesWrapperCreatingTrait: AppcuesExperienceTrait {
internal protocol AppcuesWrapperCreatingTrait: AppcuesExperienceTrait {

/// Create a wrapper controller around a container controller.
/// - Parameter containerController: The container controller.
Expand All @@ -130,7 +130,7 @@ public protocol AppcuesWrapperCreatingTrait: AppcuesExperienceTrait {

/// A trait responsible for providing the ability to show and hide the experience.
@objc
public protocol AppcuesPresentingTrait: AppcuesExperienceTrait {
internal protocol AppcuesPresentingTrait: AppcuesExperienceTrait {

/// Shows the view controller for an experience.
/// - Parameter viewController: The view controller to present.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,16 +9,16 @@
import Foundation

/// An `Error` preventing an Experience from being presented.
public struct AppcuesTraitError: Error, CustomStringConvertible {
internal struct AppcuesTraitError: Error, CustomStringConvertible {

/// A description of the nature of the error.
///
/// This value will be logged to Appcues Studio.
public var description: String
internal var description: String

/// Creates an instance of an error.
/// - Parameter description: A description of the nature of the error.
public init(description: String) {
internal init(description: String) {
self.description = description
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,11 @@ import UIKit

/// Stores values to be shared across ``AppcuesExperienceTrait`` instances. The instances may be the same trait applied to different steps,
/// or different traits that coordinate to create a more complex user interface.
public class AppcuesTraitMetadata: NSObject {
internal class AppcuesTraitMetadata: NSObject {
private let newData: [String: Any?]
private let previousData: [String: Any?]

internal init(newData: [String: Any?], previousData: [String: Any?]) {
init(newData: [String: Any?], previousData: [String: Any?]) {
self.newData = newData
self.previousData = previousData
}
Expand Down Expand Up @@ -43,14 +43,14 @@ public class AppcuesTraitMetadata: NSObject {
}

/// Accesses the value associated with the given key for reading.
public subscript<T>(_ key: String) -> T? {
internal subscript<T>(_ key: String) -> T? {
newData[key] as? T
}

/// Accesses the previous value associated with the given key for reading.
///
/// This may be useful for coordinating transitions.
public subscript<T>(previous key: String) -> T? {
internal subscript<T>(previous key: String) -> T? {
previousData[key] as? T
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import UIKit

/// Methods for managing data to be shared across trait instances.
@objc
public class AppcuesTraitMetadataDelegate: NSObject {
internal class AppcuesTraitMetadataDelegate: NSObject {
private var metadata: [String: Any?] = [:]
private var previousMetadata: [String: Any?] = [:]

Expand All @@ -21,13 +21,13 @@ public class AppcuesTraitMetadataDelegate: NSObject {
/// - Parameter newDict: Key/value pairs to update in the metadata dictionary.
///
/// Handlers are not automatically notified of changes. To refresh the handlers, call ``publish()``.
public func set(_ newDict: [String: Any?]) {
internal func set(_ newDict: [String: Any?]) {
metadata = metadata.merging(newDict)
}

/// Removes metadata values.
/// - Parameter keys: Keys to remove from the metadata dictionary.
public func unset(keys: [String]) {
internal func unset(keys: [String]) {
keys.forEach {
metadata.removeValue(forKey: $0)
}
Expand All @@ -38,7 +38,7 @@ public class AppcuesTraitMetadataDelegate: NSObject {
/// Updates are automatically published after a step change in an experience.
///
/// There are no guarantees about the order in which handlers will be called.
public func publish() {
internal func publish() {
let traitMetadata = AppcuesTraitMetadata(newData: metadata, previousData: previousMetadata)

nonAnimatingHandlers.forEach { _, observer in observer(traitMetadata) }
Expand All @@ -55,7 +55,7 @@ public class AppcuesTraitMetadataDelegate: NSObject {
/// - key: The key for the handler block.
/// - animating: Whether the observer should be called in a `UIView.animate` block.
/// - handler: Block to execute on publish.
public func registerHandler(for key: String, animating: Bool, handler: @escaping (AppcuesTraitMetadata) -> Void) {
internal func registerHandler(for key: String, animating: Bool, handler: @escaping (AppcuesTraitMetadata) -> Void) {
removeHandler(for: key)

if animating {
Expand All @@ -67,7 +67,7 @@ public class AppcuesTraitMetadataDelegate: NSObject {

/// Removes matching handlers from the dispatch table.
/// - Parameter key: Key to remove.
public func removeHandler(for key: String) {
internal func removeHandler(for key: String) {
nonAnimatingHandlers.removeValue(forKey: key)
viewAnimatingHandlers.removeValue(forKey: key)
}
Expand Down

0 comments on commit 9698559

Please sign in to comment.