react-native-bootsplash 5.0.0-beta.2 → 5.0.0-beta.3

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.
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AACA,OAAO,EACL,UAAU,EACV,kBAAkB,EAGlB,SAAS,EAGV,MAAM,cAAc,CAAC;AAGtB,MAAM,MAAM,MAAM,GAAG;IACnB,IAAI,CAAC,EAAE,OAAO,CAAC;CAChB,CAAC;AAEF,MAAM,MAAM,QAAQ,GAAG;IACrB,UAAU,EAAE,MAAM,CAAC;IACnB,cAAc,CAAC,EAAE,MAAM,CAAC;IACxB,IAAI,EAAE;QACJ,KAAK,EAAE,MAAM,CAAC;QACd,MAAM,EAAE,MAAM,CAAC;KAChB,CAAC;IACF,KAAK,CAAC,EAAE;QACN,MAAM,EAAE,MAAM,CAAC;QACf,KAAK,EAAE,MAAM,CAAC;QACd,MAAM,EAAE,MAAM,CAAC;KAChB,CAAC;CACH,CAAC;AAEF,MAAM,MAAM,sBAAsB,GAAG;IACnC,QAAQ,EAAE,QAAQ,CAAC;IAEnB,IAAI,EAAE,kBAAkB,CAAC;IACzB,QAAQ,CAAC,EAAE,kBAAkB,CAAC;IAC9B,KAAK,CAAC,EAAE,kBAAkB,CAAC;IAC3B,SAAS,CAAC,EAAE,kBAAkB,CAAC;IAE/B,OAAO,EAAE,MAAM,IAAI,CAAC;IAEpB,oBAAoB,CAAC,EAAE,OAAO,CAAC;IAC/B,wBAAwB,CAAC,EAAE,OAAO,CAAC;CACpC,CAAC;AAEF,MAAM,MAAM,gBAAgB,GAAG;IAC7B,SAAS,EAAE,SAAS,CAAC;IACrB,IAAI,EAAE,UAAU,CAAC;IACjB,KAAK,CAAC,EAAE,UAAU,CAAC;CACpB,CAAC;AAEF,wBAAgB,IAAI,CAAC,MAAM,GAAE,MAAW,GAAG,OAAO,CAAC,IAAI,C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BAAgB,SAAS,IAAI,OAAO,CAAC,OAAO,CAAC,CAE5C;AAED,wBAAgB,gBAAgB,CAAC,MAAM,EAAE,sBAAsB,oBAmJ9D;;;;;;AAED,wBAIE"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "react-native-bootsplash",
3
- "version": "5.0.0-beta.2",
3
+ "version": "5.0.0-beta.3",
4
4
  "license": "MIT",
5
5
  "description": "Display a bootsplash on your app starts. Hide it when you want.",
6
6
  "author": "Mathieu Acthernoene <zoontek@gmail.com>",
@@ -64,9 +64,11 @@
64
64
  "react-native": ">=0.70.0"
65
65
  },
66
66
  "dependencies": {
67
+ "detect-indent": "^6.1.0",
67
68
  "fs-extra": "^11.1.1",
68
69
  "picocolors": "^1.0.0",
69
- "sharp": "^0.32.4"
70
+ "sharp": "^0.32.4",
71
+ "xml-formatter": "^3.5.0"
70
72
  },
