Skip to content

Commit

Permalink
Merge pull request #27 from bndkt/v0.0.6-rc
Browse files Browse the repository at this point in the history
v0.0.6
  • Loading branch information
nathan-ahn authored Dec 12, 2024
2 parents ec3f093 + 8ee605b commit f6a2437
Show file tree
Hide file tree
Showing 9 changed files with 91 additions and 19 deletions.
5 changes: 3 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -40,9 +40,10 @@ startActivity(3, "4343", "$32.23", driverName, 47, 43);
- `frequentUpdates` (boolean, default: false): Depending on this param, NSSupportsLiveActivitiesFrequentUpdates will be set
- `widgetsFolder` (string, default: "widgets"): Path from the project root to the folder containing the Swift widget files
- `deploymentTarget` (string, default: "16.2"): The minimum deployment target for the app
- `groupIdentifier` (string): The app group identifier which is required for communication with the main app. Must start with `group.`
<!--
- moduleFileName (string, default: "Module.swift"): File within the widget folder that defines the native module
- attributesFileName (string): File within the widget folder that defined the widget attributes
- `moduleFileName` (string, default: "Module.swift"): File within the widget folder that defines the native module
- `attributesFileName` (string): File within the widget folder that defined the widget attributes
-->

## Example
Expand Down
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-widget-extension",
"version": "0.0.5",
"version": "0.0.6",
"description": "Expo config plugin to add widgets and live activities to a React Native app",
"main": "build/index.js",
"types": "build/index.d.ts",
Expand Down
10 changes: 7 additions & 3 deletions plugin/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,15 @@ import { withConfig } from "./withConfig";
import { withPodfile } from "./withPodfile";

import { withXcode } from "./withXcode";
import { withWidgetExtensionEntitlements } from "./withWidgetExtensionEntitlements";

