appcues / appcues-ios-sdk

The Appcues iOS SDK
https://www.appcues.com/mobile
MIT License
8 stars 2 forks source link

Add AppcuesPresentationDelegate with experience metadata #509

Closed mmaatttt closed 8 months ago

mmaatttt commented 8 months ago

Background

We provide AppcuesExperienceDelegate to allow apps visibility into when the presentation lifecycle of Appcues experiences. This protocol was designed before embeds (and therefore multiple render contexts) and so is no longer particularly useful for an app with multiple embed frames in addition to modals/tooltips.

Change

I've created AppcuesPresentationDelegate that contains the same functions, but with a metadata: AppcuesPresentationMetadata value that provides id, name, and renderContext ("modal" or $frameName) to provide more clarity into what experience is triggering the presentation lifecycle methods.

Frame delegate

I've also added presentationDelegate as a property on AppcuesFrameView. It functions exactly the same way, but is scoped to only experiences rendering in the specific frame. This doesn't really provide any new functionality since the metadata["renderContext"] from the global Appcues.presentationDelegate would allow you to filter, but it creates a better developer experience because each frame view can have its own delegate logic that can be implemented close to the UI code for the frame itself instead of once globally.

Notes

  1. For the sake of backwards compatibility, AppcuesExperienceDelegate remains untouched, so AppcuesPresentationDelegate is solely additive. We can remove AppcuesExperienceDelegate in SDK v4 if we so choose. I've updated the docs to indicate using presentationDelegate is to be preferred over experienceDelegate.
  2. Having AppcuesPresentationDelegate be objc compatible creates some limitations, so AppcuesPresentationMetadata has to be a class instead of the struct which would be preferred.
  3. AppcuesPresentationMetadata can be enhanced in the future with additional values if we see a need. Note that removing/renaming a value would be a breaking change.