Honestly, it’s not HTML … But it sort of is. But really, it isn’t.
DrivenUI is an iOS SDK which makes introducing and building Server Driven UI feature into iOS Applications much more convenient. Currently it’s based on JSON response format to render SwiftUI views on the screen.
CocoaPods is a dependency manager for Cocoa projects. For usage and installation instructions, visit their website. To integrate DrivenUI into your Xcode project using CocoaPods, specify it in your Podfile:
pod 'DrivenUI', '~> 0.1.1'
Swift Package Manager
The Swift Package Manager is a tool for automating the distribution of Swift code and is integrated into the swift compiler. It is in early development, but Driven does support its use on supported platforms.
Once you have your Swift package set up, adding DrivenUI as a dependency is as easy as adding it to the dependencies value of your Package.swift.
As we’re in BETA version, please fill an Issue with your application Bundle Id and leave your email and we will send you instantly your DrivenUI SDK Key.
You have two ways to init DrivenUI in your application.
If you are using SwiftUI new application life cycle, add configure method into init for your main App.
If you are using AppDelegate, add configure method into didFinishLaunchWithOptions method.
Driven.configure(with: YUOR_SDK_KEY)
Basic Usage
Connect to your Backend and retrieve your JSON response (Check supported views JSON Structure formats).
Parse your JSON response in your ViewModel:
// Add published property into your ViewModel
// so that you views can react on it's changes ;)
@Published var serverView: DrivenComponent?
// Parse JSON response from API to DrivenComponent
let response = try? JSONDecoder().decode(DrivenComponent.self, from: data)
if let response = response {
DispatchQueue.main.async {
self?.serverView = response
}
} else {
DispatchQueue.main.async {
self?.serverView = nil
}
}
In your Content View add this build function:
@ViewBuilder func buildView() -> some View {
if let serverView = viewModel.serverView {
DrivenComponentFactory(material: serverView).toPresentable()
} else {
Text("No views from server.")
}
}
Use this buildView inside your view hierarchy:
var body: some View {
NavigationView {
buildView()
.padding([.top], 48)
.navigationBarTitle("DrivenUI SDK")
}
}
And VOILA you have your views rendered on the screen 🔥
JSON Structure
Every supported view component is consist of 4 keys each one take a place based on the Component you need to render:
{
// type values are the Supported Views (Please check below section).
"type": "",
// properties values are pair of key-value of Supported Properties (Please check below section).
"properties": { },
// values are pair of key-value of Supported Values for each View (Please check below section).
"values": { },
// subviews values are pair of key-value of another component should be rendered inside one of those views: HStack, VStack, ZStack, and List.
"subviews": { }
}
Welcome to DrivenUI SDK
DrivenUI is an iOS SDK which makes introducing and building Server Driven UI feature into iOS Applications much more convenient. Currently it’s based on JSON response format to render SwiftUI views on the screen.
⭐️ Star us on GitHub — it helps!
Table of content
Requirments
Installation
CocoaPods
CocoaPods is a dependency manager for Cocoa projects. For usage and installation instructions, visit their website. To integrate DrivenUI into your Xcode project using CocoaPods, specify it in your
Podfile
:Swift Package Manager
The Swift Package Manager is a tool for automating the distribution of Swift code and is integrated into the
swift
compiler. It is in early development, but Driven does support its use on supported platforms.Once you have your Swift package set up, adding DrivenUI as a dependency is as easy as adding it to the
dependencies
value of yourPackage.swift
.Usage
Init SDK
As we’re in
BETA
version, please fill an Issue with your applicationBundle Id
and leave your email and we will send you instantly your DrivenUI SDK Key.You have two ways to init DrivenUI in your application.
init
for your main App.AppDelegate
, add configure method intodidFinishLaunchWithOptions
method.Basic Usage
Connect to your Backend and retrieve your JSON response (Check supported views JSON Structure formats).
Parse your JSON response in your ViewModel:
In your Content View add this build function:
Use this
buildView
inside your view hierarchy:And VOILA you have your views rendered on the screen 🔥
JSON Structure
Every supported view component is consist of 4 keys each one take a place based on the Component you need to render:
Backend Response for Text View Example
Backend Response for Image View Example
Backend Response for HStack View Example
Supported Views
imageUrl
for retrieving image from URL.systemIconName
for using system image.localImageName
for using asset catalog image.text
the text value that will be shown.Supported Properties
width
andheight
foregroundColor
,backgroundColor
, andborderColor
borderWidth
,spacing
(for HStack and VStack), andpadding
horizontalAlignment
leading
center
trailing
verticalAlignment
top
bottom
center
firstTextBaseline
lastTextBaseline
font
largeTitle
title
headline
subheadline
body
callout
footnote
caption
fontWeight
ultraLight
thin
light
regular
medium
semibold
bold
heavy
black
TODO
Please check CHANGELOG file for more information to know what’s included in each version.
License