const withLiveActivities: ConfigPlugin<{
const withWidgetsAndLiveActivities: ConfigPlugin<{
frequentUpdates?: boolean;
widgetsFolder?: string;
deploymentTarget?: string;
moduleFileName?: string;
attributesFileName?: string;
groupIdentifier?: string;
}> = (
config,
{
Expand All @@ -18,6 +20,7 @@ const withLiveActivities: ConfigPlugin<{
deploymentTarget = "16.2",
moduleFileName = "Module.swift",
attributesFileName = "Attributes.swift",
groupIdentifier,
}
) => {
const targetName = `${IOSConfig.XcodeUtils.sanitizedName(
Expand Down Expand Up @@ -46,11 +49,12 @@ const withLiveActivities: ConfigPlugin<{
attributesFileName,
},
],
[withWidgetExtensionEntitlements, { targetName, groupIdentifier }],
[withPodfile, { targetName }],
[withConfig, { targetName, bundleIdentifier }],
[withConfig, { targetName, bundleIdentifier, groupIdentifier }],
]);

return config;
};

export default withLiveActivities;
export default withWidgetsAndLiveActivities;
26 changes: 26 additions & 0 deletions plugin/src/lib/getWidgetExtensionEntitlements.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
import { ExportedConfig, InfoPlist } from "@expo/config-plugins";

export function getWidgetExtensionEntitlements(
iosConfig: ExportedConfig["ios"],
{
groupIdentifier,
}: {
groupIdentifier?: string;
}
) {
const entitlements: InfoPlist = {};

addApplicationGroupsEntitlement(entitlements, groupIdentifier);

return entitlements;
}

export function addApplicationGroupsEntitlement(entitlements: InfoPlist, groupIdentifier?: string) {
if (groupIdentifier) {
const existingApplicationGroups = (entitlements["com.apple.security.application-groups"] as string[]) ?? [];

entitlements["com.apple.security.application-groups"] = [groupIdentifier, ...existingApplicationGroups];
}

return entitlements;
}
35 changes: 23 additions & 12 deletions plugin/src/withConfig.ts
Original file line number Diff line number Diff line change
@@ -1,17 +1,18 @@
import { ConfigPlugin } from "@expo/config-plugins";

import { addApplicationGroupsEntitlement, getWidgetExtensionEntitlements } from "./lib/getWidgetExtensionEntitlements";

export const withConfig: ConfigPlugin<{
bundleIdentifier: string;
targetName: string;
}> = (config, { bundleIdentifier, targetName }) => {
groupIdentifier?: string;
}> = (config, { bundleIdentifier, targetName, groupIdentifier }) => {
let configIndex: null | number = null;
config.extra?.eas?.build?.experimental?.ios?.appExtensions?.forEach(
(ext: any, index: number) => {
if (ext.targetName === targetName) {
configIndex = index;
}
config.extra?.eas?.build?.experimental?.ios?.appExtensions?.forEach((ext: any, index: number) => {
if (ext.targetName === targetName) {
configIndex = index;
}
);
});

if (!configIndex) {
config.extra = {
Expand All @@ -25,8 +26,7 @@ export const withConfig: ConfigPlugin<{
ios: {
...config.extra?.eas?.build?.experimental?.ios,
appExtensions: [
...(config.extra?.eas?.build?.experimental?.ios
?.appExtensions ?? []),
...(config.extra?.eas?.build?.experimental?.ios?.appExtensions ?? []),
{
targetName,
bundleIdentifier,
Expand All @@ -41,10 +41,21 @@ export const withConfig: ConfigPlugin<{
}

if (configIndex != null && config.extra) {
const appClipConfig =
config.extra.eas.build.experimental.ios.appExtensions[configIndex];
const widgetsExtensionConfig = config.extra.eas.build.experimental.ios.appExtensions[configIndex];

widgetsExtensionConfig.entitlements = {
...widgetsExtensionConfig.entitlements,
...getWidgetExtensionEntitlements(config.ios, {
groupIdentifier,
}),
};

appClipConfig.entitlements = {};
config.ios = {
...config.ios,
entitlements: {
...addApplicationGroupsEntitlement(config.ios?.entitlements ?? {}, groupIdentifier),
},
};
}

return config;
Expand Down
3 changes: 2 additions & 1 deletion plugin/src/withPodfile.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,8 @@ export const withPodfile: ConfigPlugin<{ targetName: string }> = (
src: podFileContent,
newSrc: `installer.pods_project.targets.each do |target|
target.build_configurations.each do |config|
config.build_settings['APPLICATION_EXTENSION_API_ONLY'] = 'No'
# Sentry has build errors unless configured as 'YES' for the Sentry target: https://github.com/bndkt/react-native-widget-extension/issues/24
config.build_settings['APPLICATION_EXTENSION_API_ONLY'] = target.name == 'Sentry' ? 'YES' : 'No'
end
end`,
anchor:
Expand Down
27 changes: 27 additions & 0 deletions plugin/src/withWidgetExtensionEntitlements.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
import plist from "@expo/plist";
import { ConfigPlugin, withInfoPlist } from "@expo/config-plugins";
import * as fs from "fs";
import * as path from "path";

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

export const withWidgetExtensionEntitlements: ConfigPlugin<{
targetName: string;
targetPath: string;
groupIdentifier: string;
appleSignin: boolean;
}> = (config, { targetName, groupIdentifier }) => {
return withInfoPlist(config, (config) => {
const targetPath = path.join(config.modRequest.platformProjectRoot, targetName);
const filePath = path.join(targetPath, `${targetName}.entitlements`);

const appClipEntitlements = getWidgetExtensionEntitlements(config.ios, {
groupIdentifier,
});

fs.mkdirSync(path.dirname(filePath), { recursive: true });
fs.writeFileSync(filePath, plist.build(appClipEntitlements));

return config;
});
};
1 change: 1 addition & 0 deletions plugin/src/xcode/addPbxGroup.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ export function addPbxGroup(
...entitlementFiles,
...plistFiles,
...assetDirectories,
`${targetName}.entitlements`,
],
targetName,
targetName
Expand Down
1 change: 1 addition & 0 deletions plugin/src/xcode/addXCConfigurationList.ts
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ export function addXCConfigurationList(
INFOPLIST_KEY_NSHumanReadableCopyright: `""`,
MARKETING_VERSION: `"${marketingVersion}"`,
SWIFT_OPTIMIZATION_LEVEL: `"-Onone"`,
CODE_SIGN_ENTITLEMENTS: `"${targetName}/${targetName}.entitlements"`,
// DEVELOPMENT_TEAM: `"G76836P2D4"`,
};

Expand Down

0 comments on commit f6a2437

Please sign in to comment.