Get started

Integration

The Common UI SDK is a core configuration module for all DriveKit UI SDKs.

To add Common UI module to your app, add the following pod to your podfile:

target 'my-target' do
  pod 'DriveKitCommonUI'
end

Then, run pod install

On this Github repository, you have a demo app and source code that you can use as an example.

Initialization

An initialization phase is required to ensure that Common UI SDK works perfectly. To initialize Common UI SDK in your app, you must call the initialization method in didFinishLaunchingWithOptions method of your AppDelegate file.

import DriveKitCoreModule
import DriveKitCommonUI

func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {
     DriveKit.shared.initialize()
     DriveKitUI.shared.initialize()
     ...
}

This method will initialize the SDK with the default configuration set up by DriveQuant.

It is possible (from Swift, not Objective-C) to provide some parameters to this DriveKitUI initialization method in order to set custom values for colors (colors: DKColors), fonts (fonts: DKFonts), and/or text localization (overridedStringsFileName: String?).

Configurations

Colors

The colors that can be configured are listed in the table below:

To override the default colors configuration, you should create a subclass of DKDefaultColors and override the colors that you want to change (or you can create an object implementing the DKColors protocol, necessary if your project is in Objective-C for instance). Then pass an instance of this object as a parameter of the configureColors method.

import DriveKitCoreModule
import DriveKitCommonUI

func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {
     DriveKit.shared.initialize()
     DriveKitUI.shared.initialize()
     DriveKitUI.shared.configureColors(Colors())
     ...
}

class Colors: DKDefaultColors {
    override func primaryColor() -> UIColor {
        return UIColor.red
    }
}

Fonts

The Common UI configuration module allows to set up two fonts:

  1. primaryFont: this is the main font used in the application. The default value is Roboto.

  2. secondaryFont: this is the font used on the page titles or to emphasize a specific point. The default value is Roboto.

To override the fonts, you can add the primary and secondary fonts to the CommonUI SDK by calling the configureFonts method as in this following example:

import DriveKitCoreModule
import DriveKitCommonUI

func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {
     DriveKit.shared.initialize()
     DriveKitUI.shared.initialize()
     DriveKitUI.shared.configureFonts(Fonts())
     ...
}

class Fonts: DKDefaultFonts {
    override func primaryFont() -> String {
        return "Impact"
    }
}

Note: From Objective-C, it is not possible to subclass the DKDefaultFonts class. To override the fonts, it is thus necessary to create a class implementing the DKFonts protocol.

Text Localization

Contents of each DriveKit UI module are translated into 5 languages: English, French, German, Spanish and Italian.

DriveKit simplifies the internationalization of your application and it is possible to add other languages.

DriveKit Common UI contains a number of basic text keys used in other DriveKit UI modules. You can override these keys to customize your application.

To help make the text keys in the code easier to read, a specific nomenclature has been set up: dk_<module name>_<key description>.

For the Common UI module, all localizable keys are prefixed with: dk_common.

There are several files containing text keys:

  • A .strings file in the common UI module containing generic keys to all modules.

  • One file per UI module containing module-specific text keys.

Text customization

To override a text key in the common UI module, simply define the keys to be modified in a .strings file at the application level and configure the filename in the common UI module. The text keys can be directly retrieved on Github, in the Localizable folder of each module.

import DriveKitCoreModule
import DriveKitCommonUI

func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {
    DriveKit.shared.initialize()
    DriveKitUI.shared.initialize()
    DriveKitUI.shared.configureStringsFileName("OverridedStrings")
    ...
}

Add language

The translation file can be retrieved from GitHub. Add it to your application after adding the appropriate translation(s).

Get analytics

For analytics purposes, you can tag screens of any DriveKit UI component by providing to this following method an instance of an object conforming to DKAnalytics protocol:

DriveKitUI.shared.configureAnalytics(Analytics())

Where the Analytics object is for instance:

class Analytics: DKAnalytics {
    func trackScreen(_ screen: String, viewController: UIViewController) {
        // TODO: manage screen tracking here with the tool of your choice.
    }

    func trackEvent(_ event: DKAnalyticsEvent, parameters: [String : Any]?) {
        // TODO: manage event tracking here with the tool of your choice.
    }
}

The screen String received in the trackScreen method is the value associated to one of the keys in this array, corresponding to the visited screen. If you want to customize screen tags, you can provide the path to a plist file (see the default tags file) with your custom values in the configuration method:

DriveKitUI.shared.configureAnalytics(Analytics(), tagsFileName: "CustomAnalyticsTags")

If, in the plist, a value is empty, the tracking is disabled for this screen.

The trackEvent method allows you to add additional information that may be useful for analysis. For example, that method is called each time the user opens the trip detail screen.

Last updated