Reset the demo project to a blank state
masterIf you want to start developing from scratch, run the reset command. This moves the existing starter code to the app-example directory and creates a clean app directory.
npm run reset-projectrepository·master·Indexed 18 days ago
https://github.com/obytes/app-icon-badgeA package and Expo plugin for generating app icon badges. It supports 'banner' and 'ribbon' badge types with customizable text, position, and colors. The tool includes a CLI for manual icon processing, a JSON configuration system for batching, and an Expo config plugin to automatically apply badges to iOS and Android adaptive icons during the build process.
If you want to start developing from scratch, run the reset command. This moves the existing starter code to the app-example directory and creates a clean app directory.
npm run reset-projectTo run the demo project locally, install the dependencies and start the Expo development server.
npm install
npx expo startTo use the app-icon-badge plugin in an Expo project, add it to the plugins array in your app.config.ts (or app.json). The plugin accepts a configuration object of type AppIconBadgeOptions as its second element in the plugin array tuple.
enabled (boolean): Enables or disables the plugin. It is recommended to set this to false for production builds to avoid badges appearing in released versions.badges (Array): An array of badge objects to be rendered on the app icon.text (string): The text content to display on the badge (e.g., 'DEV' or a version number).type ('banner' | 'ribbon'): Defines the visual style of the badge. Supported values are banner or ribbon.color ('white' | 'black'): The color of the text. Currently, only white and black are supported.background (string): The background color of the badge. Must be provided in hex format (e.g., #FF0000).import type { AppIconBadgeOptions } from 'app-icon-badge/types';
const appIconBadgeConfig: AppIconBadgeOptions = {
enabled: true,
badges: [
{
text: 'DEV',
type: 'banner',
color: 'white',
background: '#FF0000',
},
{
text: 'V1.0.1',
type: 'ribbon',
},
],
};
// In your app.config.ts export:
export default ({ config }: ConfigContext): ExpoConfig => ({
...config,
plugins: ['expo-router', ['app-icon-badge', appIconBadgeConfig]],
});The withIconBadge function is an Expo config plugin used to integrate icon badges into your app icon. It is exported as the default module from the plugin entrypoint. Note that while icon generation is an asynchronous operation, this plugin uses a synchronous version of the underlying function to ensure compatibility with the Expo config plugin lifecycle.
const withIconBadge = require('app-icon-badge/plugin');
module.exports = (config) => {
return withIconBadge(config);
};The getResultPath function calculates the output filename for a generated badge based on the provided icon path. It inserts the string result into the filename before the file extension.
Note: While the JSDoc documentation suggests an environment parameter, the current implementation only accepts an icon property in its Params object and does not use the environment to alter the path.
getResultPath({
icon: './assets/icon.png',
environment: 'development',
});The loadOverlay function loads an image from a given file path and optionally replaces a specific base color (black #000000) with a new background color. This is useful for dynamically changing the color of badge overlays.
path (string): The file path to the image overlay.background (string, optional): A hex color string (e.g., #FF0000) representing the new color to apply.background is provided as a valid hex color, the function attempts to replace pixels that are close to #000000 (using Delta E color difference) with the new color.background is provided but is not a valid hex color, a warning is logged to the console, and the original image is returned without changes.background is not provided, the original image is returned.import { loadOverlay } from './load-overlay';
// Load an overlay with a specific background color
const overlay = await loadOverlay({
path: './path/to/overlay.png',
background: '#FF5733'
});The IconConfig class is used to define the parameters for generating app icon badges. It accepts a configuration object containing the source icon, destination path, a list of badges to apply, and an optional flag for adaptive icons.
icon: The source icon path (string).dstPath: The destination path where the generated icons will be saved (optional string).badges: An array of Badge objects to be applied to the icon.isAdaptiveIcon: A boolean flag indicating if the icon should be generated as an adaptive icon (optional boolean).import { IconConfig } from './cli/icon-config';
const config = new IconConfig({
icon: 'path/to/source/icon.png',
dstPath: 'path/to/output/folder',
badges: [{ /* badge configuration */ }],
isAdaptiveIcon: true
});The withIconBadgeAsync plugin is an Expo Config Plugin used to automatically add badges to your application icons for both iOS and Android. It handles updating the main app icon, the iOS-specific icon, and the Android adaptive icon foreground image.
enabled option is not provided, the plugin defaults to true..expo/app-icon-badge directory and updates your app.json (or app.config.js) to point to these new files.icon and the ios.icon field.icon and the android.adaptiveIcon.foregroundImage field.The plugin accepts an AppIconBadgeConfig object:
badges: An array of Badge objects to be applied to the icon.enabled: A boolean determining if the plugin should run (defaults to true).// Example usage in app.config.ts or app.json
export default {
expo: {
plugins: [
[
'app-icon-badge/with-icon-badge-async',
{
enabled: true,
badges: [
// ... your badge configurations
],
},
],
],
},
};The createBannerBadge function generates a banner badge image using Jimp. It overlays text onto a banner image based on the provided configuration.
Options Object (Banner):
text: The string to display on the banner (will be converted to uppercase).position: Where the banner is placed. Options are 'top' or 'bottom' (defaults to 'bottom').color: The font color (defaults to 'white').background: The background color for the banner overlay.isAdaptiveIcon (Boolean):
true, the function uses an adaptive icon overlay (assets/banner-overlay-adaptive.png) and adjusts the banner height to 310. It also changes the text alignment logic to ensure text is positioned correctly relative to the adaptive icon shape.false (default), it uses the standard overlay (assets/banner-overlay.png) with a height of 180 and middle-aligned text.import { createBannerBadge } from './path-to-module';
const badge = await createBannerBadge(
{
text: 'v1.0.0',
position: 'bottom',
color: 'white',
background: '#000000'
},
false
);
if (badge) {
// badge is a Jimp instance
await badge.writeAsync('badge.png');
}The addBadge function is the primary entrypoint for applying one or more badges (ribbons or banners) to an icon image. It reads the source icon, composites the requested badges onto it, and saves the resulting image to a destination path.
Parameters:
icon: The source image (path or buffer).dstPath: (Optional) The destination path where the resulting image will be saved. If omitted, the path is automatically generated using getResultPath.isAdaptiveIcon: (Optional) Boolean indicating if the icon is an adaptive icon. Defaults to false.badges: An array of badge configurations. Supported types are 'ribbon' and 'banner' (via createRibbonBadge and createBannerBadge).Returns:
Promise that resolves to the string path of the saved result image.import { addBadge } from 'app-icon-badge';
const resultPath = await addBadge({
icon: './path/to/icon.png',
dstPath: './output/icon-with-badge.png',
isAdaptiveIcon: false,
badges: [
{ type: 'ribbon', text: 'New' },
{ type: 'banner', text: 'Beta' }
],
});
console.log(`Badge added at: ${resultPath}`);The createRibbonBadge function generates a ribbon overlay image with text, which can be used to decorate app icons. It supports positioning the ribbon on the left or right side and provides special handling for adaptive icons.
Ribbon objecttext (string): The text to display on the ribbon.position ('left' | 'right'): The side of the icon where the ribbon will appear. Defaults to 'right'.color ('white' | 'black'): The color of the text. Defaults to 'white'.background (optional): The background color/image used for the ribbon overlay.isAdaptiveIcon (boolean)true, the function uses a specific overlay (assets/ribbon-overlay-adaptive.png) and different dimensions/translations optimized for adaptive icon shapes. Defaults to false.Promise<Jimp | null> containing the generated Jimp image instance.import { createRibbonBadge } from './create-ribbon-badge';
const ribbon = await createRibbonBadge(
{
text: 'NEW',
position: 'right',
color: 'white',
background: '#ff0000'
},
false // isAdaptiveIcon
);
if (ribbon) {
// Use the Jimp instance (e.g., save to file)
await ribbon.write('ribbon.png');
}The withIconBadge plugin is an Expo Config Plugin used to automatically add badges to your application icons. It handles both standard icons and Android adaptive icons by generating new icon files in the .expo/app-icon-badge directory and updating your Expo configuration to point to these new files.
When enabled, the plugin performs the following:
config.icon is defined, it generates a badged version at .expo/app-icon-badge/icon.png.config.android.adaptiveIcon.foregroundImage is defined, it generates a badged version at .expo/app-icon-badge/foregroundImage.png with the isAdaptiveIcon flag set.config.ios.icon is defined, it generates a badged version at .expo/app-icon-badge/icon.png.If enabled is set to false in the options, the plugin will do nothing.
import { withIconBadge } from 'obytes/app-icon-badge';
export default ({ config }) => {
return withIconBadge(config, {
enabled: true,
badges: [
// your badge configurations here
],
});
};