uilib-native 4.1.3 → 4.3.2

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.
Files changed (81) hide show
  1. package/.vscode/settings.json +22 -0
  2. package/android/build/outputs/logs/manifest-merger-debug-report.txt +4 -4
  3. package/android/build.gradle +1 -0
  4. package/android/src/main/AndroidManifest.xml +1 -2
  5. package/components/DynamicFonts/FontDownloader.d.ts +41 -0
  6. package/components/DynamicFonts/{FontDownloader.ts → FontDownloader.js} +33 -67
  7. package/components/DynamicFonts/FontLoader.d.ts +35 -0
  8. package/components/DynamicFonts/{FontLoader.ts → FontLoader.js} +20 -54
  9. package/components/DynamicFonts/NoPermissionsAcquirer.d.ts +3 -0
  10. package/components/DynamicFonts/{NoPermissionsAcquirer.ts → NoPermissionsAcquirer.js} +2 -2
  11. package/components/DynamicFonts/PermissionsAcquirer.android.d.ts +13 -0
  12. package/components/DynamicFonts/{PermissionsAcquirer.android.ts → PermissionsAcquirer.android.js} +8 -24
  13. package/components/DynamicFonts/PermissionsAcquirer.ios.js +2 -0
  14. package/components/DynamicFonts/{PermissionsAcquirer.ios.ts → PermissionsAcquirer.web.d.ts} +0 -1
  15. package/components/DynamicFonts/PermissionsAcquirer.web.js +2 -0
  16. package/components/DynamicFonts/RNFSPackage.d.ts +2 -0
  17. package/components/DynamicFonts/RNFSPackage.js +5 -0
  18. package/components/DynamicFonts/index.d.ts +61 -0
  19. package/components/DynamicFonts/index.js +154 -0
  20. package/components/HighlighterOverlayView.d.ts +34 -0
  21. package/components/HighlighterOverlayView.js +40 -0
  22. package/components/HighlighterOverlayView.web.js +15 -0
  23. package/components/Keyboard/KeyboardInput/CustomKeyboardView/CustomKeyboardView.android.d.ts +7 -0
  24. package/components/Keyboard/KeyboardInput/CustomKeyboardView/CustomKeyboardView.android.js +28 -0
  25. package/components/Keyboard/KeyboardInput/CustomKeyboardView/CustomKeyboardView.ios.d.ts +19 -0
  26. package/components/Keyboard/KeyboardInput/CustomKeyboardView/{CustomKeyboardView.ios.tsx → CustomKeyboardView.ios.js} +25 -33
  27. package/components/Keyboard/KeyboardInput/CustomKeyboardView/index.d.ts +4 -0
  28. package/components/Keyboard/KeyboardInput/CustomKeyboardView/index.js +10 -0
  29. package/components/Keyboard/KeyboardInput/CustomKeyboardView/{index.web.tsx → index.web.js} +2 -7
  30. package/components/Keyboard/KeyboardInput/CustomKeyboardViewBase.d.ts +24 -0
  31. package/components/Keyboard/KeyboardInput/CustomKeyboardViewBase.js +67 -0
  32. package/components/Keyboard/KeyboardInput/KeyboardAccessoryView.d.ts +74 -0
  33. package/components/Keyboard/KeyboardInput/{KeyboardAccessoryView.tsx → KeyboardAccessoryView.js} +24 -104
  34. package/components/Keyboard/KeyboardInput/KeyboardRegistry.d.ts +71 -0
  35. package/components/Keyboard/KeyboardInput/{KeyboardRegistry.ts → KeyboardRegistry.js} +28 -19
  36. package/components/Keyboard/KeyboardInput/TextInputKeyboardManager/TextInputKeyboardManager.android.d.ts +4 -0
  37. package/components/Keyboard/KeyboardInput/TextInputKeyboardManager/{TextInputKeyboardManager.android.ts → TextInputKeyboardManager.android.js} +2 -5
  38. package/components/Keyboard/KeyboardInput/TextInputKeyboardManager/TextInputKeyboardManager.ios.d.ts +10 -0
  39. package/components/Keyboard/KeyboardInput/TextInputKeyboardManager/{TextInputKeyboardManager.ios.ts → TextInputKeyboardManager.ios.js} +15 -15
  40. package/components/Keyboard/KeyboardInput/TextInputKeyboardManager/index.d.ts +4 -0
  41. package/components/Keyboard/KeyboardInput/TextInputKeyboardManager/index.js +6 -0
  42. package/components/Keyboard/KeyboardInput/utils/EventEmitterManager.d.ts +10 -0
  43. package/components/Keyboard/KeyboardInput/utils/{EventEmitterManager.ts → EventEmitterManager.js} +8 -14
  44. package/components/Keyboard/KeyboardInput/utils/KeyboardUtils.d.ts +11 -0
  45. package/components/Keyboard/KeyboardInput/utils/{KeyboardUtils.ts → KeyboardUtils.js} +3 -3
  46. package/components/Keyboard/KeyboardTracking/KeyboardAwareInsetsView.d.ts +16 -0
  47. package/components/Keyboard/KeyboardTracking/{KeyboardAwareInsetsView.tsx → KeyboardAwareInsetsView.js} +12 -10
  48. package/components/Keyboard/KeyboardTracking/KeyboardTrackingView/KeyboardTrackingView.android.d.ts +12 -0
  49. package/components/Keyboard/KeyboardTracking/KeyboardTrackingView/KeyboardTrackingView.android.js +17 -0
  50. package/components/Keyboard/KeyboardTracking/KeyboardTrackingView/KeyboardTrackingView.ios.d.ts +24 -0
  51. package/components/Keyboard/KeyboardTracking/KeyboardTrackingView/{KeyboardTrackingView.ios.tsx → KeyboardTrackingView.ios.js} +5 -14
  52. package/components/Keyboard/KeyboardTracking/KeyboardTrackingView/index.d.ts +81 -0
  53. package/components/Keyboard/KeyboardTracking/KeyboardTrackingView/index.js +22 -0
  54. package/components/Keyboard/KeyboardTracking/KeyboardTrackingView/{index.web.tsx → index.web.js} +2 -6
  55. package/components/Keyboard/KeyboardTracking/keyboardAwareInsetsView.api.json +1 -1
  56. package/components/Keyboard/index.d.ts +40 -0
  57. package/components/Keyboard/index.js +13 -0
  58. package/components/SafeArea/SafeAreaInsetsManager.d.ts +20 -0
  59. package/components/SafeArea/{SafeAreaInsetsManager.ts → SafeAreaInsetsManager.js} +23 -26
  60. package/components/SafeArea/SafeAreaSpacerView.d.ts +10 -0
  61. package/components/SafeArea/SafeAreaSpacerView.js +14 -0
  62. package/components/SafeArea/SafeAreaSpacerView.web.d.ts +10 -0
  63. package/components/SafeArea/SafeAreaSpacerView.web.js +9 -0
  64. package/components/index.d.ts +6 -0
  65. package/components/index.js +6 -0
  66. package/package.json +1 -1
  67. package/components/DynamicFonts/RNFSPackage.ts +0 -6
  68. package/components/DynamicFonts/index.ts +0 -194
  69. package/components/HighlighterOverlayView.tsx +0 -90
  70. package/components/HighlighterOverlayView.web.tsx +0 -58
  71. package/components/Keyboard/KeyboardInput/CustomKeyboardView/CustomKeyboardView.android.tsx +0 -31
  72. package/components/Keyboard/KeyboardInput/CustomKeyboardView/index.tsx +0 -16
  73. package/components/Keyboard/KeyboardInput/CustomKeyboardViewBase.tsx +0 -83
  74. package/components/Keyboard/KeyboardInput/TextInputKeyboardManager/index.ts +0 -9
  75. package/components/Keyboard/KeyboardTracking/KeyboardTrackingView/KeyboardTrackingView.android.tsx +0 -15
  76. package/components/Keyboard/KeyboardTracking/KeyboardTrackingView/index.tsx +0 -96
  77. package/components/Keyboard/index.ts +0 -15
  78. package/components/SafeArea/SafeAreaSpacerView.tsx +0 -19
  79. package/components/SafeArea/SafeAreaSpacerView.web.tsx +0 -14
  80. package/components/index.ts +0 -16
  81. /package/components/DynamicFonts/{PermissionsAcquirer.web.ts → PermissionsAcquirer.ios.d.ts} +0 -0
