Skip to content

Commit 8b913d3

Browse files
authored
Merge pull request #456 from getyoti/SDK-2486
SDK-2486: Support dark mode in IDV SDK
2 parents 364d037 + e1224a6 commit 8b913d3

File tree

3 files changed

+119
-0
lines changed

3 files changed

+119
-0
lines changed

yoti-sdk-api/src/main/java/com/yoti/api/client/docs/DocScanConstants.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,4 +86,8 @@ private DocScanConstants() { }
8686
public static final String EAGER = "EAGER";
8787
public static final String JUST_IN_TIME = "JUST_IN_TIME";
8888

89+
public static final String ON = "ON";
90+
public static final String OFF = "OFF";
91+
public static final String AUTO = "AUTO";
92+
8993
}

yoti-sdk-api/src/main/java/com/yoti/api/client/docs/session/create/SdkConfig.java

Lines changed: 83 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,12 +15,18 @@ public class SdkConfig {
1515
@JsonProperty(Property.PRIMARY_COLOUR)
1616
private final String primaryColour;
1717

18+
@JsonProperty(Property.PRIMARY_COLOUR_DARK_MODE)
19+
private final String primaryColourDarkMode;
20+
1821
@JsonProperty(Property.SECONDARY_COLOUR)
1922
private final String secondaryColour;
2023

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

27+
@JsonProperty(Property.DARK_MODE)
28+
private final String darkMode;
29+
2430
@JsonProperty(Property.LOCALE)
2531
private final String locale;
2632

@@ -50,9 +56,11 @@ public class SdkConfig {
5056

5157
SdkConfig(String allowedCaptureMethods,
5258
String primaryColour,
59+
String primaryColourDarkMode,
5360
String secondaryColour,
5461
String fontColour,
5562
String locale,
63+
String darkMode,
5664
String presetIssuingCountry,
5765
String successUrl,
5866
String errorUrl,
@@ -63,9 +71,11 @@ public class SdkConfig {
6371
String biometricConsentFlow) {
6472
this.allowedCaptureMethods = allowedCaptureMethods;
6573
this.primaryColour = primaryColour;
74+
this.primaryColourDarkMode = primaryColourDarkMode;
6675
this.secondaryColour = secondaryColour;
6776
this.fontColour = fontColour;
6877
this.locale = locale;
78+
this.darkMode = darkMode;
6979
this.presetIssuingCountry = presetIssuingCountry;
7080
this.successUrl = successUrl;
7181
this.errorUrl = errorUrl;
@@ -98,6 +108,15 @@ public String getPrimaryColour() {
98108
return primaryColour;
99109
}
100110

111+
/**
112+
* The primary colour to use when in dark mode
113+
*
114+
* @return the primary colour
115+
*/
116+
public String getPrimaryColourDarkMode() {
117+
return primaryColourDarkMode;
118+
}
119+
101120
/**
102121
* The secondary colour
103122
*
@@ -125,6 +144,15 @@ public String getLocale() {
125144
return locale;
126145
}
127146

147+
/**
148+
* Whether to use dark mode - may be 'ON', 'OFF', or 'AUTO'
149+
*
150+
* @return the dark mode
151+
*/
152+
public String getDarkMode() {
153+
return darkMode;
154+
}
155+
128156
/**
129157
* The preset issuing country
130158
*
@@ -204,9 +232,11 @@ public static class Builder {
204232

205233
private String allowedCaptureMethods;
206234
private String primaryColour;
235+
private String primaryColourDarkMode;
207236
private String secondaryColour;
208237
private String fontColour;
209238
private String locale;
239+
private String darkMode;
210240
private String presetIssuingCountry;
211241
private String successUrl;
212242
private String errorUrl;
@@ -258,6 +288,17 @@ public Builder withPrimaryColour(String primaryColour) {
258288
return this;
259289
}
260290

291+
/**
292+
* Sets the primary colour to be used by the web/native client when in dark mode
293+
*
294+
* @param primaryColourDarkMode the primary colour for the dark mode, hexadecimal value e.g. #ff0000
295+
* @return the builder
296+
*/
297+
public Builder withPrimaryColourDarkMode(String primaryColourDarkMode) {
298+
this.primaryColourDarkMode = primaryColourDarkMode;
299+
return this;
300+
}
301+
261302
/**
262303
* Sets the secondary colour to be used by the web/native client (used on the button)
263304
*
@@ -291,6 +332,44 @@ public Builder withLocale(String locale) {
291332
return this;
292333
}
293334

335+
/**
336+
* Whether to use dark mode on the web/native client - may be 'ON', 'OFF', or 'AUTO'
337+
*
338+
* @param darkMode the dark mode, e.g. "ON"
339+
* @return the builder
340+
*/
341+
public Builder withDarkMode(String darkMode) {
342+
this.darkMode = darkMode;
343+
return this;
344+
}
345+
346+
/**
347+
* Sets the dark mode to 'ON' to be used by the web/native client
348+
*
349+
* @return the builder
350+
*/
351+
public Builder withDarkModeOn() {
352+
return withDarkMode(DocScanConstants.ON);
353+
}
354+
355+
/**
356+
* Sets the dark mode to 'OFF' to be used by the web/native client
357+
*
358+
* @return the builder
359+
*/
360+
public Builder withDarkModeOff() {
361+
return withDarkMode(DocScanConstants.OFF);
362+
}
363+
364+
/**
365+
* Sets the dark mode to 'AUTO' to be used by the web/native client
366+
*
367+
* @return the builder
368+
*/
369+
public Builder withDarkModeAuto() {
370+
return withDarkMode(DocScanConstants.AUTO);
371+
}
372+
294373
/**
295374
* Sets the preset issuing country used by the web/native client
296375
*
@@ -406,9 +485,11 @@ public SdkConfig build() {
406485
return new SdkConfig(
407486
allowedCaptureMethods,
408487
primaryColour,
488+
primaryColourDarkMode,
409489
secondaryColour,
410490
fontColour,
411491
locale,
492+
darkMode,
412493
presetIssuingCountry,
413494
successUrl,
414495
errorUrl,
@@ -425,8 +506,10 @@ private static final class Property {
425506

426507
private static final String ALLOWED_CAPTURE_METHODS = "allowed_capture_methods";
427508
private static final String PRIMARY_COLOUR = "primary_colour";
509+
private static final String PRIMARY_COLOUR_DARK_MODE = "primary_colour_dark_mode";
428510
private static final String SECONDARY_COLOUR = "secondary_colour";
429511
private static final String FONT_COLOUR = "font_colour";
512+
private static final String DARK_MODE = "dark_mode";
430513
private static final String LOCALE = "locale";
431514
private static final String PRESET_ISSUING_COUNTRY = "preset_issuing_country";
432515
private static final String SUCCESS_URL = "success_url";

yoti-sdk-api/src/test/java/com/yoti/api/client/docs/session/create/SdkConfigTest.java

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,11 @@
1313
public class SdkConfigTest {
1414

1515
private static final String SOME_PRIMARY_COLOUR = "#FFFFFF";
16+
private static final String SOME_PRIMARY_COLOUR_DARK_MODE = "#3b706f";
1617
private static final String SOME_SECONDARY_COLOUR = "#679bdd";
1718
private static final String SOME_FONT_COLOUR = "#b40c12";
1819
private static final String SOME_LOCALE = "en";
20+
private static final String SOME_DARK_MODE = "ON";
1921
private static final String SOME_PRESET_ISSUING_COUNTRY = "USA";
2022
private static final String SOME_BRAND_ID = "someBrandId";
2123

@@ -30,9 +32,11 @@ public void shouldBuildSimpleSdkConfigWithAllOptions() {
3032
SdkConfig result = SdkConfig.builder()
3133
.withAllowsCamera()
3234
.withPrimaryColour(SOME_PRIMARY_COLOUR)
35+
.withPrimaryColourDarkMode(SOME_PRIMARY_COLOUR_DARK_MODE)
3336
.withSecondaryColour(SOME_SECONDARY_COLOUR)
3437
.withFontColour(SOME_FONT_COLOUR)
3538
.withLocale(SOME_LOCALE)
39+
.withDarkMode(SOME_DARK_MODE)
3640
.withPresetIssuingCountry(SOME_PRESET_ISSUING_COUNTRY)
3741
.withSuccessUrl(SOME_SUCCESS_URL)
3842
.withErrorUrl(SOME_ERROR_URL)
@@ -46,9 +50,11 @@ public void shouldBuildSimpleSdkConfigWithAllOptions() {
4650

4751
assertThat(result.getAllowedCaptureMethods(), is("CAMERA"));
4852
assertThat(result.getPrimaryColour(), is(SOME_PRIMARY_COLOUR));
53+
assertThat(result.getPrimaryColourDarkMode(), is(SOME_PRIMARY_COLOUR_DARK_MODE));
4954
assertThat(result.getSecondaryColour(), is(SOME_SECONDARY_COLOUR));
5055
assertThat(result.getFontColour(), is(SOME_FONT_COLOUR));
5156
assertThat(result.getLocale(), is(SOME_LOCALE));
57+
assertThat(result.getDarkMode(), is(SOME_DARK_MODE));
5258
assertThat(result.getPresetIssuingCountry(), is(SOME_PRESET_ISSUING_COUNTRY));
5359
assertThat(result.getSuccessUrl(), is(SOME_SUCCESS_URL));
5460
assertThat(result.getErrorUrl(), is(SOME_ERROR_URL));
@@ -112,5 +118,31 @@ public void shouldOverridePreviousAllowedCaptureMethods() {
112118
assertThat(result.getAllowedCaptureMethods(), is("CAMERA"));
113119
}
114120

121+
@Test
122+
public void shouldSetDarkModeToOn() {
123+
SdkConfig result = SdkConfig.builder()
124+
.withDarkModeOn()
125+
.build();
126+
127+
assertThat(result.getDarkMode(), is("ON"));
128+
}
129+
130+
@Test
131+
public void shouldSetDarkModeToOff() {
132+
SdkConfig result = SdkConfig.builder()
133+
.withDarkModeOff()
134+
.build();
135+
136+
assertThat(result.getDarkMode(), is("OFF"));
137+
}
138+
139+
@Test
140+
public void shouldSetDarkModeToAuto() {
141+
SdkConfig result = SdkConfig.builder()
142+
.withDarkModeAuto()
143+
.build();
144+
145+
assertThat(result.getDarkMode(), is("AUTO"));
146+
}
115147

116148
}

0 commit comments

Comments
 (0)