Skip to content

Commit f6a2437

Browse files
authored
Merge pull request #27 from bndkt/v0.0.6-rc
v0.0.6
2 parents ec3f093 + 8ee605b commit f6a2437

File tree

9 files changed

+91
-19
lines changed

9 files changed

+91
-19
lines changed

README.md

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,9 +40,10 @@ startActivity(3, "4343", "$32.23", driverName, 47, 43);
4040
- `frequentUpdates` (boolean, default: false): Depending on this param, NSSupportsLiveActivitiesFrequentUpdates will be set
4141
- `widgetsFolder` (string, default: "widgets"): Path from the project root to the folder containing the Swift widget files
4242
- `deploymentTarget` (string, default: "16.2"): The minimum deployment target for the app
43+
- `groupIdentifier` (string): The app group identifier which is required for communication with the main app. Must start with `group.`
4344
<!--
44-
- moduleFileName (string, default: "Module.swift"): File within the widget folder that defines the native module
45-
- attributesFileName (string): File within the widget folder that defined the widget attributes
45+
- `moduleFileName` (string, default: "Module.swift"): File within the widget folder that defines the native module
46+
- `attributesFileName` (string): File within the widget folder that defined the widget attributes
4647
-->
4748

4849
## Example

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "react-native-widget-extension",
3-
"version": "0.0.5",
3+
"version": "0.0.6",
44
"description": "Expo config plugin to add widgets and live activities to a React Native app",
55
"main": "build/index.js",
66
"types": "build/index.d.ts",

plugin/src/index.ts

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,15 @@ import { withConfig } from "./withConfig";
33
import { withPodfile } from "./withPodfile";
44

55
import { withXcode } from "./withXcode";
6+
import { withWidgetExtensionEntitlements } from "./withWidgetExtensionEntitlements";
67