@@ -0,0 +1,22 @@
1
+ {
2
+ "workbench.colorCustomizations": {
3
+ "activityBar.activeBackground": "#2f8c2f",
4
+ "activityBar.background": "#2f8c2f",
5
+ "activityBar.foreground": "#e7e7e7",
6
+ "activityBar.inactiveForeground": "#e7e7e799",
7
+ "activityBarBadge.background": "#3838a7",
8
+ "activityBarBadge.foreground": "#e7e7e7",
9
+ "commandCenter.border": "#e7e7e799",
10
+ "sash.hoverBorder": "#2f8c2f",
11
+ "statusBar.background": "#226622",
12
+ "statusBar.foreground": "#e7e7e7",
13
+ "statusBarItem.hoverBackground": "#2f8c2f",
14
+ "statusBarItem.remoteBackground": "#226622",
15
+ "statusBarItem.remoteForeground": "#e7e7e7",
16
+ "tab.activeBorder": "#2f8c2f",
17
+ "titleBar.activeBackground": "#226622",
18
+ "titleBar.activeForeground": "#e7e7e7",
19
+ "titleBar.inactiveBackground": "#22662299",
20
+ "titleBar.inactiveForeground": "#e7e7e799"
21
+ }
22
+ }
@@ -1,11 +1,11 @@
1
1
  -- Merging decision tree log ---
