Skip to content

Commit 350179d

Browse files
authored
Feat/dynamic fonts add option to not request permissions and test downloaded (#2758)
* Add a way to delete fonts from disk * Improve \ fix some errors * Add a way to not request permissions * Add isFontDownloaded to the API
1 parent 09d43f2 commit 350179d

File tree

3 files changed

+21
-7
lines changed

3 files changed

+21
-7
lines changed
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
export default class NoPermissionsAcquirer {
2+
public async getPermissions() {
3+
return Promise.resolve();
4+
}
5+
}
Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
export default class PermissionsAcquirer {
2-
public async getPermissions() {
3-
return Promise.resolve();
4-
}
5-
}
1+
import PermissionsAcquirer from './NoPermissionsAcquirer';
2+
3+
export default PermissionsAcquirer;

lib/components/DynamicFonts/index.ts

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import FontLoader, {FontExtension, LoadFontInput} from './FontLoader';
33
import FontDownloader, {FontDownloaderProps} from './FontDownloader';
44
import PermissionsAcquirerAndroid, {PermissionsAcquirerProps} from './PermissionsAcquirer.android';
55
import PermissionsAcquirerIOS from './PermissionsAcquirer.ios';
6+
import NoPermissionsAcquirer from './NoPermissionsAcquirer';
67
const PermissionsAcquirer = Platform.OS === 'android' ? PermissionsAcquirerAndroid : PermissionsAcquirerIOS;
78

89
const DEFAULT_FONT_LOAD_ERROR_MESSAGE = 'Unable to load this font.';
@@ -15,6 +16,10 @@ type DynamicFontsProps = {
1516
* Enable debug mode to print extra logs
1617
*/
1718
debug?: boolean;
19+
/**
20+
* Do not request permissions
21+
*/
22+
doNotRequestPermissions?: boolean;
1823
};
1924

2025
type GetFontInput = {
@@ -45,9 +50,11 @@ export default class DynamicFonts {
4550
private readonly fontDownloader: InstanceType<typeof FontDownloader>;
4651

4752
constructor(props: DynamicFontsProps) {
48-
const {debug = __DEV__} = props;
53+
const {debug = __DEV__, doNotRequestPermissions} = props;
4954
this.props = {fontLoadErrorMessage: DEFAULT_FONT_LOAD_ERROR_MESSAGE, ...props};
50-
this.permissionsAcquirer = new PermissionsAcquirer(this.props.permissionsAcquirerProps ?? {});
55+
this.permissionsAcquirer = doNotRequestPermissions
56+
? new NoPermissionsAcquirer()
57+
: new PermissionsAcquirer(this.props.permissionsAcquirerProps ?? {});
5158
this.fontLoader = new FontLoader({debug});
5259
const fontDownloadingProps = this.props.fontDownloadingProps ?? {};
5360
this.fontDownloader = new FontDownloader({...fontDownloadingProps, debug});
@@ -162,4 +169,8 @@ export default class DynamicFonts {
162169
await this.deleteFontFromDisk(fontName, fontExtension, fontNamePrefix);
163170
});
164171
}
172+
173+
public async isFontDownloaded(fontName: string, fontExtension: FontExtension): Promise<boolean> {
174+
return await this.fontDownloader.isFontDownloaded(fontName, fontExtension);
175+
}
165176
}

0 commit comments

Comments
 (0)