Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "react-native-app-clip",
"version": "0.9.1",
"version": "0.9.2",
"description": "Config plugin to add an App Clip to a React Native iOS app",
"main": "build/index.js",
"types": "build/index.d.ts",
Expand Down
18 changes: 18 additions & 0 deletions plugin/src/lib/getAppClipIcon.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
import type { ConfigPlugin } from "expo/config-plugins";
import path from "node:path";

export function getAppClipIcon(
config: Pick<Parameters<ConfigPlugin>[0], "icon" | "ios">,
): { name: string; fileName: string } | undefined {
let icon = config.ios?.icon || config.icon;
if (icon && typeof icon === "object" && !icon.light && !icon.dark && !icon.tinted) {
icon = config.icon;
}
if (typeof icon !== "string" || path.extname(icon) !== ".icon") {
return undefined;
}
return {
name: path.basename(icon, ".icon"),
fileName: path.basename(icon),
};
}
6 changes: 6 additions & 0 deletions plugin/src/withPlist.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ import {
import fs from "node:fs";
import path from "node:path";

import { getAppClipIcon } from "./lib/getAppClipIcon";

/**
* List of keys that are not allowed in the Info.plist due to not being supported in App Clip. Add to this array as new build issues arise.
*/
Expand Down Expand Up @@ -74,6 +76,10 @@ export const withPlist: ConfigPlugin<{
}

infoPlist.CFBundleName = "$(PRODUCT_MODULE_NAME)";
const appClipIcon = getAppClipIcon(config);
if (appClipIcon) {
infoPlist.CFBundleIconName = appClipIcon.name;
}

fs.mkdirSync(path.dirname(filePath), {
recursive: true,
Expand Down
21 changes: 20 additions & 1 deletion plugin/src/withXcode.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,12 @@
import { type ConfigPlugin, withXcodeProject } from "expo/config-plugins";
import {
IOSConfig,
type ConfigPlugin,
withXcodeProject,
} from "expo/config-plugins";
import fs from "node:fs";
import path from "node:path";

import { getAppClipIcon } from "./lib/getAppClipIcon";
import { addBuildPhases } from "./xcode/addBuildPhases";
import { addPbxGroup } from "./xcode/addPbxGroup";
import { modifyAppDelegate } from "./xcode/modifyAppDelegate";
Expand All @@ -20,6 +25,7 @@ export const withXcode: ConfigPlugin<{
}> = (config, { name, targetName, bundleIdentifier, deploymentTarget, enableCompression }) => {
return withXcodeProject(config, (config) => {
const xcodeProject = config.modResults;
const appClipIcon = getAppClipIcon(config);

const targetUuid = xcodeProject.generateUuid();
const groupName = "Embed App Clips";
Expand All @@ -32,6 +38,7 @@ export const withXcode: ConfigPlugin<{
bundleIdentifier,
deploymentTarget,
appleTeamId: config.ios?.appleTeamId,
appIconName: appClipIcon?.name,
});

const productFile = addProductFile(xcodeProject, {
Expand All @@ -54,6 +61,7 @@ export const withXcode: ConfigPlugin<{
projectName: projectName as string,
targetName,
platformProjectRoot,
appIconFileName: appClipIcon?.fileName,
});

if (enableCompression) {
Expand All @@ -74,8 +82,19 @@ export const withXcode: ConfigPlugin<{
groupName,
productFile,
enableCompression,
resourcesPhaseName: appClipIcon ? "Resources" : undefined,
});

if (appClipIcon) {
IOSConfig.XcodeUtils.addResourceFileToGroup({
filepath: appClipIcon.fileName,
groupName: targetName,
project: xcodeProject,
isBuildFile: true,
targetUuid,
});
}

return config;
});
};
4 changes: 3 additions & 1 deletion plugin/src/xcode/addBuildPhases.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ export function addBuildPhases(
groupName,
productFile,
enableCompression,
resourcesPhaseName,
}: {
targetUuid: string;
groupName: string;
Expand All @@ -18,6 +19,7 @@ export function addBuildPhases(
group: string;
};
enableCompression?: boolean;
resourcesPhaseName?: string;
},
) {
const buildPath = `"$(CONTENTS_FOLDER_PATH)/AppClips"`;
Expand Down Expand Up @@ -81,7 +83,7 @@ export function addBuildPhases(
xcodeProject.addBuildPhase(
["Images.xcassets", "SplashScreen.storyboard", "Supporting/Expo.plist"],
"PBXResourcesBuildPhase",
groupName,
resourcesPhaseName ?? groupName,
targetUuid,
folderType,
buildPath,
Expand Down
16 changes: 15 additions & 1 deletion plugin/src/xcode/addPbxGroup.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,13 @@ export function addPbxGroup(
projectName,
targetName,
platformProjectRoot,
}: { projectName: string; targetName: string; platformProjectRoot: string },
appIconFileName,
}: {
projectName: string;
targetName: string;
platformProjectRoot: string;
appIconFileName?: string;
},
) {
const targetPath = path.join(platformProjectRoot, targetName);

Expand All @@ -34,6 +40,14 @@ export function addPbxGroup(
);
copyFolderRecursiveSync(imagesXcassetsSource, targetPath);

if (appIconFileName) {
fs.cpSync(
path.join(platformProjectRoot, projectName, appIconFileName),
path.join(targetPath, appIconFileName),
{ recursive: true },
);
}

// Add PBX group
const { uuid: pbxGroupUuid } = xcodeProject.addPbxGroup(
[
Expand Down
6 changes: 5 additions & 1 deletion plugin/src/xcode/addXCConfigurationList.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,17 +9,21 @@ export function addXCConfigurationList(
bundleIdentifier,
deploymentTarget,
appleTeamId,
appIconName,
}: {
name: string;
targetName: string;
currentProjectVersion: string;
bundleIdentifier: string;
deploymentTarget: string;
appleTeamId?: string;
appIconName?: string;
},
) {
const commonBuildSettings: Record<string, string> = {
ASSETCATALOG_COMPILER_APPICON_NAME: "AppIcon",
ASSETCATALOG_COMPILER_APPICON_NAME: appIconName
? JSON.stringify(appIconName)
: "AppIcon",
CLANG_ENABLE_MODULES: "YES",
CURRENT_PROJECT_VERSION: `"${currentProjectVersion}"`,
INFOPLIST_FILE: `${targetName}/Info.plist`,
Expand Down
Loading