Skip to content

Commit

Permalink
♻️ Add AppcuesPresentationDelegate.experienceStepDidChange
Browse files Browse the repository at this point in the history
  • Loading branch information
mmaatttt committed Mar 7, 2024
1 parent 37411f8 commit 6216dc4
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,10 @@ internal enum RenderContext: Hashable, CustomStringConvertible {
case modal
case embed(frameID: String)

var id: String {
var frameID: String? {
switch self {
case .modal:
return "modal"
return nil
case .embed(let frameID):
return frameID
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -108,8 +108,12 @@ extension ExperienceStateMachine: AppcuesExperienceContainerEventHandler {

func containerDidAppear() {
switch state {
case let .beginningStep(experience, _, package, isFirst) where isFirst && package.wrapperController.isAppearing:
experienceDidAppear(experience: experience)
case let .beginningStep(experience, _, package, isFirst) where package.wrapperController.isAppearing:
if isFirst {
experienceDidAppear(experience: experience)
} else {
experienceStepDidChange(experience: experience)
}
default:
break
}
Expand Down Expand Up @@ -149,12 +153,14 @@ extension ExperienceStateMachine: AppcuesExperienceContainerEventHandler {
state = .beginningStep(experience, stepIndex, package, isFirst: false)
state = .renderingStep(experience, newStepIndex, package, isFirst: false)
}
experienceStepDidChange(experience: experience)
case let .endingStep(experience, _, package, _):
let targetStepId = package.steps[newPageIndex].id
if let newStepIndex = experience.stepIndex(for: targetStepId) {
state = .beginningStep(experience, newStepIndex, package, isFirst: false)
state = .renderingStep(experience, newStepIndex, package, isFirst: false)
}
experienceStepDidChange(experience: experience)
default:
break
}
Expand Down Expand Up @@ -198,6 +204,11 @@ extension ExperienceStateMachine: AppcuesExperienceContainerEventHandler {
clientAppcuesPresentationDelegate?.experienceDidAppear(metadata: experience.delegateMetadata())
}

private func experienceStepDidChange(experience: ExperienceData) {
clientControllerPresentationDelegate?.experienceStepDidChange(metadata: experience.delegateMetadata())
clientAppcuesPresentationDelegate?.experienceStepDidChange(metadata: experience.delegateMetadata())
}

private func experienceWillDisappear(experience: ExperienceData) {
clientControllerDelegate?.experienceWillDisappear()
clientAppcuesDelegate?.experienceWillDisappear()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,15 +17,21 @@ public class AppcuesPresentationMetadata: NSObject {
/// Name of the experience.
public let name: String

/// Context of the experience.
///
/// Either `"modal"` or the `frameID` of an ``AppcuesFrame``.
public let renderContext: String
/// True if the experience is presented as an overlay. Includes modals, tooltips, and slideouts.
public let isOverlay: Bool

internal init(id: String, name: String, renderContext: String) {
/// True if the experience is presented in an embe frame.
public let isEmbed: Bool

/// Frame ID of the experience. Non-nil when `isEmbed == true`
public let frameID: String?

internal init(id: String, name: String, isOverlay: Bool, isEmbed: Bool, frameID: String?) {
self.id = id
self.name = name
self.renderContext = renderContext
self.isOverlay = isOverlay
self.isEmbed = isEmbed
self.frameID = frameID
}
}

Expand All @@ -44,6 +50,10 @@ public protocol AppcuesPresentationDelegate: AnyObject {
/// - Parameter metadata: Dictionary containing metadata about the experience.
func experienceDidAppear(metadata: AppcuesPresentationMetadata)

/// Notifies the delegate after a step change in a presented Appcues experience.
/// - Parameter metadata: Dictionary containing metadata about the experience.
func experienceStepDidChange(metadata: AppcuesPresentationMetadata)

/// Notifies the delegate before an Appcues experience is dismissed.
/// - Parameter metadata: Dictionary containing metadata about the experience.
func experienceWillDisappear(metadata: AppcuesPresentationMetadata)
Expand Down
4 changes: 3 additions & 1 deletion Sources/AppcuesKit/Presentation/UI/ExperienceData.swift
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,9 @@ internal class ExperienceData {
AppcuesPresentationMetadata(
id: model.id.appcuesFormatted,
name: model.name,
renderContext: model.renderContext.id
isOverlay: model.renderContext == .modal,
isEmbed: model.renderContext != .modal,
frameID: model.renderContext.frameID
)
}

Expand Down

0 comments on commit 6216dc4

Please sign in to comment.