Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -413,8 +413,13 @@ You can customize the SDK by adding a `colors.json` file to your project at the
"onfidoPrimaryColor": "#FF0000",
"onfidoPrimaryButtonTextColor": "#008000",
"onfidoPrimaryButtonColorPressed": "#FFA500",
"onfidoAndroidColorAccent":"#4BC0B1",
"onfidoAndroidStatusBarColor": "#A52A2A",
"onfidoAndroidToolBarColor": "#800080",
"onfidoAndroidToolBarTitleColor": "#3E3B32",
"onfidoAndroidToolBarSubtitleColor": "#F5D033",
"onfidoAndroidButtonCornerRadius": 32,
"onfidoIosButtonCornerRadius": 26,
"onfidoIosSupportDarkMode": true
}
```
Expand All @@ -423,8 +428,13 @@ Below is a description of all available keys:
* **`onfidoPrimaryColor`**: Defines the background color of views such as the document type icon, capture confirmation buttons, and back navigation button.
* **`onfidoPrimaryButtonTextColor`**: Defines the text color of labels included in views such as capture confirmation buttons.
* **`onfidoPrimaryButtonColorPressed`**: Defines the background color of capture confirmation buttons when pressed.
* **`onfidoAndroidColorAccent`**: Android only. Defines the color of the `FloatingActionButton` which allows the user to move between steps, as well as some details on the alert dialogs shown during the flow.
* **`onfidoAndroidStatusBarColor`**: Android only. Defines the background color of the `Toolbar` that guides the user through the flow.
* **`onfidoAndroidToolBarColor`**: Android only. Defines the color of the status bar above the `Toolbar`.
* **`onfidoAndroidToolBarTitleColor`**: Android only. Defines the color of the title on the `Toolbar`.
* **`onfidoAndroidToolBarSubtitleColor`**: Android only. Defines the color of the subtitle on the `Toolbar`.
* **`onfidoAndroidButtonCornerRadius`**: Android only. Defines the radius dimensions of all the corners of primary and secondary buttons
* **`onfidoIosButtonCornerRadius`**: iOS Only. Defines the radius dimensions of all the corners of primary and secondary buttons
* **`onfidoIosSupportDarkMode`**: iOS Only. Defines if Dark Mode will be supported on SDK screens. The value is true by default.

Once you've added the colors.json to your project, you should add colors.json file to your xcode project as bundle resource. You can create symbolic link (rather than copy paste) to prevent redundancy. You can check out SampleApp project to see example usage.
Expand Down
7 changes: 7 additions & 0 deletions ios/OnfidoSdk.swift
Original file line number Diff line number Diff line change
Expand Up @@ -14,16 +14,19 @@ public class AppearancePublic: NSObject {
public let primaryColor: UIColor
public let primaryTitleColor: UIColor
public let primaryBackgroundPressedColor: UIColor
public let buttonCornerRadius: CGFloat
public let supportDarkMode: Bool

public init(
primaryColor: UIColor,
primaryTitleColor: UIColor,
primaryBackgroundPressedColor: UIColor,
buttonCornerRadius: CGFloat,
supportDarkMode: Bool = true) {
self.primaryColor = primaryColor
self.primaryTitleColor = primaryTitleColor
self.primaryBackgroundPressedColor = primaryBackgroundPressedColor
self.buttonCornerRadius = buttonCornerRadius
self.supportDarkMode = supportDarkMode
}
}
Expand Down Expand Up @@ -51,6 +54,8 @@ public func loadAppearancePublicFromFile(filePath: String?) throws -> Appearance
? UIColor.white : UIColor.from(hex: jsonResult["onfidoPrimaryButtonTextColor"] as! String)
let primaryBackgroundPressedColor: UIColor = (jsonResult["onfidoPrimaryButtonColorPressed"] == nil)
? UIColor.primaryButtonColorPressed : UIColor.from(hex: jsonResult["onfidoPrimaryButtonColorPressed"] as! String)
let buttonCornerRadius: CGFloat = (jsonResult["onfidoIosButtonCornerRadius"] == nil)
? 5 : jsonResult["onfidoIosButtonCornerRadius"] as! CGFloat
let supportDarkMode: Bool = (jsonResult["onfidoIosSupportDarkMode"] == nil)
? true : jsonResult["onfidoIosSupportDarkMode"] as! Bool

Expand All @@ -59,6 +64,7 @@ public func loadAppearancePublicFromFile(filePath: String?) throws -> Appearance
primaryColor: primaryColor,
primaryTitleColor: primaryTitleColor,
primaryBackgroundPressedColor: primaryBackgroundPressedColor,
buttonCornerRadius: buttonCornerRadius,
supportDarkMode: supportDarkMode
)
return appearancePublic
Expand All @@ -80,6 +86,7 @@ public func loadAppearanceFromFile(filePath: String?) throws -> Appearance {
appearance.primaryColor = appearancePublic.primaryColor
appearance.primaryTitleColor = appearancePublic.primaryTitleColor
appearance.primaryBackgroundPressedColor = appearancePublic.primaryBackgroundPressedColor
appearance.buttonCornerRadius = appearancePublic.buttonCornerRadius
appearance.supportDarkMode = appearancePublic.supportDarkMode
return appearance
} else {
Expand Down
55 changes: 46 additions & 9 deletions scripts/update_colors.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,13 +26,23 @@ try {
fs.mkdirSync('android/src/main/res/values')
}

fs.writeFile('android/src/main/res/values/colors.xml', generateFileContent(colors), function (e) {
fs.writeFile('android/src/main/res/values/colors.xml', generateColorsFileContent(colors), function (e) {
if (e != null) {
console.log('\nAn error occured while trying to update colors:\n' + e + '\n')
} else {
console.log("\nColors were successfully updated\n")
}
})

if (colors.onfidoAndroidButtonCornerRadius) {
fs.writeFile('android/src/main/res/values/dimens.xml', generateDimensFileContent(colors.onfidoAndroidButtonCornerRadius), function (e) {
if (e != null) {
console.log('\nAn error occured while trying to update border radius:\n' + e + '\n')
} else {
console.log("\Border radius was successfully updated\n")
}
})
}
});
} else {
console.log('\nNo colors.json was found. Ensure it is at the same level as your node-modules directory\n')
Expand All @@ -41,31 +51,58 @@ try {
console.log(e)
}

function generateFileContent(colors) {
function generateColorsFileContent(colors) {
let fileContent = '<?xml version="1.0" encoding="utf-8"?>\n'
fileContent += '<resources>\n'
Object.keys(colors).forEach((color) => {
let keyName = color;
switch (keyName) {
case 'onfidoAndroidColorAccent':
keyName = 'onfidoColorAccent'
break
case 'onfidoPrimaryColor':
keyName = 'onfidoPrimaryButtonColor'
break
case 'onfidoPrimaryButtonColorPressed':
keyName = 'onfidoPrimaryButtonColorPressed'
break
case 'onfidoPrimaryButtonTextColor':
keyName = 'onfidoPrimaryButtonTextColor'
break
case 'onfidoAndroidStatusBarColor':
keyName = 'onfidoColorPrimary'
break
case 'onfidoAndroidToolBarColor':
keyName = 'onfidoColorPrimaryDark'
break
case 'onfidoAndroidToolBarTitleColor':
keyName = 'onfidoTextColorPrimary'
break
case 'onfidoAndroidToolBarSubtitleColor':
keyName = 'onfidoTextColorSecondary'
break
default:
return
}

if (color !== 'onfidoIosSupportDarkMode') {
fileContent += '\t<color name=\"'
fileContent += keyName
fileContent += "\">"
fileContent += colors[color]
fileContent += "</color>\n"
}
fileContent += '\t<color name=\"'
fileContent += keyName
fileContent += "\">"
fileContent += colors[color]
fileContent += "</color>\n"
})
fileContent += "</resources>"
return fileContent
}

function generateDimensFileContent(borderRadius) {
let fileContent = '<resources>\n'
fileContent += '\t<dimen name=\"'
fileContent += 'onfidoButtonCornerRadius'
fileContent += "\">"
fileContent += borderRadius
fileContent += "dp"
fileContent += "</dimen>\n"
fileContent += "</resources>"
return fileContent
}