2
2
  manifest
3
- ADDED from /Users/michaelle/Dev/public-ui-lib/lib/android/src/main/AndroidManifest.xml:2:1-5:12
4
- INJECTED from /Users/michaelle/Dev/public-ui-lib/lib/android/src/main/AndroidManifest.xml:2:1-5:12
5
- INJECTED from /Users/michaelle/Dev/public-ui-lib/lib/android/src/main/AndroidManifest.xml:2:1-5:12
3
+ ADDED from /Users/michaelle/Dev/public-ui-lib/lib/android/src/main/AndroidManifest.xml:2:1-4:12
4
+ INJECTED from /Users/michaelle/Dev/public-ui-lib/lib/android/src/main/AndroidManifest.xml:2:1-4:12
5
+ INJECTED from /Users/michaelle/Dev/public-ui-lib/lib/android/src/main/AndroidManifest.xml:2:1-4:12
6
6
  package
7
- ADDED from /Users/michaelle/Dev/public-ui-lib/lib/android/src/main/AndroidManifest.xml:4:5-39
8
7
  INJECTED from /Users/michaelle/Dev/public-ui-lib/lib/android/src/main/AndroidManifest.xml
8
+ ADDED from /Users/michaelle/Dev/public-ui-lib/lib/android/src/main/AndroidManifest.xml:2:1-4:12
9
9
  INJECTED from /Users/michaelle/Dev/public-ui-lib/lib/android/src/main/AndroidManifest.xml
10
10
  xmlns:android
11
11
  ADDED from /Users/michaelle/Dev/public-ui-lib/lib/android/src/main/AndroidManifest.xml:3:5-63
@@ -9,6 +9,7 @@ project.ext {
9
9
  }
10
10
 
