2 min read
Dynamic Content
Last Updated - Platform 25.0 - SDK 20.0Dynamic Content is an exiting new technology that we hope to eventually replace most or all of the SDK. It is a new micro architecture composed of Slots and Components.
Some features have predefined slots that can be filled with components dynamically from the slotContent
of their associated BE response data.
Slots are easy to add to any feature with slotContent
or using a custom data solution to provide their content dynamically.
Over time we will roll out slots to more of the SDK features or even build entire features from them.
Set up
The v25 release brings the base of Dynamic Content with limited slots and components and integration with Dynamic Yield. Dynamic Content requires no developer set up.
However, clients are able to customise their API to return slotContent
without an integration.
We are also working new interfaces into our App Manager to dynamically customise UI in the future.
Slots
Slots (SlotView
) are simplified views that can be added anywhere in the view hierarchy to provide a slot for dynamic components.
Check feature specific documentation for the SDK predefined slots.
Slot views rely on the same mechanism as navigation (deep links) to resolve a single view.
Each SlotView
has a resolver
that defaults to the shared container resolver where the SDK registers all its components.
Unlike navigation route resolution returns an outcome (a view) that the slot presents.
If the route succeeds, the SlotView
expands to best fit the new view.
If the route fails to resolve a view, the SlotView
collapses to zero height.
Depending on the content and scenario this can cause interesting (good or bad) animations which can be improved by returning and setting expected size constraints on the resolved view during update(...)
(check the ImageComponentView
).
Finally, the above resolution has some level of optimisation to reduce the amount of times views are created.
State updates happen very often and cause new view data; if a new ViewSource
has the same route as the existing resolved view, the SlotView
calls that view's update(..)
function to avoid destroying and recreating views.
As of v25 we support the following slots out of the box:
- Cart
scroll-top
scroll-bottom
- Shop
scroll-top
- Product List
scroll-top
- Product Details
recommendations
(after links but before carousels)
Components
Components consist of two mechanisms and three parts as a simplified architecture since they are views presented by the data layer rather than by the feature. See dynamic components for the full list of components.
The below example walks through how the ImageComponentView
works (pseudocode).
The first mechanism is the route (deeplink) that identifies the ImageComponentView
. Component views are registered against a static deeplink route (usually without parameters for components). These views are resolved via the ViewSource
which also carries the content
to present.
SlotViewResolver.shared.set(route: "image") { ImageComponentView() }
The second mechanism is the content
mapping. The SlotContentManager
is the main mapper for all slotContent
that maps ImageComponentData
to ImageComponentContent
within a ViewSource
. Component mappers (specific to the type
property) are registered to the SlotContentManager
to map the content of a specific type.
SlotComponentManager.shared.set(type: "image") { (data: ImageComponentData) in guard let url = data.url.toURL() else { return nil } return ViewSource(path: "image", content: ImageComponentContent( id: data.id, url: url, link: data.link, customData: data.customData ))}
Finally, the ImageComponentView
updates itself using the content via its update(...)
functions.
To simplify the above process the SDK exposes the ComponentView
protocol and sets the route and mapper in an overridable class function inject(into:mapper:)
at the top of the ImageComponentView
and other SDK component views. These injection functions are dynamically called when the SDK initialises itself on app launch.
Dynamic Yield
Our initial implementation releases with our Dynamic Yield integration to return content set up directly within Dynamic Yield.
History
- 20.0 (v25): Limited release with Dynamic Yield integration.