71
73
  "devDependencies": {
72
74
  "@babel/core": "^7.20.0",
package/src/generate.ts CHANGED
@@ -3,26 +3,24 @@ import {
3
3
  CommandFunction,
4
4
  IOSProjectConfig,
5
5
  } from "@react-native-community/cli-types";
6
+ import detectIndent from "detect-indent";
6
7
  import fs from "fs-extra";
7
8
  import path from "path";
8
9
  import pc from "picocolors";
9
10
  import type { Sharp } from "sharp";
10
11
  import sharp from "sharp";
12
+ import xmlFormat, { XMLFormatterOptions } from "xml-formatter";
11
13
  import type { Manifest } from ".";
12
14
 
13
- export type Color = {
14
- hex: string;
15
- rgb: {
16
- R: string;
17
- G: string;
18
- B: string;
19
- };
20
- };
15
+ const workingPath = process.env.INIT_CWD ?? process.env.PWD ?? process.cwd();
21
16
 
22
17
  export const androidColorRegex =
23
18
  /<color name="bootsplash_background">#\w+<\/color>/g;
24
19
 
25
- const workingPath = process.env.INIT_CWD ?? process.env.PWD ?? process.cwd();
20
+ export type Color = {
21
+ hex: string;
22
+ rgb: { R: string; G: string; B: string };
23
+ };
26
24
 
27
25
  const parseColor = (value: string): Color => {
28
26
  const up = value.toUpperCase().replace(/[^0-9A-F]/g, "");
@@ -42,31 +40,6 @@ const parseColor = (value: string): Color => {
42
40
  return { hex, rgb };
43
41
  };
44
42
 
45
- const ContentsJson = `{
46
- "images": [
47
- {
48
- "idiom": "universal",
49
- "filename": "bootsplash_logo.png",
50
- "scale": "1x"
51
- },
52
- {
53
- "idiom": "universal",
54
- "filename": "bootsplash_logo@2x.png",
55
- "scale": "2x"
56
- },
57
- {
58
- "idiom": "universal",
59
- "filename": "bootsplash_logo@3x.png",
60
- "scale": "3x"
61
- }
62
- ],
63
- "info": {
64
- "author": "xcode",
65
- "version": 1
66
- }
67
- }
68
- `;
69
-
70
43
  const getStoryboard = ({
71
44
  logoHeight,
72
45
  logoWidth,
@@ -143,6 +116,38 @@ export const logWrite = (
143
116
  (dimensions != null ? ` (${dimensions.width}x${dimensions.height})` : ""),
144
117
  );
145
118
 
119
+ export const writeJson = (file: string, json: object) => {
120
+ const amount = fs.existsSync(file)
121
+ ? detectIndent(fs.readFileSync(file, "utf-8")).amount || 2
122
+ : 2;
123
+
124
+ fs.writeFileSync(file, JSON.stringify(json, null, amount) + "\n", "utf-8");
125
+ logWrite(file);
126
+ };
127
+
128
+ export const writeXml = (
129
+ file: string,
130
+ xml: string,
131
+ options?: XMLFormatterOptions,
132
+ ) => {
133
+ const indentation = fs.existsSync(file)
134
+ ? detectIndent(fs.readFileSync(file, "utf-8")).indent || " "
135
+ : " ";
136
+
137
+ fs.writeFileSync(
138
+ file,
139
+ xmlFormat(xml, {
140
+ collapseContent: true,
141
+ ...options,
142
+ indentation,
143
+ lineSeparator: "\n",
144
+ }) + "\n",
145
+ "utf-8",
146
+ );
147
+
148
+ logWrite(file);
149
+ };
150
+
146
151
  const ensureSupportedFormat = async (
147
152
  name: string,
148
153
  image: Sharp | undefined,
@@ -410,32 +415,15 @@ export const generate: CommandFunction<{
410
415
  if (fs.existsSync(colorsXmlPath)) {
411
416
  const colorsXml = fs.readFileSync(colorsXmlPath, "utf-8");
412
417
 
413
- if (colorsXml.match(androidColorRegex)) {
414
- fs.writeFileSync(
415
- colorsXmlPath,
416
- colorsXml.replace(androidColorRegex, colorsXmlEntry),
417
- "utf-8",
418
- );
419
- } else {
420
- fs.writeFileSync(
421
- colorsXmlPath,
422
- colorsXml.replace(
423
- /<\/resources>/g,
424
- ` ${colorsXmlEntry}\n</resources>`,
425
- ),
426
- "utf-8",
427
- );
428
- }
418
+ const nextXml = colorsXml.match(androidColorRegex)
419
+ ? colorsXml.replace(androidColorRegex, colorsXmlEntry)
420
+ : colorsXml.replace(/<\/resources>/g, `${colorsXmlEntry}</resources>`);
421
+
422
+ writeXml(colorsXmlPath, nextXml);
429
423
  } else {
430
- fs.writeFileSync(
431
- colorsXmlPath,
432
- `<resources>\n ${colorsXmlEntry}\n</resources>\n`,
433
- "utf-8",
434
- );
424
+ writeXml(colorsXmlPath, `<resources>${colorsXmlEntry}</resources>`);
435
425
  }
436
426
 
437
- logWrite(colorsXmlPath);
438
-
439
427
  await Promise.all(
440
428
  [
441
429
  { ratio: 1, suffix: "mdpi" },
@@ -519,11 +507,29 @@ export const generate: CommandFunction<{
519
507
 
520
508
  fs.ensureDirSync(imageSetPath);
521
509
 
522
- fs.writeFileSync(
523
- path.resolve(imageSetPath, "Contents.json"),
524
- ContentsJson,
525
- "utf-8",
526
- );
510
+ writeJson(path.resolve(imageSetPath, "Contents.json"), {
511
+ images: [
512
+ {
513
+ idiom: "universal",
514
+ filename: "bootsplash_logo.png",
515
+ scale: "1x",
516
+ },
517
+ {
518
+ idiom: "universal",
519
+ filename: "bootsplash_logo@2x.png",
520
+ scale: "2x",
521
+ },
522
+ {
523
+ idiom: "universal",
524
+ filename: "bootsplash_logo@3x.png",
525
+ scale: "3x",
526
+ },
527
+ ],
528
+ info: {
529
+ author: "xcode",
530
+ version: 1,
531
+ },
532
+ });
527
533
 
528
534
  await Promise.all(
529
535
  [
@@ -553,26 +559,13 @@ export const generate: CommandFunction<{
553
559
 
554
560
  fs.ensureDirSync(assetsOutputPath);
555
561
 
556
- const manifest: Manifest = {
562
+ writeJson(path.resolve(assetsOutputPath, "bootsplash_manifest.json"), {
557
563
  background: background.hex,
558
564
  logo: {
559
565
  width: logoWidth,
560
566
  height: logoHeight,
561
567
  },
562
- };
563
-
564
- const manifestPath = path.resolve(
565
- assetsOutputPath,
566
- "bootsplash_manifest.json",
567
- );
568
-
569
- fs.writeFileSync(
570
- manifestPath,
571
- JSON.stringify(manifest, null, 2) + "\n",
572
- "utf-8",
573
- );
574
-
575
- logWrite(manifestPath);
568
+ } satisfies Manifest);
576
569
 
577
570
  await Promise.all(
578
571
  [
package/src/index.ts CHANGED
@@ -22,7 +22,6 @@ export type Manifest = {
22
22
  height: number;
23
23
  };
24
24
  brand?: {
25
- bottom: number;
26
25
  width: number;
27
26
  height: number;
28
27
  };
@@ -75,7 +74,6 @@ export function useHideAnimation(config: UseHideAnimationConfig) {
75
74
  const hasBrand = manifest.brand != null && brandSrc != null;
76
75
  const logoWidth = manifest.logo.width;
77
76
  const logoHeight = manifest.logo.height;
78
- const brandBottom = manifest.brand?.bottom;
79
77
  const brandWidth = manifest.brand?.width;
80
78
  const brandHeight = manifest.brand?.height;
81
79
 
@@ -158,7 +156,7 @@ export function useHideAnimation(config: UseHideAnimationConfig) {
158
156
  source: brandFinalSrc,
159
157
  style: {
160
158
  position: "absolute",
161
- bottom: brandBottom,
159
+ bottom: 60,
162
160
  width: brandWidth,
163
161
  height: brandHeight,
164
162
  },
@@ -195,7 +193,6 @@ export function useHideAnimation(config: UseHideAnimationConfig) {
195
193
 
196
194
  logoWidth,
197
195
  logoHeight,
198
- brandBottom,
199
196
  brandWidth,
200
197
  brandHeight,
201
198