7-
const withLiveActivities: ConfigPlugin<{
8+
const withWidgetsAndLiveActivities: ConfigPlugin<{
89
frequentUpdates?: boolean;
910
widgetsFolder?: string;
1011
deploymentTarget?: string;
1112
moduleFileName?: string;
1213
attributesFileName?: string;
14+
groupIdentifier?: string;
1315
}> = (
1416
config,
1517
{
@@ -18,6 +20,7 @@ const withLiveActivities: ConfigPlugin<{
1820
deploymentTarget = "16.2",
1921
moduleFileName = "Module.swift",
2022
attributesFileName = "Attributes.swift",
23+
groupIdentifier,
2124
}
2225
) => {
2326
const targetName = `${IOSConfig.XcodeUtils.sanitizedName(
@@ -46,11 +49,12 @@ const withLiveActivities: ConfigPlugin<{
4649
attributesFileName,
4750
},
4851
],
52+
[withWidgetExtensionEntitlements, { targetName, groupIdentifier }],
4953
[withPodfile, { targetName }],
50-
[withConfig, { targetName, bundleIdentifier }],
54+
[withConfig, { targetName, bundleIdentifier, groupIdentifier }],
5155
]);
5256

5357
return config;
5458
};
5559

56-
export default withLiveActivities;
60+
export default withWidgetsAndLiveActivities;
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
import { ExportedConfig, InfoPlist } from "@expo/config-plugins";
2+
3+
export function getWidgetExtensionEntitlements(
4+
iosConfig: ExportedConfig["ios"],
5+
{
6+
groupIdentifier,
7+
}: {
8+
groupIdentifier?: string;
9+
}
10+
) {
11+
const entitlements: InfoPlist = {};
12+
13+
addApplicationGroupsEntitlement(entitlements, groupIdentifier);
14+
15+
return entitlements;
16+
}
17+
18+
export function addApplicationGroupsEntitlement(entitlements: InfoPlist, groupIdentifier?: string) {
19+
if (groupIdentifier) {
20+
const existingApplicationGroups = (entitlements["com.apple.security.application-groups"] as string[]) ?? [];
21+
22+
entitlements["com.apple.security.application-groups"] = [groupIdentifier, ...existingApplicationGroups];
23+
}
24+
25+
return entitlements;
26+
}

plugin/src/withConfig.ts

Lines changed: 23 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,18 @@
11
import { ConfigPlugin } from "@expo/config-plugins";
22

3+
import { addApplicationGroupsEntitlement, getWidgetExtensionEntitlements } from "./lib/getWidgetExtensionEntitlements";
4+
35
export const withConfig: ConfigPlugin<{
46
bundleIdentifier: string;
57
targetName: string;
6-
}> = (config, { bundleIdentifier, targetName }) => {
8+
groupIdentifier?: string;
9+
}> = (config, { bundleIdentifier, targetName, groupIdentifier }) => {
710
let configIndex: null | number = null;
8-
config.extra?.eas?.build?.experimental?.ios?.appExtensions?.forEach(
9-
(ext: any, index: number) => {
10-
if (ext.targetName === targetName) {
11-
configIndex = index;
12-
}
11+
config.extra?.eas?.build?.experimental?.ios?.appExtensions?.forEach((ext: any, index: number) => {
12+
if (ext.targetName === targetName) {
13+
configIndex = index;
1314
}
14-
);
15+
});
1516

1617
if (!configIndex) {
1718
config.extra = {
@@ -25,8 +26,7 @@ export const withConfig: ConfigPlugin<{
2526
ios: {
2627
...config.extra?.eas?.build?.experimental?.ios,
2728
appExtensions: [
28-
...(config.extra?.eas?.build?.experimental?.ios
29-
?.appExtensions ?? []),
29+
...(config.extra?.eas?.build?.experimental?.ios?.appExtensions ?? []),
3030
{
3131
targetName,
3232
bundleIdentifier,
@@ -41,10 +41,21 @@ export const withConfig: ConfigPlugin<{
4141
}
4242

4343
if (configIndex != null && config.extra) {
44-
const appClipConfig =
45-
config.extra.eas.build.experimental.ios.appExtensions[configIndex];
44+
const widgetsExtensionConfig = config.extra.eas.build.experimental.ios.appExtensions[configIndex];
45+
46+
widgetsExtensionConfig.entitlements = {
47+
...widgetsExtensionConfig.entitlements,
48+
...getWidgetExtensionEntitlements(config.ios, {
49+
groupIdentifier,
50+
}),
51+
};
4652

47-
appClipConfig.entitlements = {};
53+
config.ios = {
54+
...config.ios,
55+
entitlements: {
56+
...addApplicationGroupsEntitlement(config.ios?.entitlements ?? {}, groupIdentifier),
57+
},
58+
};
4859
}
4960

5061
return config;

plugin/src/withPodfile.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,8 @@ export const withPodfile: ConfigPlugin<{ targetName: string }> = (
3535
src: podFileContent,
3636
newSrc: `installer.pods_project.targets.each do |target|
3737
target.build_configurations.each do |config|
38-
config.build_settings['APPLICATION_EXTENSION_API_ONLY'] = 'No'
38+
# Sentry has build errors unless configured as 'YES' for the Sentry target: https://github.com/bndkt/react-native-widget-extension/issues/24
39+
config.build_settings['APPLICATION_EXTENSION_API_ONLY'] = target.name == 'Sentry' ? 'YES' : 'No'
3940
end
4041
end`,
4142
anchor:
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
import plist from "@expo/plist";
2+
import { ConfigPlugin, withInfoPlist } from "@expo/config-plugins";
3+
import * as fs from "fs";
4+
import * as path from "path";
5+
6+
import { getWidgetExtensionEntitlements } from "./lib/getWidgetExtensionEntitlements";
7+
8+
export const withWidgetExtensionEntitlements: ConfigPlugin<{
9+
targetName: string;
10+
targetPath: string;
11+
groupIdentifier: string;
12+
appleSignin: boolean;
13+
}> = (config, { targetName, groupIdentifier }) => {
14+
return withInfoPlist(config, (config) => {
15+
const targetPath = path.join(config.modRequest.platformProjectRoot, targetName);
16+
const filePath = path.join(targetPath, `${targetName}.entitlements`);
17+
18+
const appClipEntitlements = getWidgetExtensionEntitlements(config.ios, {
19+
groupIdentifier,
20+
});
21+
22+
fs.mkdirSync(path.dirname(filePath), { recursive: true });
23+
fs.writeFileSync(filePath, plist.build(appClipEntitlements));
24+
25+
return config;
26+
});
27+
};

plugin/src/xcode/addPbxGroup.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ export function addPbxGroup(
3030
...entitlementFiles,
3131
...plistFiles,
3232
...assetDirectories,
33+
`${targetName}.entitlements`,
3334
],
3435
targetName,
3536
targetName

plugin/src/xcode/addXCConfigurationList.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@ export function addXCConfigurationList(
5252
INFOPLIST_KEY_NSHumanReadableCopyright: `""`,
5353
MARKETING_VERSION: `"${marketingVersion}"`,
5454
SWIFT_OPTIMIZATION_LEVEL: `"-Onone"`,
55+
CODE_SIGN_ENTITLEMENTS: `"${targetName}/${targetName}.entitlements"`,
5556
// DEVELOPMENT_TEAM: `"G76836P2D4"`,
5657
};
5758

0 commit comments

Comments
 (0)