Content

Openers

Unflow provides you with content to show to your users. The openers we provide can be customised to look how you wish, or simply fetched from our service.

We've got an example of both on each platform below.

You can use Unflow as a data source and build an entirely custom app, like we did with Unf1ow.

You can customise the appearance of openers by using the OpenerView component.

Here, you'll be provided with each opener, and you can customise as you wish. It will be placed inside a scrolling HStack.

When you do this, you'll have to take control of opening the screens when they're tapped, using UnflowSdk.client.openScreen(with: opener.id)

OpenerView() { itemState in
    // use the opener with itemState.opener
}

This complete example shows you how you may choose to use that to create a simple fixed size notification style view.

struct YourOpenerView: View {
    var body: some View {
        OpenerView() { itemState in
            viewForOpener(opener: itemState.opener)
        }
    }

    func viewForOpener(opener: Opener) -> some View {
        Button {
            try? UnflowSDK.client.openScreen(withID: opener.id)
        } label: {
            HStack {
                if let imageURL = opener.imageURL {
                    AsyncImage(url: URL(string: imageURL))
                        .aspectRatio(contentMode: .fill)
                        .frame(width: 44, height: 44)
                        .cornerRadius(8)
                }
                VStack(alignment: .leading) {
                    Text(opener.title)
                        .lineLimit(1)
                    if let subtitle = opener.subtitle {
                        Text(subtitle)
                            .lineLimit(1)
                    }
                }
                .foregroundColor(.primary)
            }
            .padding()
            .background(Color.white, in: RoundedRectangle(cornerRadius: 12))
        }
        .frame(width: 200)
    }
}

The alternative option is to customise the interface entirely, using the alternative OpenerView.

If you want to limit the content shown, pass spaceKey, providing the key of a space from your dashboard, to only show content from that space.

var body: some View {
    OpenerView() { openers in
        // Do something with the openers array
    }
}

The final option is to fetch the openers from Unflow and do what you wish with them. This is not dependent on any particular UI framework, so allows you to work with UIKit, SwiftUI, or any other.

You can use Combine to get a live updating stream or fetch once with a completion handler.

If you want to limit the content shown, pass the id, providing the key of a space from your dashboard, to only show content from that space.

import Combine

class YourViewModel {
    private var cancellables: Set<AnyCancellable> = []

    func fetchOpeners() {
        UnflowSDK.client.openers().receive(on: RunLoop.main).sink { openers in
            // Do something with the openers
        }
        .store(in: &cancellables)
        // Fetch once without live updates
        UnflowSDK.client.getOpeners { openers in
            // Do something with the openers
        }
    }
}