uilib-native 5.0.1 → 5.1.0-snapshot.7630
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.
- package/package.json +4 -5
- package/components/DynamicFonts/FontDownloader.d.ts +0 -41
- package/components/DynamicFonts/FontDownloader.js +0 -140
- package/components/DynamicFonts/FontLoader.d.ts +0 -35
- package/components/DynamicFonts/FontLoader.js +0 -89
- package/components/DynamicFonts/NoPermissionsAcquirer.d.ts +0 -3
- package/components/DynamicFonts/NoPermissionsAcquirer.js +0 -5
- package/components/DynamicFonts/PermissionsAcquirer.android.d.ts +0 -13
- package/components/DynamicFonts/PermissionsAcquirer.android.js +0 -42
- package/components/DynamicFonts/PermissionsAcquirer.ios.d.ts +0 -2
- package/components/DynamicFonts/PermissionsAcquirer.ios.js +0 -2
- package/components/DynamicFonts/PermissionsAcquirer.web.d.ts +0 -2
- package/components/DynamicFonts/PermissionsAcquirer.web.js +0 -2
- package/components/DynamicFonts/RNFSPackage.d.ts +0 -2
- package/components/DynamicFonts/RNFSPackage.js +0 -5
- package/components/DynamicFonts/index.d.ts +0 -61
- package/components/DynamicFonts/index.js +0 -154
- package/components/HighlighterOverlayView/index.d.ts +0 -34
- package/components/HighlighterOverlayView/index.js +0 -49
- package/components/HighlighterOverlayView/index.web.d.ts +0 -34
- package/components/HighlighterOverlayView/index.web.js +0 -15
- package/components/Keyboard/KeyboardAccessoryView/CustomKeyboardView/CustomKeyboardView.android.d.ts +0 -10
- package/components/Keyboard/KeyboardAccessoryView/CustomKeyboardView/CustomKeyboardView.android.js +0 -51
- package/components/Keyboard/KeyboardAccessoryView/CustomKeyboardView/CustomKeyboardView.ios.d.ts +0 -19
- package/components/Keyboard/KeyboardAccessoryView/CustomKeyboardView/CustomKeyboardView.ios.js +0 -62
- package/components/Keyboard/KeyboardAccessoryView/CustomKeyboardView/CustomKeyboardViewBase.d.ts +0 -27
- package/components/Keyboard/KeyboardAccessoryView/CustomKeyboardView/CustomKeyboardViewBase.js +0 -67
- package/components/Keyboard/KeyboardAccessoryView/CustomKeyboardView/index.d.ts +0 -4
- package/components/Keyboard/KeyboardAccessoryView/CustomKeyboardView/index.js +0 -10
- package/components/Keyboard/KeyboardAccessoryView/CustomKeyboardView/index.web.d.ts +0 -3
- package/components/Keyboard/KeyboardAccessoryView/CustomKeyboardView/index.web.js +0 -6
- package/components/Keyboard/KeyboardAccessoryView/KeyboardRegistry/EventEmitterManager/index.d.ts +0 -10
- package/components/Keyboard/KeyboardAccessoryView/KeyboardRegistry/EventEmitterManager/index.js +0 -33
- package/components/Keyboard/KeyboardAccessoryView/KeyboardRegistry/index.d.ts +0 -71
- package/components/Keyboard/KeyboardAccessoryView/KeyboardRegistry/index.js +0 -135
- package/components/Keyboard/KeyboardAccessoryView/KeyboardUtils/index.d.ts +0 -26
- package/components/Keyboard/KeyboardAccessoryView/KeyboardUtils/index.js +0 -91
- package/components/Keyboard/KeyboardAccessoryView/TextInputKeyboardManager/TextInputKeyboardManager.android.d.ts +0 -4
- package/components/Keyboard/KeyboardAccessoryView/TextInputKeyboardManager/TextInputKeyboardManager.android.js +0 -9
- package/components/Keyboard/KeyboardAccessoryView/TextInputKeyboardManager/TextInputKeyboardManager.ios.d.ts +0 -10
- package/components/Keyboard/KeyboardAccessoryView/TextInputKeyboardManager/TextInputKeyboardManager.ios.js +0 -64
- package/components/Keyboard/KeyboardAccessoryView/TextInputKeyboardManager/index.d.ts +0 -4
- package/components/Keyboard/KeyboardAccessoryView/TextInputKeyboardManager/index.js +0 -6
- package/components/Keyboard/KeyboardAccessoryView/index.d.ts +0 -84
- package/components/Keyboard/KeyboardAccessoryView/index.js +0 -161
- package/components/Keyboard/KeyboardAwareInsetsView/index.d.ts +0 -16
- package/components/Keyboard/KeyboardAwareInsetsView/index.js +0 -31
- package/components/Keyboard/KeyboardTrackingView/KeyboardTrackingView.android.d.ts +0 -12
- package/components/Keyboard/KeyboardTrackingView/KeyboardTrackingView.android.js +0 -17
- package/components/Keyboard/KeyboardTrackingView/KeyboardTrackingView.ios.d.ts +0 -21
- package/components/Keyboard/KeyboardTrackingView/KeyboardTrackingView.ios.js +0 -35
- package/components/Keyboard/KeyboardTrackingView/index.d.ts +0 -81
- package/components/Keyboard/KeyboardTrackingView/index.js +0 -22
- package/components/Keyboard/KeyboardTrackingView/index.web.d.ts +0 -6
- package/components/Keyboard/KeyboardTrackingView/index.web.js +0 -7
- package/components/Keyboard/index.d.ts +0 -40
- package/components/Keyboard/index.js +0 -13
- package/components/SafeArea/SafeAreaInsetsManager.d.ts +0 -34
- package/components/SafeArea/SafeAreaInsetsManager.js +0 -128
- package/components/SafeArea/SafeAreaSpacerView.d.ts +0 -10
- package/components/SafeArea/SafeAreaSpacerView.js +0 -68
- package/components/SafeArea/SafeAreaSpacerView.web.d.ts +0 -10
- package/components/SafeArea/SafeAreaSpacerView.web.js +0 -9
- package/components/SafeArea/index.d.ts +0 -10
- package/components/SafeArea/index.js +0 -11
- package/components/index.d.ts +0 -6
- package/components/index.js +0 -6
- package/specs/HighlighterViewNativeComponent.d.ts +0 -61
- package/specs/KeyboardTrackingViewNativeComponent.d.ts +0 -58
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "uilib-native",
|
|
3
|
-
"version": "5.0.
|
|
3
|
+
"version": "5.1.0-snapshot.7630",
|
|
4
4
|
"homepage": "https://github.com/wix/react-native-ui-lib",
|
|
5
5
|
"description": "uilib native components (separated from js components)",
|
|
6
6
|
"main": "components/index",
|
|
@@ -10,14 +10,13 @@
|
|
|
10
10
|
"author": "Ethan Sharabi <ethan.shar@gmail.com>",
|
|
11
11
|
"license": "MIT",
|
|
12
12
|
"dependencies": {
|
|
13
|
-
"lodash": "^4.17.21"
|
|
14
|
-
"prop-types": "^15.5.10"
|
|
13
|
+
"lodash": "^4.17.21"
|
|
15
14
|
},
|
|
16
15
|
"devDependencies": {
|
|
17
16
|
"shell-utils": "^1.0.10"
|
|
18
17
|
},
|
|
19
18
|
"peerDependencies": {
|
|
20
|
-
"react": ">=
|
|
21
|
-
"react-native": ">=0.
|
|
19
|
+
"react": ">=19.0.0",
|
|
20
|
+
"react-native": ">=0.78.3"
|
|
22
21
|
}
|
|
23
22
|
}
|
|
@@ -1,41 +0,0 @@
|
|
|
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,140 +0,0 @@
|
|
|
1
|
-
import { Platform } from 'react-native';
|
|
2
|
-
import RNFS from "./RNFSPackage";
|
|
3
|
-
const DEFAULT_DYNAMIC_FONTS_FOLDER = '/dynamicFonts';
|
|
4
|
-
const DEFAULT_DOWNLOAD_ERROR_MESSAGE = 'An error occurred downloading the file:';
|
|
5
|
-
// TODO: this can probably be a more general "downloader" if we so choose
|
|
6
|
-
export default class FontDownloader {
|
|
7
|
-
constructor(props) {
|
|
8
|
-
this.props = {
|
|
9
|
-
dynamicFontsFolder: DEFAULT_DYNAMIC_FONTS_FOLDER,
|
|
10
|
-
downloadErrorMessage: DEFAULT_DOWNLOAD_ERROR_MESSAGE,
|
|
11
|
-
...props
|
|
12
|
-
};
|
|
13
|
-
if (!RNFS) {
|
|
14
|
-
throw new Error(`RNUILib FontDownloader requires installing "react-native-fs" dependency`);
|
|
15
|
-
}
|
|
16
|
-
this.fs = RNFS;
|
|
17
|
-
}
|
|
18
|
-
log(message, ...optionalParams) {
|
|
19
|
-
const {
|
|
20
|
-
debug
|
|
21
|
-
} = this.props;
|
|
22
|
-
if (debug) {
|
|
23
|
-
console.log(message, optionalParams);
|
|
24
|
-
}
|
|
25
|
-
}
|
|
26
|
-
getPrivateFolder() {
|
|
27
|
-
const {
|
|
28
|
-
dynamicFontsFolder
|
|
29
|
-
} = this.props;
|
|
30
|
-
return (Platform.OS === 'android' ? this.fs.ExternalDirectoryPath : this.fs.DocumentDirectoryPath) + dynamicFontsFolder;
|
|
31
|
-
}
|
|
32
|
-
getPrivateFilePath(fileName) {
|
|
33
|
-
return this.getPrivateFolder() + '/' + fileName;
|
|
34
|
-
}
|
|
35
|
-
getFileName(fontName, fontExtension) {
|
|
36
|
-
return fontName + '.' + fontExtension;
|
|
37
|
-
}
|
|
38
|
-
async _isFontDownloaded(fileName) {
|
|
39
|
-
const privateFilePath = this.getPrivateFilePath(fileName);
|
|
40
|
-
return await this.fs.exists(privateFilePath);
|
|
41
|
-
}
|
|
42
|
-
async createPrivateFolderIfNeeded() {
|
|
43
|
-
const privateFolder = this.getPrivateFolder();
|
|
44
|
-
if (!(await this.fs.exists(privateFolder))) {
|
|
45
|
-
await this.fs.mkdir(privateFolder);
|
|
46
|
-
}
|
|
47
|
-
}
|
|
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
|
-
};
|
|
56
|
-
return {
|
|
57
|
-
fromUrl: fontUri,
|
|
58
|
-
toFile: downloadLocation,
|
|
59
|
-
// TODO: It is possible to add a better progress, maybe for slower networks
|
|
60
|
-
// progress: ({bytesWritten, contentLength}: {bytesWritten: number; contentLength: number}) => {},
|
|
61
|
-
...platformSpecificOptions,
|
|
62
|
-
fileCache: false,
|
|
63
|
-
readTimeout
|
|
64
|
-
};
|
|
65
|
-
}
|
|
66
|
-
|
|
67
|
-
/**
|
|
68
|
-
* Download the font
|
|
69
|
-
* @param fontUri the remote location of the font
|
|
70
|
-
* @param fontName the full name of the font
|
|
71
|
-
* @param fontExtension the extension of the font, i.e. '.ttf' or '.otf'
|
|
72
|
-
* @param timeout a timeout for the download to fail after
|
|
73
|
-
* @returns the full path of the download
|
|
74
|
-
*/
|
|
75
|
-
async downloadFont(fontUri, fontName, fontExtension, timeout) {
|
|
76
|
-
const {
|
|
77
|
-
downloadErrorMessage
|
|
78
|
-
} = this.props;
|
|
79
|
-
await this.createPrivateFolderIfNeeded();
|
|
80
|
-
const fileName = this.getFileName(fontName, fontExtension);
|
|
81
|
-
const downloadLocation = this.getPrivateFilePath(fileName);
|
|
82
|
-
try {
|
|
83
|
-
this.log(fontName, 'Starting to download');
|
|
84
|
-
const result = await this.fs.downloadFile(this.getDownloadFontOptions(fontUri, downloadLocation, timeout)).promise;
|
|
85
|
-
if (result.statusCode === 200) {
|
|
86
|
-
this.log(fontName, 'Finished downloading');
|
|
87
|
-
return downloadLocation;
|
|
88
|
-
} else {
|
|
89
|
-
this.log(fontName, 'Error downloading statusCode:', result.statusCode);
|
|
90
|
-
return Promise.reject({
|
|
91
|
-
source: 'uilib:FontDownloader:downloadFont',
|
|
92
|
-
message: `${downloadErrorMessage} fontName: ${fontName} statusCode: ${result.statusCode}`
|
|
93
|
-
});
|
|
94
|
-
}
|
|
95
|
-
} catch (error) {
|
|
96
|
-
this.log(fontName, 'Error downloading error:', error);
|
|
97
|
-
return Promise.reject({
|
|
98
|
-
source: 'uilib:FontDownloader:downloadFont',
|
|
99
|
-
message: `${downloadErrorMessage} fontName: ${fontName} error: ${JSON.stringify(error)}`
|
|
100
|
-
});
|
|
101
|
-
}
|
|
102
|
-
}
|
|
103
|
-
|
|
104
|
-
/**
|
|
105
|
-
* Is the font cached (already downloaded)
|
|
106
|
-
* @param {*} fontName the full name of the font
|
|
107
|
-
* @param {*} fontExtension the extension of the font, i.e. '.ttf' or '.otf'
|
|
108
|
-
*/
|
|
109
|
-
async isFontDownloaded(fontName, fontExtension) {
|
|
110
|
-
const fileName = this.getFileName(fontName, fontExtension);
|
|
111
|
-
return await this._isFontDownloaded(fileName);
|
|
112
|
-
}
|
|
113
|
-
async readFontFromDisk(fontName, fontExtension) {
|
|
114
|
-
let base64FontString;
|
|
115
|
-
const fileName = this.getFileName(fontName, fontExtension);
|
|
116
|
-
const privateFilePath = this.getPrivateFilePath(fileName);
|
|
117
|
-
if (await this.fs.exists(privateFilePath)) {
|
|
118
|
-
this.log(fontName, 'Starting to read from disk');
|
|
119
|
-
base64FontString = await this.fs.readFile(privateFilePath, 'base64').catch(err => {
|
|
120
|
-
this.log(fontName, 'Failed reading from disk:', err);
|
|
121
|
-
});
|
|
122
|
-
this.log(fontName, 'Finished reading from disk');
|
|
123
|
-
} else {
|
|
124
|
-
this.log(fontName, 'File does not exist (read)');
|
|
125
|
-
}
|
|
126
|
-
return base64FontString;
|
|
127
|
-
}
|
|
128
|
-
async deleteFontFromDisk(fontFullName) {
|
|
129
|
-
const privateFilePath = this.getPrivateFilePath(fontFullName);
|
|
130
|
-
if (await this.fs.exists(privateFilePath)) {
|
|
131
|
-
this.log(fontFullName, 'Starting to delete');
|
|
132
|
-
await this.fs.unlink(privateFilePath).catch(err => {
|
|
133
|
-
this.log(fontFullName, 'Failed deleting:', err);
|
|
134
|
-
});
|
|
135
|
-
this.log(fontFullName, 'Finished deleting');
|
|
136
|
-
} else {
|
|
137
|
-
this.log(fontFullName, 'File does not exist (delete)');
|
|
138
|
-
}
|
|
139
|
-
}
|
|
140
|
-
}
|
|
@@ -1,35 +0,0 @@
|
|
|
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,89 +0,0 @@
|
|
|
1
|
-
import { NativeModules } from 'react-native';
|
|
2
|
-
const {
|
|
3
|
-
DynamicFont
|
|
4
|
-
} = NativeModules;
|
|
5
|
-
export default class FontLoader {
|
|
6
|
-
loadedFonts = new Map();
|
|
7
|
-
constructor(props) {
|
|
8
|
-
this.props = props;
|
|
9
|
-
}
|
|
10
|
-
log(message, ...optionalParams) {
|
|
11
|
-
const {
|
|
12
|
-
debug
|
|
13
|
-
} = this.props;
|
|
14
|
-
if (debug) {
|
|
15
|
-
console.log(message, optionalParams);
|
|
16
|
-
}
|
|
17
|
-
}
|
|
18
|
-
loadFont = ({
|
|
19
|
-
fontName,
|
|
20
|
-
base64FontString,
|
|
21
|
-
fontExtension = 'ttf',
|
|
22
|
-
forceLoad = false
|
|
23
|
-
}) => {
|
|
24
|
-
/* Check if this font was already loaded */
|
|
25
|
-
if (!forceLoad && this.loadedFonts.has(fontName)) {
|
|
26
|
-
this.log(fontName, 'Already loaded');
|
|
27
|
-
return Promise.resolve(this.loadedFonts.get(fontName));
|
|
28
|
-
}
|
|
29
|
-
if (!fontName) {
|
|
30
|
-
throw new Error('fontName is a required argument');
|
|
31
|
-
}
|
|
32
|
-
if (!base64FontString) {
|
|
33
|
-
throw new Error('base64FontString is a required argument');
|
|
34
|
-
}
|
|
35
|
-
this.log(fontName, 'Starting to load');
|
|
36
|
-
/* Load font via native binary code */
|
|
37
|
-
return new Promise((resolve, reject) => {
|
|
38
|
-
DynamicFont.loadFont({
|
|
39
|
-
name: fontName,
|
|
40
|
-
data: base64FontString,
|
|
41
|
-
type: fontExtension
|
|
42
|
-
}, (err, givenName) => {
|
|
43
|
-
if (err) {
|
|
44
|
-
reject(err);
|
|
45
|
-
return;
|
|
46
|
-
}
|
|
47
|
-
/* Loaded successfully... resolve promise with "real" font name */
|
|
48
|
-
this.loadedFonts.set(fontName, givenName);
|
|
49
|
-
resolve(givenName);
|
|
50
|
-
});
|
|
51
|
-
});
|
|
52
|
-
};
|
|
53
|
-
|
|
54
|
-
// TODO: Needs to be tested
|
|
55
|
-
// public loadFontFromFile = (fontName: string, filePath: string) => {
|
|
56
|
-
// if (!fontName) {
|
|
57
|
-
// throw new Error('name is a required argument');
|
|
58
|
-
// }
|
|
59
|
-
|
|
60
|
-
// if (!filePath) {
|
|
61
|
-
// throw new Error('filePath is a required argument');
|
|
62
|
-
// }
|
|
63
|
-
|
|
64
|
-
// return new Promise((resolve, reject) => {
|
|
65
|
-
// DynamicFont.loadFontFromFile({
|
|
66
|
-
// name: fontName,
|
|
67
|
-
// filePath
|
|
68
|
-
// },
|
|
69
|
-
// (err: string, givenName: string) => {
|
|
70
|
-
// if (err) {
|
|
71
|
-
// reject(err);
|
|
72
|
-
// return;
|
|
73
|
-
// }
|
|
74
|
-
// resolve(givenName);
|
|
75
|
-
// });
|
|
76
|
-
// });
|
|
77
|
-
// };
|
|
78
|
-
|
|
79
|
-
loadFonts = (fonts, forceLoad) => {
|
|
80
|
-
if (!fonts) {
|
|
81
|
-
return Promise.resolve([]);
|
|
82
|
-
}
|
|
83
|
-
const fontsArray = fonts instanceof Array ? fonts : [fonts];
|
|
84
|
-
return Promise.all(fontsArray.filter(font => font).map(font => this.loadFont({
|
|
85
|
-
forceLoad,
|
|
86
|
-
...font
|
|
87
|
-
})));
|
|
88
|
-
};
|
|
89
|
-
}
|
|
@@ -1,13 +0,0 @@
|
|
|
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,42 +0,0 @@
|
|
|
1
|
-
import { Platform, PermissionsAndroid } from 'react-native';
|
|
2
|
-
const AndroidOsVersion = Platform.OS === 'android' ? Platform.constants.Release : undefined;
|
|
3
|
-
const DEFAULT_PERMISSIONS_ACQUIRER_PROPS = {
|
|
4
|
-
requestPermissionsTitle: 'Allow Storage Access',
|
|
5
|
-
requestPermissionsMessage: 'Give the app permission to access the files and storage on your device.',
|
|
6
|
-
requestPermissionsPositiveButtonText: 'Continue',
|
|
7
|
-
permissionsRefusalMessage: 'Please edit your permission settings to continue.',
|
|
8
|
-
permissionsErrorMessage: `We weren't able to obtain the required permissions. Please try Again.`
|
|
9
|
-
};
|
|
10
|
-
export default class PermissionsAcquirer {
|
|
11
|
-
constructor(props) {
|
|
12
|
-
this.props = props;
|
|
13
|
-
}
|
|
14
|
-
async checkPermissions() {
|
|
15
|
-
return await PermissionsAndroid.check(PermissionsAndroid.PERMISSIONS.WRITE_EXTERNAL_STORAGE);
|
|
16
|
-
}
|
|
17
|
-
async getPermissions() {
|
|
18
|
-
if (AndroidOsVersion && Number(AndroidOsVersion) >= 13 || (await this.checkPermissions())) {
|
|
19
|
-
return Promise.resolve();
|
|
20
|
-
}
|
|
21
|
-
try {
|
|
22
|
-
const result = await PermissionsAndroid.request(PermissionsAndroid.PERMISSIONS.WRITE_EXTERNAL_STORAGE, {
|
|
23
|
-
title: this.props.requestPermissionsTitle ?? DEFAULT_PERMISSIONS_ACQUIRER_PROPS.requestPermissionsTitle,
|
|
24
|
-
message: this.props.requestPermissionsMessage ?? DEFAULT_PERMISSIONS_ACQUIRER_PROPS.requestPermissionsMessage,
|
|
25
|
-
buttonPositive: this.props.requestPermissionsPositiveButtonText ?? DEFAULT_PERMISSIONS_ACQUIRER_PROPS.requestPermissionsPositiveButtonText
|
|
26
|
-
});
|
|
27
|
-
if (result === PermissionsAndroid.RESULTS.GRANTED) {
|
|
28
|
-
return Promise.resolve();
|
|
29
|
-
} else {
|
|
30
|
-
return Promise.reject({
|
|
31
|
-
source: 'uilib:FontDownloader:getPermissions',
|
|
32
|
-
message: this.props.permissionsRefusalMessage ?? DEFAULT_PERMISSIONS_ACQUIRER_PROPS.permissionsRefusalMessage
|
|
33
|
-
});
|
|
34
|
-
}
|
|
35
|
-
} catch (err) {
|
|
36
|
-
return Promise.reject({
|
|
37
|
-
source: 'uilib:FontDownloader:getPermissions',
|
|
38
|
-
message: this.props.permissionsErrorMessage ?? DEFAULT_PERMISSIONS_ACQUIRER_PROPS.permissionsErrorMessage
|
|
39
|
-
});
|
|
40
|
-
}
|
|
41
|
-
}
|
|
42
|
-
}
|
|
@@ -1,61 +0,0 @@
|
|
|
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
|
-
}
|
|
@@ -1,154 +0,0 @@
|
|
|
1
|
-
import FontLoader, { FontExtension } from "./FontLoader";
|
|
2
|
-
import FontDownloader from "./FontDownloader";
|
|
3
|
-
// @ts-expect-error
|
|
4
|
-
import PermissionsAcquirer from "./PermissionsAcquirer";
|
|
5
|
-
import NoPermissionsAcquirer from "./NoPermissionsAcquirer";
|
|
6
|
-
const DEFAULT_FONT_LOAD_ERROR_MESSAGE = 'Unable to load this font.';
|
|
7
|
-
export { FontExtension };
|
|
8
|
-
export default class DynamicFonts {
|
|
9
|
-
constructor(props) {
|
|
10
|
-
const {
|
|
11
|
-
debug = __DEV__,
|
|
12
|
-
doNotRequestPermissions
|
|
13
|
-
} = props;
|
|
14
|
-
this.props = {
|
|
15
|
-
fontLoadErrorMessage: DEFAULT_FONT_LOAD_ERROR_MESSAGE,
|
|
16
|
-
...props
|
|
17
|
-
};
|
|
18
|
-
this.permissionsAcquirer = doNotRequestPermissions ? new NoPermissionsAcquirer() : new PermissionsAcquirer(this.props.permissionsAcquirerProps ?? {});
|
|
19
|
-
this.fontLoader = new FontLoader({
|
|
20
|
-
debug
|
|
21
|
-
});
|
|
22
|
-
const fontDownloadingProps = this.props.fontDownloadingProps ?? {};
|
|
23
|
-
this.fontDownloader = new FontDownloader({
|
|
24
|
-
...fontDownloadingProps,
|
|
25
|
-
debug
|
|
26
|
-
});
|
|
27
|
-
}
|
|
28
|
-
log(message, ...optionalParams) {
|
|
29
|
-
const {
|
|
30
|
-
debug
|
|
31
|
-
} = this.props;
|
|
32
|
-
if (debug) {
|
|
33
|
-
console.log(message, optionalParams);
|
|
34
|
-
}
|
|
35
|
-
}
|
|
36
|
-
async loadFont(input) {
|
|
37
|
-
const {
|
|
38
|
-
fontLoadErrorMessage
|
|
39
|
-
} = this.props;
|
|
40
|
-
try {
|
|
41
|
-
return await this.fontLoader.loadFont(input);
|
|
42
|
-
} catch (err) {
|
|
43
|
-
return Promise.reject({
|
|
44
|
-
source: 'uilib:FontDownloader:loadFont',
|
|
45
|
-
message: `${fontLoadErrorMessage} fontName: ${input.fontName} error: ${JSON.stringify(err)}`
|
|
46
|
-
});
|
|
47
|
-
}
|
|
48
|
-
}
|
|
49
|
-
|
|
50
|
-
/**
|
|
51
|
-
* Get font - download from uri (or from cache if already downloaded) and load it to memory
|
|
52
|
-
* You need to handle errors in the form of Promise.reject
|
|
53
|
-
* @param fontUri the uri of the font (to be downloaded from)
|
|
54
|
-
* @param fontName the full name of the font
|
|
55
|
-
* @param fontExtension the extension of the font, i.e. '.ttf' or '.otf'
|
|
56
|
-
* @param timeout milliseconds for the download to complete in (defaults to 5000)
|
|
57
|
-
*/
|
|
58
|
-
async getFont({
|
|
59
|
-
fontUri,
|
|
60
|
-
fontName,
|
|
61
|
-
fontExtension,
|
|
62
|
-
timeout = 5000
|
|
63
|
-
}) {
|
|
64
|
-
const {
|
|
65
|
-
fontLoadErrorMessage
|
|
66
|
-
} = this.props;
|
|
67
|
-
await this.permissionsAcquirer.getPermissions();
|
|
68
|
-
if (await this.fontDownloader.isFontDownloaded(fontName, fontExtension)) {
|
|
69
|
-
this.log(fontName, 'Already downloaded');
|
|
70
|
-
} else {
|
|
71
|
-
await this.fontDownloader.downloadFont(fontUri, fontName, fontExtension, timeout);
|
|
72
|
-
}
|
|
73
|
-
const base64FontString = await this.fontDownloader.readFontFromDisk(fontName, fontExtension);
|
|
74
|
-
if (base64FontString) {
|
|
75
|
-
this.log(fontName, 'Loading');
|
|
76
|
-
const _fontName = await this.loadFont({
|
|
77
|
-
fontName,
|
|
78
|
-
base64FontString,
|
|
79
|
-
fontExtension
|
|
80
|
-
});
|
|
81
|
-
this.log(_fontName, 'Finished loading');
|
|
82
|
-
return Promise.resolve(_fontName);
|
|
83
|
-
} else {
|
|
84
|
-
return Promise.reject({
|
|
85
|
-
source: 'uilib:FontDownloader:getFont',
|
|
86
|
-
message: `${fontLoadErrorMessage} fontName: ${fontName}`
|
|
87
|
-
});
|
|
88
|
-
}
|
|
89
|
-
}
|
|
90
|
-
async getFonts(fonts) {
|
|
91
|
-
await this.permissionsAcquirer.getPermissions();
|
|
92
|
-
if (fonts instanceof Array) {
|
|
93
|
-
return Promise.all(fonts.filter(font => font).map(font => this.getFont(font)));
|
|
94
|
-
} else {
|
|
95
|
-
return Promise.resolve([await this.getFont(fonts)]);
|
|
96
|
-
}
|
|
97
|
-
}
|
|
98
|
-
buildFontData(rootUri, fontName, fontExtension, fontNamePrefix) {
|
|
99
|
-
const _fontName = `${fontNamePrefix ?? ''}${fontName}`;
|
|
100
|
-
const fullFontName = `${_fontName}.${fontExtension}`;
|
|
101
|
-
return {
|
|
102
|
-
fontUri: `${rootUri}${fullFontName}`,
|
|
103
|
-
fontName: _fontName,
|
|
104
|
-
fontExtension,
|
|
105
|
-
fullFontName
|
|
106
|
-
};
|
|
107
|
-
}
|
|
108
|
-
|
|
109
|
-
// eslint-disable-next-line max-params
|
|
110
|
-
async getFontFamily(rootUri, fontNames, fontExtension, fontNamePrefix, retries = 1) {
|
|
111
|
-
const fonts = fontNames.map(fontName => this.buildFontData(rootUri, fontName, fontExtension, fontNamePrefix));
|
|
112
|
-
let fontsLoaded = [];
|
|
113
|
-
let tryCounter = 0;
|
|
114
|
-
while (fontsLoaded.length < fontNames.length && tryCounter < retries) {
|
|
115
|
-
try {
|
|
116
|
-
++tryCounter;
|
|
117
|
-
// TODO: we should return successful loaded fonts and not fail all of them
|
|
118
|
-
fontsLoaded = await this.getFonts(fonts);
|
|
119
|
-
} catch (error) {
|
|
120
|
-
this.log(`getFontFamily failed (try #${tryCounter}) error:`, error);
|
|
121
|
-
}
|
|
122
|
-
}
|
|
123
|
-
return Promise.resolve(fontsLoaded);
|
|
124
|
-
}
|
|
125
|
-
async deleteFontFromDisk(fontName, fontExtension, fontNamePrefix) {
|
|
126
|
-
const fontInput = this.buildFontData('', fontName, fontExtension, fontNamePrefix);
|
|
127
|
-
await this.fontDownloader.deleteFontFromDisk(fontInput.fullFontName);
|
|
128
|
-
}
|
|
129
|
-
async deleteFont(fontName, fontExtension) {
|
|
130
|
-
await this.permissionsAcquirer.getPermissions();
|
|
131
|
-
await this.deleteFontFromDisk(fontName, fontExtension);
|
|
132
|
-
}
|
|
133
|
-
async deleteFontFamily(fontNames, fontExtension, fontNamePrefix) {
|
|
134
|
-
await this.permissionsAcquirer.getPermissions();
|
|
135
|
-
fontNames.forEach(async fontName => {
|
|
136
|
-
await this.deleteFontFromDisk(fontName, fontExtension, fontNamePrefix);
|
|
137
|
-
});
|
|
138
|
-
}
|
|
139
|
-
async isFontDownloaded(fontName, fontExtension) {
|
|
140
|
-
return await this.fontDownloader.isFontDownloaded(fontName, fontExtension);
|
|
141
|
-
}
|
|
142
|
-
async isFontFamilyDownloaded(rootUri, fontNames, fontExtension, fontNamePrefix) {
|
|
143
|
-
const fonts = fontNames.map(fontName => this.buildFontData(rootUri, fontName, fontExtension, fontNamePrefix));
|
|
144
|
-
try {
|
|
145
|
-
const areDownloaded = await Promise.all(fonts.filter(font => font).map(font => {
|
|
146
|
-
return this.fontDownloader.isFontDownloaded(font.fontName, font.fontExtension);
|
|
147
|
-
}));
|
|
148
|
-
return Promise.resolve(areDownloaded.every(v => v === true));
|
|
149
|
-
} catch (error) {
|
|
150
|
-
this.log(`isFontFamilyDownloaded failed error:`, error);
|
|
151
|
-
return Promise.resolve(false);
|
|
152
|
-
}
|
|
153
|
-
}
|
|
154
|
-
}
|
|
@@ -1,34 +0,0 @@
|
|
|
1
|
-
import React from 'react';
|
|
2
|
-
import { ViewStyle } from 'react-native';
|
|
3
|
-
type HighlightFrameType = {
|
|
4
|
-
x: number;
|
|
5
|
-
y: number;
|
|
6
|
-
width: number;
|
|
7
|
-
height: number;
|
|
8
|
-
};
|
|
9
|
-
type HighlightViewTagParams = {
|
|
10
|
-
padding: number | ViewStyle['padding'];
|
|
11
|
-
offset: Pick<HighlightFrameType, 'x' | 'y'>;
|
|
12
|
-
};
|
|
13
|
-
export type HighlighterOverlayViewProps = {
|
|
14
|
-
visible: boolean;
|
|
15
|
-
overlayColor?: string;
|
|
16
|
-
borderRadius?: number;
|
|
17
|
-
strokeColor?: string;
|
|
18
|
-
strokeWidth?: number;
|
|
19
|
-
onRequestClose?: () => void;
|
|
20
|
-
highlightFrame?: HighlightFrameType;
|
|
21
|
-
style?: ViewStyle;
|
|
22
|
-
highlightViewTag?: number;
|
|
23
|
-
children?: JSX.Element[] | JSX.Element;
|
|
24
|
-
highlightViewTagParams?: HighlightViewTagParams;
|
|
25
|
-
minimumRectSize?: Pick<HighlightFrameType, 'width' | 'height'>;
|
|
26
|
-
innerPadding?: number;
|
|
27
|
-
accessible?: boolean;
|
|
28
|
-
testID?: string;
|
|
29
|
-
};
|
|
30
|
-
declare const HighlighterOverlayView: {
|
|
31
|
-
(props: HighlighterOverlayViewProps): React.JSX.Element;
|
|
32
|
-
displayName: string;
|
|
33
|
-
};
|
|
34
|
-
export default HighlighterOverlayView;
|