Skip to content

Commit

Permalink
feat(ios-stickers): custom id for sticker project (#150)
Browse files Browse the repository at this point in the history
  • Loading branch information
xseignard committed Dec 15, 2022
1 parent b862911 commit 72da275
Show file tree
Hide file tree
Showing 18 changed files with 166 additions and 144 deletions.
1 change: 1 addition & 0 deletions apps/ios-stickers/app.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
"@config-plugins/ios-stickers",
{
"name": "Stickers",
"stickerBundleId": "dev.bacon.iosstickers.stickers",
"icon": "./assets/imessage-icon.png",
"columns": 4,
"stickers": [
Expand Down
4 changes: 2 additions & 2 deletions apps/ios-stickers/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@
},
"dependencies": {
"@config-plugins/ios-stickers": "*",
"expo": "~47.0.3",
"expo-splash-screen": "~0.17.4",
"expo": "~47.0.8",
"expo-splash-screen": "~0.17.5",
"expo-status-bar": "~1.4.2",
"react": "18.1.0",
"react-dom": "18.1.0",
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
"@expo/package-manager": "^0.0.43",
"@types/js-yaml": "^4.0.5",
"@types/prompts": "^2.0.13",
"eslint": "^7.25.0",
"eslint": "^8.10.0",
"expo-yarn-workspaces": "^2.0.2",
"js-yaml": "^4.1.0",
"lerna": "3.4.1",
Expand Down
2 changes: 2 additions & 0 deletions packages/ios-stickers/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ In your app.json `plugins` array:
{
"name": "Stickers!",
"icon": "./assets/imessage-icon.png",
"stickerBundleId": "dev.bacon.iosstickers.stickers",
"columns": 4,
"stickers": [
"./assets/stickers/annoyed.png",
Expand All @@ -39,6 +40,7 @@ In your app.json `plugins` array:
```

- `name`: defaults to the iOS app name
- `stickerBundleId`: custom bundle identifier for the stickers project, if not provided, it will defaults to `${ios.bundleIdentifier}.${name}-Stickers` given your expo config values.
- `icon`: defaults to the iOS app icon
- `columns`: number of stickers to render, defaults to `3`. Can be one of `2`, `3`, `4`.
- `stickers`: local file paths or remote URLs, or `{ image: "...", name: "...", accessibilityLabel: "..." }`. Order is preserved.
3 changes: 3 additions & 0 deletions packages/ios-stickers/build/options.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions packages/ios-stickers/build/withStickerAssets.d.ts

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions packages/ios-stickers/build/withStickerPack.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion packages/ios-stickers/build/withStickerXcodeTarget.d.ts

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions packages/ios-stickers/build/withStickerXcodeTarget.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion packages/ios-stickers/build/xcodeSticker.d.ts

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 4 additions & 2 deletions packages/ios-stickers/build/xcodeSticker.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ describe(withStickerPack, () => {
expect(() =>
withStickerPack(exp, {
name: "test",
stickerBundleId: "test",
stickers: [{ image: "test.png" }],
columns: 2,
icon: "test.png",
Expand Down
3 changes: 3 additions & 0 deletions packages/ios-stickers/src/options.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,9 @@
"name": {
"type": "string"
},
"stickerBundleId": {
"type": "string"
},
"columns": {
"type": "number",
"enum": [
Expand Down
1 change: 1 addition & 0 deletions packages/ios-stickers/src/withStickerAssets.ts
Original file line number Diff line number Diff line change
Expand Up @@ -221,5 +221,6 @@ export type Props = {
stickers?: (string | Sticker)[];
icon?: string;
name?: string;
stickerBundleId?: string;
columns?: 2 | 3 | 4;
};
4 changes: 2 additions & 2 deletions packages/ios-stickers/src/withStickerPack.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ const withStickerPack: ConfigPlugin<Props> = (config, options = {}) => {
// Perform option validation.
validate(schema as any, options);

const { stickers, icon, name, columns = 3 } = options;
const { stickers, icon, name, stickerBundleId, columns = 3 } = options;

const size = sizeColumnMap[columns] || "regular";
if (!size) {
Expand All @@ -50,7 +50,7 @@ const withStickerPack: ConfigPlugin<Props> = (config, options = {}) => {

config = withStickersPlist(config, { name });
config = withStickerAssets(config, { stickers: _stickers, icon, size });
config = withStickerXcodeTarget(config);
config = withStickerXcodeTarget(config, { stickerBundleId });
return config;
};

Expand Down
8 changes: 6 additions & 2 deletions packages/ios-stickers/src/withStickerXcodeTarget.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { ConfigPlugin, withXcodeProject } from "@expo/config-plugins";

import { Props } from "./withStickerAssets";
import {
addStickerResourceFile,
addStickersTarget,
Expand All @@ -12,7 +13,9 @@ export function getProjectStickersName(name: string) {
return `${name} Stickers`;
}

export const withStickerXcodeTarget: ConfigPlugin = (config) => {
export const withStickerXcodeTarget: ConfigPlugin<
Pick<Props, "stickerBundleId">
> = (config, { stickerBundleId }) => {
return withXcodeProject(config, (config) => {
const stickerPackName = getProjectStickersName(
config.modRequest.projectName!
Expand All @@ -22,7 +25,8 @@ export const withStickerXcodeTarget: ConfigPlugin = (config) => {
config.modResults,
stickerPackName,
config.ios!.bundleIdentifier!,
stickerPackName
stickerPackName,
stickerBundleId
);

const stickersKey = addStickerResourceFile(
Expand Down
8 changes: 6 additions & 2 deletions packages/ios-stickers/src/xcodeSticker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,8 @@ export function addStickersTarget(
proj: XcodeProject,
name: string,
bundleId: string,
subfolder: string
subfolder: string,
stickerBundleId?: string
) {
// Setup uuid and name of new target
const targetUuid = proj.generateUuid();
Expand All @@ -111,7 +112,10 @@ export function addStickersTarget(
throw new Error("Target type invalid: " + targetType);
}

const PRODUCT_BUNDLE_IDENTIFIER = `"${bundleId}.${bundleName}"`;
// Either use the given bundleId for the stickers or
// generate one from the app bundleId and stickers project folder
const PRODUCT_BUNDLE_IDENTIFIER =
stickerBundleId ?? `"${bundleId}.${bundleName}"`;
const INFOPLIST_FILE = `"${subfolder}/Info.plist"`;

const commonBuildSettings = {
Expand Down
Loading

0 comments on commit 72da275

Please sign in to comment.