Custom Layouts
Brand Diyalog SDK dialogs with your own view controllers. Your app controls the look and feel; the SDK keeps driving the behavior, such as running the alert actions.
The iOS SDK currently supports this customization surface:
- Alert Dialog: present SDK alerts with your own custom view controller and layout.
For colors, backgrounds and typography, see Style your SDK.
Overview#
The Diyalog iOS SDK lets your app supply its own UI for critical SDK views. For alert dialogs, you conform to the DiyalogCustomAlertDelegate protocol. Once the delegate is registered, the SDK hands every alert presentation to your app, passing along the title, the message and the action models to show.
Design principles#
- Opt-in: if you never register the custom delegate, the SDK uses the default system
UIAlertController. - Contract by delegate: your app implements the presentation and must make sure the handler of each provided action is invoked when the user taps its button.
- Register early: assign the delegate in
AppDelegate'sdidFinishLaunchingWithOptions, next to the rest of your Diyalog initialization.
Quick start#
Register the delegate once during app startup, before initializing the Diyalog engine or navigating to chat:
To turn the custom alert integration off at runtime, set the delegate back to nil:
1. Custom Alert Dialog#
Brand the confirmation and info dialogs shown by the SDK (such as logout confirmations, error messages and permission prompts) with your app's colors, typography and button styles.
Alert Dialog API#
The SDK exposes a delegate protocol that your app conforms to:
| Parameter | Description |
|---|---|
viewController | The SDK view controller to present your alert on |
title | Alert title; nil when the alert has no title |
message | Alert message |
preferredStyle | Preferred presentation style requested by the SDK |
actions | DLGAlertAction objects, each with a title and a style (.default, .cancel or .destructive) |
Registration#
Reference implementation: CustomAlertViewController#
Below is a complete reference implementation of a custom alert view controller. It builds a styled popup with Auto Layout, creates a button for every item in the actions array, and makes sure the right action is invoked when a button is tapped.
Note:
ActionWrapperis a small helper class in your app, not part of the SDK. Itsinvokemethod must dismiss the alert view controller and run the handler of theDLGAlertActionit wraps.
Alert Dialog behavior notes#
- Title and message: passed directly from the SDK based on the context of the alert. If an alert has no title,
titleisnil. - Actions array: contains
DLGAlertActionobjects, each with atitle(e.g. "OK", "Cancel") and astyle(such as.default,.cancelor.destructive). Your layout should visually distinguish these styles where needed. - Dismissal: the
ActionWrapperin the reference implementation (or your equivalent) is responsible for dismissing the view controller withself.dismiss(animated: true), before or after running the SDK's action closure. The SDK does not dismiss your customUIViewControllerautomatically.
Integration checklist#
Use this before shipping a host customization:
- The custom delegate is assigned in
AppDelegate'sdidFinishLaunchingWithOptions. - Your custom view controller reads the
actionsarray and creates a tap target for every action provided by the SDK. - The custom view controller dismisses itself when an action is selected.
- Trigger a known SDK dialog (e.g. delete a message or trigger a permission prompt) to verify your custom presentation, and check that the SDK completes the action after the button is pressed.