-
Notifications
You must be signed in to change notification settings - Fork 8
/
Copy pathapp.plugin.ts
45 lines (38 loc) · 1.31 KB
/
app.plugin.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
import { addBadge } from './index';
import { Badge } from './types';
const DST_APP_ICON_BADGE_FOLDER = '.expo/app-icon-badge';
const DST_ICON = `${DST_APP_ICON_BADGE_FOLDER}/icon.png`;
const DST_ADAPTIVE_APP_ICON = `${DST_APP_ICON_BADGE_FOLDER}/foregroundImage.png`;
type Params = {
badges: Array<Badge>;
enabled?: boolean;
};
function withIconBadge(config: any, { badges, enabled = true }: Params) {
if (!enabled) return config;
// get source paths from config
const iconPath = config?.icon;
const adaptiveIconPath = config?.android?.adaptiveIcon?.foregroundImage;
// TODO: add more checks for the config object
// Generate icon with badge
// normally addBadge is async but we don't need to wait for it also not sure how to use async in this context
if (iconPath) {
addBadge({
icon: iconPath,
dstPath: DST_ICON,
badges,
}).catch(() => {}); // we silently fail to prevent error in android build process
config.icon = DST_ICON;
}
// waiting for the adaptive icon support here
if (adaptiveIconPath) {
addBadge({
isAdaptiveIcon: true,
icon: adaptiveIconPath,
dstPath: DST_ADAPTIVE_APP_ICON,
badges,
}).catch(() => {});
config.android.adaptiveIcon.foregroundImage = DST_ADAPTIVE_APP_ICON;
}
return config;
}
module.exports = withIconBadge;