Skip to content

Commit

Permalink
Merge pull request #456 from getyoti/SDK-2486
Browse files Browse the repository at this point in the history
SDK-2486: Support dark mode in IDV SDK
  • Loading branch information
artem-yoti authored Sep 23, 2024
2 parents 364d037 + e1224a6 commit 8b913d3
Show file tree
Hide file tree
Showing 3 changed files with 119 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -86,4 +86,8 @@ private DocScanConstants() { }
public static final String EAGER = "EAGER";
public static final String JUST_IN_TIME = "JUST_IN_TIME";

public static final String ON = "ON";
public static final String OFF = "OFF";
public static final String AUTO = "AUTO";

}
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,18 @@ public class SdkConfig {
@JsonProperty(Property.PRIMARY_COLOUR)
private final String primaryColour;

@JsonProperty(Property.PRIMARY_COLOUR_DARK_MODE)
private final String primaryColourDarkMode;

@JsonProperty(Property.SECONDARY_COLOUR)
private final String secondaryColour;

@JsonProperty(Property.FONT_COLOUR)
private final String fontColour;

@JsonProperty(Property.DARK_MODE)
private final String darkMode;

@JsonProperty(Property.LOCALE)
private final String locale;

Expand Down Expand Up @@ -50,9 +56,11 @@ public class SdkConfig {

SdkConfig(String allowedCaptureMethods,
String primaryColour,
String primaryColourDarkMode,
String secondaryColour,
String fontColour,
String locale,
String darkMode,
String presetIssuingCountry,
String successUrl,
String errorUrl,
Expand All @@ -63,9 +71,11 @@ public class SdkConfig {
String biometricConsentFlow) {
this.allowedCaptureMethods = allowedCaptureMethods;
this.primaryColour = primaryColour;
this.primaryColourDarkMode = primaryColourDarkMode;
this.secondaryColour = secondaryColour;
this.fontColour = fontColour;
this.locale = locale;
this.darkMode = darkMode;
this.presetIssuingCountry = presetIssuingCountry;
this.successUrl = successUrl;
this.errorUrl = errorUrl;
Expand Down Expand Up @@ -98,6 +108,15 @@ public String getPrimaryColour() {
return primaryColour;
}

/**
* The primary colour to use when in dark mode
*
* @return the primary colour
*/
public String getPrimaryColourDarkMode() {
return primaryColourDarkMode;
}

/**
* The secondary colour
*
Expand Down Expand Up @@ -125,6 +144,15 @@ public String getLocale() {
return locale;
}

/**
* Whether to use dark mode - may be 'ON', 'OFF', or 'AUTO'
*
* @return the dark mode
*/
public String getDarkMode() {
return darkMode;
}

/**
* The preset issuing country
*
Expand Down Expand Up @@ -204,9 +232,11 @@ public static class Builder {

private String allowedCaptureMethods;
private String primaryColour;
private String primaryColourDarkMode;
private String secondaryColour;
private String fontColour;
private String locale;
private String darkMode;
private String presetIssuingCountry;
private String successUrl;
private String errorUrl;
Expand Down Expand Up @@ -258,6 +288,17 @@ public Builder withPrimaryColour(String primaryColour) {
return this;
}

/**
* Sets the primary colour to be used by the web/native client when in dark mode
*
* @param primaryColourDarkMode the primary colour for the dark mode, hexadecimal value e.g. #ff0000
* @return the builder
*/
public Builder withPrimaryColourDarkMode(String primaryColourDarkMode) {
this.primaryColourDarkMode = primaryColourDarkMode;
return this;
}

/**
* Sets the secondary colour to be used by the web/native client (used on the button)
*
Expand Down Expand Up @@ -291,6 +332,44 @@ public Builder withLocale(String locale) {
return this;
}

/**
* Whether to use dark mode on the web/native client - may be 'ON', 'OFF', or 'AUTO'
*
* @param darkMode the dark mode, e.g. "ON"
* @return the builder
*/
public Builder withDarkMode(String darkMode) {
this.darkMode = darkMode;
return this;
}

/**
* Sets the dark mode to 'ON' to be used by the web/native client
*
* @return the builder
*/
public Builder withDarkModeOn() {
return withDarkMode(DocScanConstants.ON);
}

/**
* Sets the dark mode to 'OFF' to be used by the web/native client
*
* @return the builder
*/
public Builder withDarkModeOff() {
return withDarkMode(DocScanConstants.OFF);
}

/**
* Sets the dark mode to 'AUTO' to be used by the web/native client
*
* @return the builder
*/
public Builder withDarkModeAuto() {
return withDarkMode(DocScanConstants.AUTO);
}

/**
* Sets the preset issuing country used by the web/native client
*
Expand Down Expand Up @@ -406,9 +485,11 @@ public SdkConfig build() {
return new SdkConfig(
allowedCaptureMethods,
primaryColour,
primaryColourDarkMode,
secondaryColour,
fontColour,
locale,
darkMode,
presetIssuingCountry,
successUrl,
errorUrl,
Expand All @@ -425,8 +506,10 @@ private static final class Property {

private static final String ALLOWED_CAPTURE_METHODS = "allowed_capture_methods";
private static final String PRIMARY_COLOUR = "primary_colour";
private static final String PRIMARY_COLOUR_DARK_MODE = "primary_colour_dark_mode";
private static final String SECONDARY_COLOUR = "secondary_colour";
private static final String FONT_COLOUR = "font_colour";
private static final String DARK_MODE = "dark_mode";
private static final String LOCALE = "locale";
private static final String PRESET_ISSUING_COUNTRY = "preset_issuing_country";
private static final String SUCCESS_URL = "success_url";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,11 @@
public class SdkConfigTest {

private static final String SOME_PRIMARY_COLOUR = "#FFFFFF";
private static final String SOME_PRIMARY_COLOUR_DARK_MODE = "#3b706f";
private static final String SOME_SECONDARY_COLOUR = "#679bdd";
private static final String SOME_FONT_COLOUR = "#b40c12";
private static final String SOME_LOCALE = "en";
private static final String SOME_DARK_MODE = "ON";
private static final String SOME_PRESET_ISSUING_COUNTRY = "USA";
private static final String SOME_BRAND_ID = "someBrandId";

Expand All @@ -30,9 +32,11 @@ public void shouldBuildSimpleSdkConfigWithAllOptions() {
SdkConfig result = SdkConfig.builder()
.withAllowsCamera()
.withPrimaryColour(SOME_PRIMARY_COLOUR)
.withPrimaryColourDarkMode(SOME_PRIMARY_COLOUR_DARK_MODE)
.withSecondaryColour(SOME_SECONDARY_COLOUR)
.withFontColour(SOME_FONT_COLOUR)
.withLocale(SOME_LOCALE)
.withDarkMode(SOME_DARK_MODE)
.withPresetIssuingCountry(SOME_PRESET_ISSUING_COUNTRY)
.withSuccessUrl(SOME_SUCCESS_URL)
.withErrorUrl(SOME_ERROR_URL)
Expand All @@ -46,9 +50,11 @@ public void shouldBuildSimpleSdkConfigWithAllOptions() {

assertThat(result.getAllowedCaptureMethods(), is("CAMERA"));
assertThat(result.getPrimaryColour(), is(SOME_PRIMARY_COLOUR));
assertThat(result.getPrimaryColourDarkMode(), is(SOME_PRIMARY_COLOUR_DARK_MODE));
assertThat(result.getSecondaryColour(), is(SOME_SECONDARY_COLOUR));
assertThat(result.getFontColour(), is(SOME_FONT_COLOUR));
assertThat(result.getLocale(), is(SOME_LOCALE));
assertThat(result.getDarkMode(), is(SOME_DARK_MODE));
assertThat(result.getPresetIssuingCountry(), is(SOME_PRESET_ISSUING_COUNTRY));
assertThat(result.getSuccessUrl(), is(SOME_SUCCESS_URL));
assertThat(result.getErrorUrl(), is(SOME_ERROR_URL));
Expand Down Expand Up @@ -112,5 +118,31 @@ public void shouldOverridePreviousAllowedCaptureMethods() {
assertThat(result.getAllowedCaptureMethods(), is("CAMERA"));
}

@Test
public void shouldSetDarkModeToOn() {
SdkConfig result = SdkConfig.builder()
.withDarkModeOn()
.build();

assertThat(result.getDarkMode(), is("ON"));
}

@Test
public void shouldSetDarkModeToOff() {
SdkConfig result = SdkConfig.builder()
.withDarkModeOff()
.build();

assertThat(result.getDarkMode(), is("OFF"));
}

@Test
public void shouldSetDarkModeToAuto() {
SdkConfig result = SdkConfig.builder()
.withDarkModeAuto()
.build();

assertThat(result.getDarkMode(), is("AUTO"));
}

}

0 comments on commit 8b913d3

Please sign in to comment.