Skip to content

Commit

Permalink
iOS: Added custom theme feature
Browse files Browse the repository at this point in the history
  • Loading branch information
CSantosM committed Dec 20, 2020
1 parent 4b9ee99 commit 07966d7
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 2 deletions.
2 changes: 2 additions & 0 deletions plugin.xml
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,8 @@

<!-- source-file -->
<source-file src="src/ios/VeriffCordovaPlugin.swift" />
<source-file src="src/ios/Utils.swift" />


<podspec>
<config>
Expand Down
30 changes: 30 additions & 0 deletions src/ios/Utils.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
import Foundation
import UIKit
extension UIColor {
convenience init(hexString: String, alpha: CGFloat = 1.0) {
let hexString: String = hexString.trimmingCharacters(in: CharacterSet.whitespacesAndNewlines)
let scanner = Scanner(string: hexString)
if (hexString.hasPrefix("#")) {
scanner.scanLocation = 1
}
var color: UInt32 = 0
scanner.scanHexInt32(&color)
let mask = 0x000000FF
let r = Int(color >> 16) & mask
let g = Int(color >> 8) & mask
let b = Int(color) & mask
let red = CGFloat(r) / 255.0
let green = CGFloat(g) / 255.0
let blue = CGFloat(b) / 255.0
self.init(red:red, green:green, blue:blue, alpha:alpha)
}
func toHexString() -> String {
var r:CGFloat = 0
var g:CGFloat = 0
var b:CGFloat = 0
var a:CGFloat = 0
getRed(&r, green: &g, blue: &b, alpha: &a)
let rgb:Int = (Int)(r*255)<<16 | (Int)(g*255)<<8 | (Int)(b*255)<<0
return String(format:"#%06x", rgb)
}
}
11 changes: 9 additions & 2 deletions src/ios/VeriffCordovaPlugin.swift
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,18 @@ import Veriff
func launchVeriffSDK(command: CDVInvokedUrlCommand) {
callbackId = command.callbackId! as String
let sessionUrl = command.arguments[0] as! String
var configuration = VeriffSdk.Configuration()

if let veriffConfiguration: Dictionary<String,String> = command.arguments[1] as? Dictionary<String,String> {
let branding = VeriffSdk.Branding(themeColor: UIColor.init(hexString: veriffConfiguration["themeColor"]!))
configuration = VeriffSdk.Configuration(branding: branding)
}

let veriff = VeriffSdk.shared
veriff.delegate = self
veriff.startAuthentication(sessionUrl: sessionUrl)
veriff.startAuthentication(sessionUrl: sessionUrl, configuration: configuration)
}

private func returnErrorToCordova(message: String) {
self.commandDelegate!.send(
CDVPluginResult(
Expand Down

0 comments on commit 07966d7

Please sign in to comment.