11
11
  android {
12
+ namespace "com.wix.reactnativeuilib"
12
13
  compileSdkVersion project.ext.compileSdkVersion
13
14
  buildToolsVersion project.ext.buildToolsVersion
14
15
 
@@ -1,5 +1,4 @@
1
1
  <?xml version="1.0" encoding="utf-8"?>
2
2
  <manifest
3
- xmlns:android="http://schemas.android.com/apk/res/android"
4
- package="com.wix.reactnativeuilib">
3
+ xmlns:android="http://schemas.android.com/apk/res/android">
5
4
  </manifest>
@@ -0,0 +1,41 @@
1
+ import { FontExtension } from './FontLoader';
2
+ export type FontDownloaderProps = {
3
+ /**
4
+ * Should be In the following convention: '/NAME'
5
+ */
6
+ dynamicFontsFolder?: string;
7
+ downloadErrorMessage?: string;
8
+ /**
9
+ * Enable debug mode to print extra logs
10
+ */
11
+ debug?: boolean;
12
+ };
13
+ export default class FontDownloader {
14
+ private readonly props;
15
+ private readonly fs;
16
+ constructor(props: FontDownloaderProps);
17
+ private log;
18
+ private getPrivateFolder;
19
+ private getPrivateFilePath;
20
+ private getFileName;
21
+ private _isFontDownloaded;
22
+ private createPrivateFolderIfNeeded;
23
+ private getDownloadFontOptions;
24
+ /**
25
+ * Download the font
26
+ * @param fontUri the remote location of the font
27
+ * @param fontName the full name of the font
28
+ * @param fontExtension the extension of the font, i.e. '.ttf' or '.otf'
29
+ * @param timeout a timeout for the download to fail after
30
+ * @returns the full path of the download
31
+ */
32
+ downloadFont(fontUri: string, fontName: string, fontExtension: FontExtension, timeout: number): Promise<string>;
33
+ /**
34
+ * Is the font cached (already downloaded)
35
+ * @param {*} fontName the full name of the font
36
+ * @param {*} fontExtension the extension of the font, i.e. '.ttf' or '.otf'
37
+ */
38
+ isFontDownloaded(fontName: string, fontExtension: FontExtension): Promise<boolean>;
39
+ readFontFromDisk(fontName: string, fontExtension: FontExtension): Promise<string | void>;
40
+ deleteFontFromDisk(fontFullName: string): Promise<void>;
41
+ }
@@ -1,86 +1,58 @@
1
- import {Platform} from 'react-native';
2
- import RNFS from './RNFSPackage';
3
- import {FontExtension} from './FontLoader';
4
-
1
+ import { Platform } from 'react-native';
2
+ import RNFS from "./RNFSPackage";
5
3
  const DEFAULT_DYNAMIC_FONTS_FOLDER = '/dynamicFonts';
6
4
  const DEFAULT_DOWNLOAD_ERROR_MESSAGE = 'An error occurred downloading the file:';
7
-
8
- export type FontDownloaderProps = {
9
- /**
10
- * Should be In the following convention: '/NAME'
11
- */
12
- dynamicFontsFolder?: string;
13
- downloadErrorMessage?: string;
14
- /**
15
- * Enable debug mode to print extra logs
16
- */
17
- debug?: boolean;
18
- };
19
-
20
5
  // TODO: this can probably be a more general "downloader" if we so choose
21
6
  export default class FontDownloader {
22
- private readonly props: FontDownloaderProps;
23
- private readonly fs: NonNullable<typeof RNFS>;
24
-
25
- constructor(props: FontDownloaderProps) {
7
+ constructor(props) {
26
8
  this.props = {
27
9
  dynamicFontsFolder: DEFAULT_DYNAMIC_FONTS_FOLDER,
28
10
  downloadErrorMessage: DEFAULT_DOWNLOAD_ERROR_MESSAGE,
29
11
  ...props
30
12
  };
31
-
32
13
  if (!RNFS) {
33
14
  throw new Error(`RNUILib FontDownloader requires installing "react-native-fs" dependency`);
34
15
  }
35
16
  this.fs = RNFS;
36
17
  }
37
-
38
- private log(message?: any, ...optionalParams: any[]) {
39
- const {debug} = this.props;
18
+ log(message, ...optionalParams) {
19
+ const {
20
+ debug
21
+ } = this.props;
40
22
  if (debug) {
41
23
  console.log(message, optionalParams);
42
24
  }
43
25
  }
44
-
45
- private getPrivateFolder() {
46
- const {dynamicFontsFolder} = this.props;
47
- return (
48
- (Platform.OS === 'android' ? this.fs.ExternalDirectoryPath : this.fs.DocumentDirectoryPath) + dynamicFontsFolder
49
- );
26
+ getPrivateFolder() {
27
+ const {
28
+ dynamicFontsFolder
29
+ } = this.props;
30
+ return (Platform.OS === 'android' ? this.fs.ExternalDirectoryPath : this.fs.DocumentDirectoryPath) + dynamicFontsFolder;
50
31
  }
51
-
52
- private getPrivateFilePath(fileName: string) {
32
+ getPrivateFilePath(fileName) {
53
33
  return this.getPrivateFolder() + '/' + fileName;
54
34
  }
55
-
56
- private getFileName(fontName: string, fontExtension: FontExtension) {
35
+ getFileName(fontName, fontExtension) {
57
36
  return fontName + '.' + fontExtension;
58
37
  }
59
-
60
- private async _isFontDownloaded(fileName: string) {
38
+ async _isFontDownloaded(fileName) {
61
39
  const privateFilePath = this.getPrivateFilePath(fileName);
62
40
  return await this.fs.exists(privateFilePath);
63
41
  }
64
-
65
- private async createPrivateFolderIfNeeded() {
42
+ async createPrivateFolderIfNeeded() {
66
43
  const privateFolder = this.getPrivateFolder();
67
44
  if (!(await this.fs.exists(privateFolder))) {
68
45
  await this.fs.mkdir(privateFolder);
69
46
  }
70
47
  }
71
-
72
- private getDownloadFontOptions(fontUri: string, downloadLocation: string, readTimeout: number) {
73
- const platformSpecificOptions =
74
- Platform.OS === 'ios'
75
- ? {
76
- background: false,
77
- discretionary: true,
78
- cacheable: false
79
- }
80
- : {
81
- connectionTimeout: readTimeout
82
- };
83
-
48
+ getDownloadFontOptions(fontUri, downloadLocation, readTimeout) {
49
+ const platformSpecificOptions = Platform.OS === 'ios' ? {
50
+ background: false,
51
+ discretionary: true,
52
+ cacheable: false
53
+ } : {
54
+ connectionTimeout: readTimeout
55
+ };
84
56
  return {
85
57
  fromUrl: fontUri,
86
58
  toFile: downloadLocation,
@@ -100,19 +72,16 @@ export default class FontDownloader {
100
72
  * @param timeout a timeout for the download to fail after
101
73
  * @returns the full path of the download
102
74
  */
103
- public async downloadFont(fontUri: string,
104
- fontName: string,
105
- fontExtension: FontExtension,
106
- timeout: number): Promise<string> {
107
- const {downloadErrorMessage} = this.props;
75
+ async downloadFont(fontUri, fontName, fontExtension, timeout) {
76
+ const {
77
+ downloadErrorMessage
78
+ } = this.props;
108
79
  await this.createPrivateFolderIfNeeded();
109
80
  const fileName = this.getFileName(fontName, fontExtension);
110
81
  const downloadLocation = this.getPrivateFilePath(fileName);
111
-
112
82
  try {
113
83
  this.log(fontName, 'Starting to download');
114
- const result = await this.fs.downloadFile(this.getDownloadFontOptions(fontUri, downloadLocation, timeout))
115
- .promise;
84
+ const result = await this.fs.downloadFile(this.getDownloadFontOptions(fontUri, downloadLocation, timeout)).promise;
116
85
  if (result.statusCode === 200) {
117
86
  this.log(fontName, 'Finished downloading');
118
87
  return downloadLocation;
@@ -137,12 +106,11 @@ export default class FontDownloader {
137
106
  * @param {*} fontName the full name of the font
138
107
  * @param {*} fontExtension the extension of the font, i.e. '.ttf' or '.otf'
139
108
  */
140
- public async isFontDownloaded(fontName: string, fontExtension: FontExtension): Promise<boolean> {
109
+ async isFontDownloaded(fontName, fontExtension) {
141
110
  const fileName = this.getFileName(fontName, fontExtension);
142
111
  return await this._isFontDownloaded(fileName);
143
112
  }
144
-
145
- public async readFontFromDisk(fontName: string, fontExtension: FontExtension): Promise<string | void> {
113
+ async readFontFromDisk(fontName, fontExtension) {
146
114
  let base64FontString;
147
115
  const fileName = this.getFileName(fontName, fontExtension);
148
116
  const privateFilePath = this.getPrivateFilePath(fileName);
@@ -155,11 +123,9 @@ export default class FontDownloader {
155
123
  } else {
156
124
  this.log(fontName, 'File does not exist (read)');
157
125
  }
158
-
159
126
  return base64FontString;
160
127
  }
161
-
162
- public async deleteFontFromDisk(fontFullName: string): Promise<void> {
128
+ async deleteFontFromDisk(fontFullName) {
163
129
  const privateFilePath = this.getPrivateFilePath(fontFullName);
164
130
  if (await this.fs.exists(privateFilePath)) {
165
131
  this.log(fontFullName, 'Starting to delete');
@@ -171,4 +137,4 @@ export default class FontDownloader {
171
137
  this.log(fontFullName, 'File does not exist (delete)');
172
138
  }
173
139
  }
174
- }
140
+ }
@@ -0,0 +1,35 @@
1
+ export type FontExtension = 'ttf' | 'otf';
2
+ export type LoadFontInput = {
3
+ /**
4
+ * Specify registered font name (doesn't work for iOS)
5
+ */
6
+ fontName: string;
7
+ /**
8
+ * This can be a data URI or raw base64...
9
+ * if it is raw base64 type must be specified,
10
+ * but defaults to TTF (data URI mime: font/ttf or font/otf)
11
+ */
12
+ base64FontString: string;
13
+ /**
14
+ * Specify the type of font in the encoded data (ttf or otf). Defaults to "ttf"
15
+ */
16
+ fontExtension: FontExtension;
17
+ /**
18
+ * Force the loading of the font even if previously loaded it
19
+ */
20
+ forceLoad?: boolean;
21
+ };
22
+ export type FontLoaderProps = {
23
+ /**
24
+ * Enable debug mode to print extra logs
25
+ */
26
+ debug?: boolean;
27
+ };
28
+ export default class FontLoader {
29
+ private readonly props;
30
+ private readonly loadedFonts;
31
+ constructor(props: FontLoaderProps);
32
+ private log;
33
+ loadFont: ({ fontName, base64FontString, fontExtension, forceLoad }: LoadFontInput) => Promise<string>;
34
+ loadFonts: (fonts: LoadFontInput | LoadFontInput[], forceLoad?: boolean) => Promise<string[]>;
35
+ }
@@ -1,72 +1,37 @@
1
- import {NativeModules} from 'react-native';
2
-
3
- const {DynamicFont} = NativeModules;
4
-
5
- export type FontExtension = 'ttf' | 'otf';
6
-
7
- export type LoadFontInput = {
8
- /**
9
- * Specify registered font name (doesn't work for iOS)
10
- */
11
- fontName: string;
12
- /**
13
- * This can be a data URI or raw base64...
14
- * if it is raw base64 type must be specified,
15
- * but defaults to TTF (data URI mime: font/ttf or font/otf)
16
- */
17
- base64FontString: string;
18
- /**
19
- * Specify the type of font in the encoded data (ttf or otf). Defaults to "ttf"
20
- */
21
- fontExtension: FontExtension;
22
- /**
23
- * Force the loading of the font even if previously loaded it
24
- */
25
- forceLoad?: boolean;
26
- };
27
-
28
- export type FontLoaderProps = {
29
- /**
30
- * Enable debug mode to print extra logs
31
- */
32
- debug?: boolean;
33
- };
34
-
1
+ import { NativeModules } from 'react-native';
2
+ const {
3
+ DynamicFont
4
+ } = NativeModules;
35
5
  export default class FontLoader {
36
- private readonly props: FontLoaderProps;
37
- private readonly loadedFonts = new Map<string, string>();
38
-
39
- constructor(props: FontLoaderProps) {
6
+ loadedFonts = new Map();
7
+ constructor(props) {
40
8
  this.props = props;
41
9
  }
42
-
43
- private log(message?: any, ...optionalParams: any[]) {
44
- const {debug} = this.props;
10
+ log(message, ...optionalParams) {
11
+ const {
12
+ debug
13
+ } = this.props;
45
14
  if (debug) {
46
15
  console.log(message, optionalParams);
47
16
  }
48
17
  }
49
-
50
- public loadFont = ({
18
+ loadFont = ({
51
19
  fontName,
52
20
  base64FontString,
53
21
  fontExtension = 'ttf',
54
22
  forceLoad = false
55
- }: LoadFontInput): Promise<string> => {
23
+ }) => {
56
24
  /* Check if this font was already loaded */
57
25
  if (!forceLoad && this.loadedFonts.has(fontName)) {
58
26
  this.log(fontName, 'Already loaded');
59
- return Promise.resolve(this.loadedFonts.get(fontName) as string);
27
+ return Promise.resolve(this.loadedFonts.get(fontName));
60
28
  }
61
-
62
29
  if (!fontName) {
63
30
  throw new Error('fontName is a required argument');
64
31
  }
65
-
66
32
  if (!base64FontString) {
67
33
  throw new Error('base64FontString is a required argument');
68
34
  }
69
-
70
35
  this.log(fontName, 'Starting to load');
71
36
  /* Load font via native binary code */
72
37
  return new Promise((resolve, reject) => {
@@ -74,8 +39,7 @@ export default class FontLoader {
74
39
  name: fontName,
75
40
  data: base64FontString,
76
41
  type: fontExtension
77
- },
78
- (err: string, givenName: string) => {
42
+ }, (err, givenName) => {
79
43
  if (err) {
80
44
  reject(err);
81
45
  return;
@@ -112,12 +76,14 @@ export default class FontLoader {
112
76
  // });
113
77
  // };
114
78
 
115
- public loadFonts = (fonts: LoadFontInput | LoadFontInput[], forceLoad?: boolean) => {
79
+ loadFonts = (fonts, forceLoad) => {
116
80
  if (!fonts) {
117
81
  return Promise.resolve([]);
118
82
  }
119
-
120
83
  const fontsArray = fonts instanceof Array ? fonts : [fonts];
121
- return Promise.all(fontsArray.filter(font => font).map(font => this.loadFont({forceLoad, ...font})));
84
+ return Promise.all(fontsArray.filter(font => font).map(font => this.loadFont({
85
+ forceLoad,
86
+ ...font
87
+ })));
122
88
  };
123
- }
89
+ }
@@ -0,0 +1,3 @@
1
+ export default class NoPermissionsAcquirer {
2
+ getPermissions(): Promise<void>;
3
+ }
@@ -1,5 +1,5 @@
1
1
  export default class NoPermissionsAcquirer {
2
- public async getPermissions() {
2
+ async getPermissions() {
3
3
  return Promise.resolve();
4
4
  }
5
- }
5
+ }
@@ -0,0 +1,13 @@
1
+ export type PermissionsAcquirerProps = {
2
+ requestPermissionsTitle?: string;
3
+ requestPermissionsMessage?: string;
4
+ requestPermissionsPositiveButtonText?: string;
5
+ permissionsRefusalMessage?: string;
6
+ permissionsErrorMessage?: string;
7
+ };
8
+ export default class PermissionsAcquirer {
9
+ private readonly props;
10
+ constructor(props: PermissionsAcquirerProps);
11
+ checkPermissions(): Promise<boolean>;
12
+ getPermissions(): Promise<void>;
13
+ }
@@ -1,44 +1,28 @@
1
- import {Platform, PermissionsAndroid} from 'react-native';
1
+ import { Platform, PermissionsAndroid } from 'react-native';
2
2
  const AndroidOsVersion = Platform.OS === 'android' ? Platform.constants.Release : undefined;
3
-
4
- export type PermissionsAcquirerProps = {
5
- requestPermissionsTitle?: string;
6
- requestPermissionsMessage?: string;
7
- requestPermissionsPositiveButtonText?: string;
8
- permissionsRefusalMessage?: string;
9
- permissionsErrorMessage?: string;
10
- };
11
-
12
- const DEFAULT_PERMISSIONS_ACQUIRER_PROPS: Required<PermissionsAcquirerProps> = {
3
+ const DEFAULT_PERMISSIONS_ACQUIRER_PROPS = {
13
4
  requestPermissionsTitle: 'Allow Storage Access',
14
5
  requestPermissionsMessage: 'Give the app permission to access the files and storage on your device.',
15
6
  requestPermissionsPositiveButtonText: 'Continue',
16
7
  permissionsRefusalMessage: 'Please edit your permission settings to continue.',
17
8
  permissionsErrorMessage: `We weren't able to obtain the required permissions. Please try Again.`
18
9
  };
19
-
20
10
  export default class PermissionsAcquirer {
21
- private readonly props;
22
- constructor(props: PermissionsAcquirerProps) {
11
+ constructor(props) {
23
12
  this.props = props;
24
13
  }
25
-
26
- public async checkPermissions() {
14
+ async checkPermissions() {
27
15
  return await PermissionsAndroid.check(PermissionsAndroid.PERMISSIONS.WRITE_EXTERNAL_STORAGE);
28
16
  }
29
-
30
- public async getPermissions() {
31
- if ((AndroidOsVersion && Number(AndroidOsVersion) >= 13) || (await this.checkPermissions())) {
17
+ async getPermissions() {
18
+ if (AndroidOsVersion && Number(AndroidOsVersion) >= 13 || (await this.checkPermissions())) {
32
19
  return Promise.resolve();
33
20
  }
34
-
35
21
  try {
36
22
  const result = await PermissionsAndroid.request(PermissionsAndroid.PERMISSIONS.WRITE_EXTERNAL_STORAGE, {
37
23
  title: this.props.requestPermissionsTitle ?? DEFAULT_PERMISSIONS_ACQUIRER_PROPS.requestPermissionsTitle,
38
24
  message: this.props.requestPermissionsMessage ?? DEFAULT_PERMISSIONS_ACQUIRER_PROPS.requestPermissionsMessage,
39
- buttonPositive:
40
- this.props.requestPermissionsPositiveButtonText ??
41
- DEFAULT_PERMISSIONS_ACQUIRER_PROPS.requestPermissionsPositiveButtonText
25
+ buttonPositive: this.props.requestPermissionsPositiveButtonText ?? DEFAULT_PERMISSIONS_ACQUIRER_PROPS.requestPermissionsPositiveButtonText
42
26
  });
43
27
  if (result === PermissionsAndroid.RESULTS.GRANTED) {
44
28
  return Promise.resolve();
@@ -55,4 +39,4 @@ export default class PermissionsAcquirer {
55
39
  });
56
40
  }
57
41
  }
58
- }
42
+ }
@@ -0,0 +1,2 @@
1
+ import PermissionsAcquirer from "./NoPermissionsAcquirer";
2
+ export default PermissionsAcquirer;
@@ -1,3 +1,2 @@
1
1
  import PermissionsAcquirer from './NoPermissionsAcquirer';
2
-
3
2
  export default PermissionsAcquirer;
@@ -0,0 +1,2 @@
1
+ import PermissionsAcquirer from "./NoPermissionsAcquirer";
2
+ export default PermissionsAcquirer;
@@ -0,0 +1,2 @@
1
+ declare let RNFS: typeof import('react-native-fs') | undefined;
2
+ export default RNFS;
@@ -0,0 +1,5 @@
1
+ let RNFS;
2
+ try {
3
+ RNFS = require('react-native-fs');
4
+ } catch (error) {}
5
+ export default RNFS;
@@ -0,0 +1,61 @@
1
+ import { FontExtension } from './FontLoader';
2
+ import { FontDownloaderProps } from './FontDownloader';
3
+ import type { PermissionsAcquirerProps } from './PermissionsAcquirer.android';
4
+ type DynamicFontsProps = {
5
+ fontDownloadingProps?: Omit<FontDownloaderProps, 'debug'>;
6
+ permissionsAcquirerProps?: PermissionsAcquirerProps;
7
+ fontLoadErrorMessage?: string;
8
+ /**
9
+ * Enable debug mode to print extra logs
10
+ */
11
+ debug?: boolean;
12
+ /**
13
+ * Do not request permissions
14
+ */
15
+ doNotRequestPermissions?: boolean;
16
+ };
17
+ type GetFontInput = {
18
+ /**
19
+ * The uri of the font (to be downloaded from)
20
+ */
21
+ fontUri: string;
22
+ /**
23
+ * The full name of the font
24
+ */
25
+ fontName: string;
26
+ /**
27
+ * The extension of the font, i.e. '.ttf' or '.otf'
28
+ */
29
+ fontExtension: FontExtension;
30
+ /**
31
+ * Milliseconds for the download to complete in (defaults to 5000)
32
+ */
33
+ timeout?: number;
34
+ };
35
+ export { DynamicFontsProps, FontExtension, GetFontInput };
36
+ export default class DynamicFonts {
37
+ private readonly props;
38
+ private readonly permissionsAcquirer;
39
+ private readonly fontLoader;
40
+ private readonly fontDownloader;
41
+ constructor(props: DynamicFontsProps);
42
+ private log;
43
+ private loadFont;
44
+ /**
45
+ * Get font - download from uri (or from cache if already downloaded) and load it to memory
46
+ * You need to handle errors in the form of Promise.reject
47
+ * @param fontUri the uri of the font (to be downloaded from)
48
+ * @param fontName the full name of the font
49
+ * @param fontExtension the extension of the font, i.e. '.ttf' or '.otf'
50
+ * @param timeout milliseconds for the download to complete in (defaults to 5000)
51
+ */
52
+ getFont({ fontUri, fontName, fontExtension, timeout }: GetFontInput): Promise<string>;
53
+ getFonts(fonts: GetFontInput | GetFontInput[]): Promise<string[]>;
54
+ private buildFontData;
55
+ getFontFamily(rootUri: string, fontNames: string[], fontExtension: FontExtension, fontNamePrefix?: string, retries?: number): Promise<string[]>;
56
+ private deleteFontFromDisk;
57
+ deleteFont(fontName: string, fontExtension: FontExtension): Promise<void>;
58
+ deleteFontFamily(fontNames: string[], fontExtension: FontExtension, fontNamePrefix?: string): Promise<void>;
59
+ isFontDownloaded(fontName: string, fontExtension: FontExtension): Promise<boolean>;
60
+ isFontFamilyDownloaded(rootUri: string, fontNames: string[], fontExtension: FontExtension, fontNamePrefix?: string): Promise<boolean>;
61
+ }