react-native-persona 1.2.5 → 1.2.9

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -6,6 +6,7 @@ class AndroidResourcePrinter {
6
6
  theme: AndroidThemeObject;
7
7
  root: XMLBuilder;
8
8
  buttonDrawable: XMLBuilder;
9
+ buttonSecondaryDrawable: XMLBuilder;
9
10
  buttonColor: XMLBuilder;
10
11
  preprintQueue: (() => void)[] = [];
11
12
  printQueue: (() => void)[] = [];
@@ -17,6 +18,9 @@ class AndroidResourcePrinter {
17
18
  this.buttonDrawable = createXml({ version: "1.0" }).ele("selector", {
18
19
  "xmlns:android": "http://schemas.android.com/apk/res/android",
19
20
  });
21
+ this.buttonSecondaryDrawable = createXml({ version: "1.0" }).ele("selector", {
22
+ "xmlns:android": "http://schemas.android.com/apk/res/android",
23
+ });
20
24
  this.buttonColor = createXml({ version: "1.0" }).ele("selector", {
21
25
  "xmlns:android": "http://schemas.android.com/apk/res/android",
22
26
  });
@@ -32,6 +36,7 @@ class AndroidResourcePrinter {
32
36
  return {
33
37
  style: this.root,
34
38
  buttonDrawable: this.buttonDrawable,
39
+ buttonSecondaryDrawable: this.buttonSecondaryDrawable,
35
40
  buttonColor: this.buttonColor,
36
41
  };
37
42
  }
@@ -44,6 +49,9 @@ class AndroidResourcePrinter {
44
49
  this.titleText();
45
50
  this.bodyText();
46
51
  this.footnoteText();
52
+ this.cameraInstructionsText();
53
+ this.cameraHintText();
54
+ this.cameraGuideHintText();
47
55
  // this.formLabelText();
48
56
  this.textField();
49
57
  this.pickerText();
@@ -145,7 +153,7 @@ class AndroidResourcePrinter {
145
153
  }
146
154
 
147
155
  private titleText() {
148
- if (this.theme.titleTextColor || this.theme.titleTextFont) {
156
+ if (this.theme.titleTextColor || this.theme.titleTextSize || this.theme.titleTextFont) {
149
157
  this.printQueue.push(() => {
150
158
  this.root = this.root
151
159
  .ele("item", { name: "personaTitleTextAppearance" })
@@ -178,9 +186,10 @@ class AndroidResourcePrinter {
178
186
 
179
187
  // Default values taken from `Persona.Text.Title`
180
188
  // in shared/src/main/res/values/styles.xml
189
+ const textSize = this.theme.titleTextSize ? `${this.theme.titleTextSize}sp` : "26sp";
181
190
  this.root = this.root
182
191
  .ele("item", { name: "android:textSize" })
183
- .txt("26sp")
192
+ .txt(textSize)
184
193
  .up()
185
194
  .ele("item", { name: "android:textStyle" })
186
195
  .txt("bold")
@@ -199,7 +208,7 @@ class AndroidResourcePrinter {
199
208
  }
200
209
 
201
210
  private bodyText() {
202
- if (this.theme.bodyTextColor || this.theme.bodyTextFont) {
211
+ if (this.theme.bodyTextColor || this.theme.bodyTextSize || this.theme.bodyTextFont) {
203
212
  this.printQueue.push(() => {
204
213
  this.root = this.root
205
214
  .ele("item", { name: "personaBodyTextAppearance" })
@@ -230,11 +239,10 @@ class AndroidResourcePrinter {
230
239
  .up();
231
240
  }
232
241
 
233
- // Default values taken from `Persona.Text.Body`
234
- // in shared/src/main/res/values/styles.xml
242
+ const textSize = this.theme.bodyTextSize ? `${this.theme.bodyTextSize}sp` : "18sp";
235
243
  this.root = this.root
236
244
  .ele("item", { name: "android:textSize" })
237
- .txt("18sp")
245
+ .txt(textSize)
238
246
  .up();
239
247
 
240
248
  this.root = this.root.up();
@@ -254,10 +262,6 @@ class AndroidResourcePrinter {
254
262
  this.postPrintQueue.push(() => {
255
263
  this.root = this.root
256
264
  .ele("style", { name: "TextAppearance.AppCompat.Small" })
257
- .ele("item", { name: "android:textSize" })
258
- // Used default value found in the Android SDK
259
- .txt("@dimen/abc_text_size_small_material")
260
- .up()
261
265
  .ele("item", { name: "android:textColor" })
262
266
  .txt(
263
267
  // Used default value found in the Android SDK
@@ -274,11 +278,177 @@ class AndroidResourcePrinter {
274
278
  )
275
279
  .up();
276
280
  }
281
+ // Default value found in the Android SDK
282
+ const textSize = this.theme.footnoteTextSize ? `${this.theme.footnoteTextSize}sp` : "@dimen/abc_text_size_small_material";
283
+ this.root = this.root
284
+ .ele("item", { name: "android:textSize" })
285
+ .txt(textSize)
286
+ .up();
287
+
288
+ this.root = this.root.up();
289
+ });
290
+ }
291
+ }
292
+
293
+ private cameraInstructionsText() {
294
+ if (this.theme.cameraInstructionsTextColor ||
295
+ this.theme.cameraInstructionsTextSize ||
296
+ this.theme.cameraInstructionsTextFont) {
297
+ this.printQueue.push(() => {
298
+ this.root = this.root
299
+ .ele("item", { name: "personaCameraTitleTextAppearance" })
300
+ .txt("@style/RN.Persona.Text.CameraTitle")
301
+ .up();
302
+ });
303
+
304
+ // Create a text appearance
305
+ this.postPrintQueue.push(() => {
306
+ this.root = this.root.ele("style", {
307
+ name: "RN.Persona.Text.CameraTitle",
308
+ parent: "Persona.Text.CameraTitle",
309
+ });
310
+
311
+ if (this.theme.cameraInstructionsTextColor) {
312
+ this.root = this.root
313
+ .ele("item", { name: "android:textColor" })
314
+ .txt(this.theme.cameraInstructionsTextColor as string)
315
+ .up();
316
+ }
317
+
318
+ if (this.theme.cameraInstructionsTextFont) {
319
+ // TODO: Add notice about how to add a custom font that can be
320
+ // referenced here on Android
321
+ this.root = this.root
322
+ .ele("item", { name: "android:fontFamily" })
323
+ .txt(this.theme.cameraInstructionsTextFont as string)
324
+ .up();
325
+ }
326
+
327
+ const textSize = this.theme.cameraInstructionsTextSize ?
328
+ `${this.theme.cameraInstructionsTextSize}sp` : "20sp";
329
+ this.root = this.root
330
+ .ele("item", { name: "android:textSize" })
331
+ .txt(textSize)
332
+ .up();
333
+
334
+ this.root = this.root.up();
335
+ });
336
+ } else {
337
+ this.printQueue.push(() => {
338
+ this.root = this.root
339
+ .ele("item", { name: "personaCameraTitleTextAppearance" })
340
+ .txt("@style/Persona.Text.CameraTitle")
341
+ .up();
342
+ });
343
+ }
344
+ }
345
+
346
+ private cameraHintText() {
347
+ if (this.theme.cameraHintTextColor ||
348
+ this.theme.cameraHintTextSize ||
349
+ this.theme.cameraHintTextFont) {
350
+ this.printQueue.push(() => {
351
+ this.root = this.root
352
+ .ele("item", { name: "personaCameraBodyTextAppearance" })
353
+ .txt("@style/RN.Persona.Text.CameraBody")
354
+ .up();
355
+ });
356
+
357
+ // Create a text appearance
358
+ this.postPrintQueue.push(() => {
359
+ this.root = this.root.ele("style", {
360
+ name: "RN.Persona.Text.CameraBody",
361
+ parent: "Persona.Text.CameraBody",
362
+ });
363
+
364
+ if (this.theme.cameraHintTextColor) {
365
+ this.root = this.root
366
+ .ele("item", { name: "android:textColor" })
367
+ .txt(this.theme.cameraHintTextColor as string)
368
+ .up();
369
+ }
370
+
371
+ if (this.theme.cameraHintTextFont) {
372
+ // TODO: Add notice about how to add a custom font that can be
373
+ // referenced here on Android
374
+ this.root = this.root
375
+ .ele("item", { name: "android:fontFamily" })
376
+ .txt(this.theme.cameraHintTextFont as string)
377
+ .up();
378
+ }
379
+
380
+ const textSize = this.theme.cameraHintTextSize ?
381
+ `${this.theme.cameraHintTextSize}sp` : "16sp";
382
+ this.root = this.root
383
+ .ele("item", { name: "android:textSize" })
384
+ .txt(textSize)
385
+ .up();
386
+
387
+ this.root = this.root.up();
388
+ });
389
+ } else {
390
+ this.printQueue.push(() => {
391
+ this.root = this.root
392
+ .ele("item", { name: "personaCameraBodyTextAppearance" })
393
+ .txt("@style/Persona.Text.CameraBody")
394
+ .up();
395
+ });
396
+ }
397
+ }
398
+
399
+ private cameraGuideHintText() {
400
+ if (this.theme.cameraGuideHintTextColor ||
401
+ this.theme.cameraGuideHintTextSize ||
402
+ this.theme.cameraGuideHintTextFont) {
403
+ this.printQueue.push(() => {
404
+ this.root = this.root
405
+ .ele("item", { name: "personaCameraHintTextAppearance" })
406
+ .txt("@style/RN.Persona.Text.CameraHint")
407
+ .up();
408
+ });
409
+
410
+ // Create a text appearance
411
+ this.postPrintQueue.push(() => {
412
+ this.root = this.root.ele("style", {
413
+ name: "RN.Persona.Text.CameraHint",
414
+ parent: "Persona.Text.CameraHint",
415
+ });
416
+
417
+ if (this.theme.cameraGuideHintTextColor) {
418
+ this.root = this.root
419
+ .ele("item", { name: "android:textColor" })
420
+ .txt(this.theme.cameraGuideHintTextColor as string)
421
+ .up();
422
+ }
423
+
424
+ if (this.theme.cameraGuideHintTextFont) {
425
+ // TODO: Add notice about how to add a custom font that can be
426
+ // referenced here on Android
427
+ this.root = this.root
428
+ .ele("item", { name: "android:fontFamily" })
429
+ .txt(this.theme.cameraGuideHintTextFont as string)
430
+ .up();
431
+ }
432
+
433
+ const textSize = this.theme.cameraGuideHintTextSize ?
434
+ `${this.theme.cameraGuideHintTextSize}sp` : "20sp";
435
+ this.root = this.root
436
+ .ele("item", { name: "android:textSize" })
437
+ .txt(textSize)
438
+ .up();
277
439
 
278
440
  this.root = this.root.up();
279
441
  });
442
+ } else {
443
+ this.printQueue.push(() => {
444
+ this.root = this.root
445
+ .ele("item", { name: "personaCameraHintTextAppearance" })
446
+ .txt("@style/Persona.Text.CameraHint")
447
+ .up();
448
+ });
280
449
  }
281
450
  }
451
+
282
452
  private textField() {
283
453
  if (this.theme.textFieldTextColor || this.theme.textFieldTextFont) {
284
454
  this.printQueue.push(() => {
@@ -411,15 +581,23 @@ class AndroidResourcePrinter {
411
581
  this.theme.buttonTextColor ||
412
582
  this.theme.buttonDisabledTextColor ||
413
583
  this.theme.buttonCornerRadius ||
414
- this.theme.buttonFont
584
+ this.theme.buttonFont ||
585
+ this.theme.buttonTextSize
415
586
  ) {
416
587
  this.printQueue.push(() => {
417
588
  this.root = this.root
418
589
  .ele("item", { name: "buttonStyle" })
419
590
  .txt("@style/RN.Persona.Button")
420
591
  .up();
592
+
593
+ this.root = this.root
594
+ .ele("item", { name: "buttonStyleSecondary" })
595
+ .txt("@style/RN.Persona.Button.Secondary")
596
+ .up();
421
597
  });
422
598
 
599
+ const textSize = this.theme.buttonTextSize ? `${this.theme.buttonTextSize}sp` : "18sp";
600
+
423
601
  this.postPrintQueue.push(() => {
424
602
  this.root = this.root
425
603
  .ele("style", {
@@ -445,7 +623,7 @@ class AndroidResourcePrinter {
445
623
  .ele("item", {
446
624
  name: "android:textSize",
447
625
  })
448
- .txt("18sp")
626
+ .txt(textSize)
449
627
  .up()
450
628
  .ele("item", {
451
629
  name: "android:background",
@@ -459,6 +637,19 @@ class AndroidResourcePrinter {
459
637
  .up()
460
638
  .up();
461
639
 
640
+ // Build RN.Persona.Button.Secondary
641
+ this.root = this.root
642
+ .ele("style", {
643
+ name: "RN.Persona.Button.Secondary",
644
+ parent: "RN.Persona.Button",
645
+ })
646
+ .ele("item", {
647
+ name: "android:background",
648
+ })
649
+ .txt("@drawable/rn_persona_button_secondary")
650
+ .up()
651
+ .up();
652
+
462
653
  // Disabled
463
654
  this.buttonDrawable = this.buttonDrawable
464
655
  .ele("item", {
@@ -564,6 +755,83 @@ class AndroidResourcePrinter {
564
755
 
565
756
  this.buttonColor = this.buttonColor.up();
566
757
 
758
+ // Disabled
759
+ this.buttonSecondaryDrawable = this.buttonSecondaryDrawable
760
+ .ele("item", {
761
+ "android:state_enabled": "false",
762
+ })
763
+ .ele("shape", { "android:shape": "rectangle" })
764
+ .ele("corners", {
765
+ "android:radius": this.theme.buttonCornerRadius
766
+ ? `${this.theme.buttonCornerRadius}dp`
767
+ : "@dimen/abc_control_corner_material",
768
+ })
769
+ .up()
770
+ .ele("padding", {
771
+ "android:left": "@dimen/abc_button_padding_horizontal_material",
772
+ "android:top": "@dimen/abc_button_padding_vertical_material",
773
+ "android:right": "@dimen/abc_button_padding_horizontal_material",
774
+ "android:bottom": "@dimen/abc_button_padding_vertical_material",
775
+ })
776
+ .up()
777
+ .ele("solid", {
778
+ "android:color": "@android:color/darker_gray",
779
+ })
780
+ .up()
781
+ .up()
782
+ .up();
783
+
784
+ // touched
785
+ this.buttonSecondaryDrawable = this.buttonSecondaryDrawable
786
+ .ele("item", {
787
+ "android:state_pressed": "true",
788
+ })
789
+ .ele("shape", { "android:shape": "rectangle" })
790
+ .ele("corners", {
791
+ "android:radius": this.theme.buttonCornerRadius
792
+ ? `${this.theme.buttonCornerRadius}dp`
793
+ : "@dimen/abc_control_corner_material",
794
+ })
795
+ .up()
796
+ .ele("solid", {
797
+ "android:color": "@color/grayButtonDark",
798
+ })
799
+ .up()
800
+ .ele("padding", {
801
+ "android:left": "@dimen/abc_button_padding_horizontal_material",
802
+ "android:top": "@dimen/abc_button_padding_vertical_material",
803
+ "android:right": "@dimen/abc_button_padding_horizontal_material",
804
+ "android:bottom": "@dimen/abc_button_padding_vertical_material",
805
+ })
806
+ .up()
807
+ .up()
808
+ .up();
809
+
810
+ this.buttonSecondaryDrawable = this.buttonSecondaryDrawable
811
+ .ele("item")
812
+ .ele("shape", { "android:shape": "rectangle" })
813
+ .ele("corners", {
814
+ "android:radius": this.theme.buttonCornerRadius
815
+ ? `${this.theme.buttonCornerRadius}dp`
816
+ : "@dimen/abc_control_corner_material",
817
+ })
818
+ .up()
819
+ .ele("solid", {
820
+ "android:color": "@color/grayButton",
821
+ })
822
+ .up()
823
+ .ele("padding", {
824
+ "android:left": "@dimen/abc_button_padding_horizontal_material",
825
+ "android:top": "@dimen/abc_button_padding_vertical_material",
826
+ "android:right": "@dimen/abc_button_padding_horizontal_material",
827
+ "android:bottom": "@dimen/abc_button_padding_vertical_material",
828
+ })
829
+ .up()
830
+ .up()
831
+ .up();
832
+
833
+ // Finish button drawable
834
+ this.buttonSecondaryDrawable = this.buttonSecondaryDrawable.up();
567
835
  this.root = this.root.up();
568
836
  });
569
837
  }
@@ -12,6 +12,7 @@ const AndroidResourcePrinter_1 = __importDefault(require("../lib/AndroidResource
12
12
  const config_1 = __importDefault(require("../config"));
13
13
  const ANDROID_STYLES_RESOURCE_PATH = "./android/app/src/main/res/values/styles_persona.xml";
14
14
  const ANDROID_BUTTON_DRAWABLE_RESOURCE_PATH = "./android/app/src/main/res/drawable/rn_persona_button.xml";
15
+ const ANDROID_BUTTON_SECONDARY_DRAWABLE_RESOURCE_PATH = "./android/app/src/main/res/drawable/rn_persona_button_secondary.xml";
15
16
  const ANDROID_BUTTON_COLOR_RESOURCE_PATH = "./android/app/src/main/res/color/rn_persona_button.xml";
16
17
  class ThemeGenerator {
17
18
  async run() {
@@ -24,11 +25,12 @@ class ThemeGenerator {
24
25
  console.log(`\n${chalk_1.default.yellow("Creating an Android Resource files for your project at:")}\n
25
26
  - ${ANDROID_STYLES_RESOURCE_PATH}
26
27
  - ${ANDROID_BUTTON_DRAWABLE_RESOURCE_PATH}
28
+ - ${ANDROID_BUTTON_SECONDARY_DRAWABLE_RESOURCE_PATH}
27
29
  - ${ANDROID_BUTTON_COLOR_RESOURCE_PATH}\n`);
28
30
  console.log("Building your application with this resource file themes your Persona Inquiry flow.\n");
29
31
  const config = await config_1.default.get();
30
32
  const theme = config["androidTheme"];
31
- const { style, buttonDrawable, buttonColor } = new AndroidResourcePrinter_1.default(theme).process();
33
+ const { style, buttonDrawable, buttonSecondaryDrawable, buttonColor } = new AndroidResourcePrinter_1.default(theme).process();
32
34
  let { isConfirmed: confirmed } = await prompts_1.confirmResourceFiles();
33
35
  if (!confirmed) {
34
36
  process.exit(1);
@@ -45,6 +47,8 @@ class ThemeGenerator {
45
47
  });
46
48
  fs_1.default.writeFileSync(ANDROID_BUTTON_DRAWABLE_RESOURCE_PATH, buttonDrawable.end({ prettyPrint: true }));
47
49
  console.log(`${chalk_1.default.green("Saved an Android drawable file at path:")} ${ANDROID_BUTTON_DRAWABLE_RESOURCE_PATH}.`);
50
+ fs_1.default.writeFileSync(ANDROID_BUTTON_SECONDARY_DRAWABLE_RESOURCE_PATH, buttonSecondaryDrawable.end({ prettyPrint: true }));
51
+ console.log(`${chalk_1.default.green("Saved an Android drawable file at path:")} ${ANDROID_BUTTON_SECONDARY_DRAWABLE_RESOURCE_PATH}.`);
48
52
  fs_1.default.mkdirSync(path_1.default.dirname(ANDROID_BUTTON_COLOR_RESOURCE_PATH), {
49
53
  recursive: true
50
54
  });
@@ -11,6 +11,8 @@ const ANDROID_STYLES_RESOURCE_PATH =
11
11
  "./android/app/src/main/res/values/styles_persona.xml";
12
12
  const ANDROID_BUTTON_DRAWABLE_RESOURCE_PATH =
13
13
  "./android/app/src/main/res/drawable/rn_persona_button.xml";
14
+ const ANDROID_BUTTON_SECONDARY_DRAWABLE_RESOURCE_PATH =
15
+ "./android/app/src/main/res/drawable/rn_persona_button_secondary.xml";
14
16
  const ANDROID_BUTTON_COLOR_RESOURCE_PATH =
15
17
  "./android/app/src/main/res/color/rn_persona_button.xml";
16
18
 
@@ -33,6 +35,7 @@ class ThemeGenerator {
33
35
  )}\n
34
36
  - ${ANDROID_STYLES_RESOURCE_PATH}
35
37
  - ${ANDROID_BUTTON_DRAWABLE_RESOURCE_PATH}
38
+ - ${ANDROID_BUTTON_SECONDARY_DRAWABLE_RESOURCE_PATH}
36
39
  - ${ANDROID_BUTTON_COLOR_RESOURCE_PATH}\n`
37
40
  );
38
41
  console.log(
@@ -42,9 +45,12 @@ class ThemeGenerator {
42
45
  const config = await Configuration.get();
43
46
  const theme = config["androidTheme"] as AndroidThemeObject;
44
47
 
45
- const { style, buttonDrawable, buttonColor } = new AndroidResourcePrinter(
46
- theme
47
- ).process();
48
+ const {
49
+ style,
50
+ buttonDrawable,
51
+ buttonSecondaryDrawable,
52
+ buttonColor
53
+ } = new AndroidResourcePrinter(theme).process();
48
54
 
49
55
  let { isConfirmed: confirmed } = await confirmResourceFiles();
50
56
 
@@ -82,6 +88,19 @@ class ThemeGenerator {
82
88
  )} ${ANDROID_BUTTON_DRAWABLE_RESOURCE_PATH}.`
83
89
  );
84
90
 
91
+ fs.mkdirSync(path.dirname(ANDROID_BUTTON_SECONDARY_DRAWABLE_RESOURCE_PATH), {
92
+ recursive: true
93
+ });
94
+ fs.writeFileSync(
95
+ ANDROID_BUTTON_SECONDARY_DRAWABLE_RESOURCE_PATH,
96
+ buttonSecondaryDrawable.end({ prettyPrint: true })
97
+ );
98
+ console.log(
99
+ `${chalk.green(
100
+ "Saved an Android drawable file at path:"
101
+ )} ${ANDROID_BUTTON_SECONDARY_DRAWABLE_RESOURCE_PATH}.`
102
+ );
103
+
85
104
  fs.mkdirSync(path.dirname(ANDROID_BUTTON_COLOR_RESOURCE_PATH), {
86
105
  recursive: true
87
106
  });