mirror of
https://github.com/expo/config-plugins.git
synced 2026-11-13 20:28:07 -10:00
Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
99f18da4ed |
No files matched your search
@@ -1,3 +1,10 @@
|
||||
### @config-plugins/react-native-quick-actions [1.0.2](https://github.com/expo/config-plugins/compare/@config-plugins/[email protected]...@config-plugins/[email protected]) (2022-03-22)
|
||||
|
||||
|
||||
### Other chores
|
||||
|
||||
* git ignore build folders ([#59](https://github.com/expo/config-plugins/issues/59)) ([d6050be](https://github.com/expo/config-plugins/commit/d6050beb2a5c68dc59287c27ec388c2002ec7904))
|
||||
|
||||
### @config-plugins/react-native-quick-actions [1.0.1](https://github.com/expo/config-plugins/compare/@config-plugins/[email protected]...@config-plugins/[email protected]) (2022-03-16)
|
||||
|
||||
|
||||
|
||||
+20
@@ -0,0 +1,20 @@
|
||||
import { ConfigPlugin, XML } from "@expo/config-plugins";
|
||||
import { MergeResults } from "@expo/config-plugins/build/utils/generateCode";
|
||||
export declare function addQuickActionsAppDelegateImport(src: string): MergeResults;
|
||||
export declare function addQuickActionsAppDelegateInit(src: string): MergeResults;
|
||||
declare const _default: ConfigPlugin<void | {
|
||||
iconType?: string | undefined;
|
||||
title: string;
|
||||
iconSymbolName?: string | undefined;
|
||||
iconFile?: string | undefined;
|
||||
subtitle?: string | undefined;
|
||||
/**
|
||||
* A unique string that the system passes to your app
|
||||
*/
|
||||
type: string;
|
||||
/**
|
||||
* An optional, app-defined dictionary. One use for this dictionary is to provide app version information, as described in the “App Launch and App Update Considerations for Quick Actions” section of the overview in UIApplicationShortcutItem Class Reference.
|
||||
*/
|
||||
userInfo?: XML.XMLObject | undefined;
|
||||
}[]>;
|
||||
export default _default;
|
||||
+106
@@ -0,0 +1,106 @@
|
||||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.addQuickActionsAppDelegateInit = exports.addQuickActionsAppDelegateImport = void 0;
|
||||
const config_plugins_1 = require("@expo/config-plugins");
|
||||
const generateCode_1 = require("@expo/config-plugins/build/utils/generateCode");
|
||||
const remapping = {
|
||||
iconType: "UIApplicationShortcutItemIconType",
|
||||
iconFile: "UIApplicationShortcutItemIconFile",
|
||||
iconSymbolName: "UIApplicationShortcutItemIconSymbolName",
|
||||
title: "UIApplicationShortcutItemTitle",
|
||||
subtitle: "UIApplicationShortcutItemSubtitle",
|
||||
type: "UIApplicationShortcutItemType",
|
||||
userInfo: "UIApplicationShortcutItemUserInfo",
|
||||
};
|
||||
// #import "RNQuickActionManager.h"
|
||||
// https://github.com/jordanbyron/react-native-quick-actions#adding-static-quick-actions---ios-only
|
||||
// https://developer.apple.com/documentation/uikit/menus_and_shortcuts/add_home_screen_quick_actions
|
||||
// TODO: Auto generate images in asset catalogues
|
||||
/**
|
||||
* Apply react-native-quick-actions configuration for Expo SDK 42 projects.
|
||||
*/
|
||||
const withReactNativeQuickActions = (config, _items) => {
|
||||
config = withQuickActionsAppDelegate(config);
|
||||
const items = _items || [];
|
||||
if (!Array.isArray(items) || !items.length) {
|
||||
return config;
|
||||
}
|
||||
return config_plugins_1.withInfoPlist(config, (config) => {
|
||||
config.modResults.UIApplicationShortcutItems = items.map((item) => {
|
||||
const result = {};
|
||||
for (const [key, value] of Object.entries(remapping)) {
|
||||
// @ts-expect-error
|
||||
const itemValue = item[key];
|
||||
if (itemValue) {
|
||||
result[value] = itemValue;
|
||||
}
|
||||
}
|
||||
return result;
|
||||
});
|
||||
for (const index in config.modResults.UIApplicationShortcutItems) {
|
||||
const item = config.modResults.UIApplicationShortcutItems[index];
|
||||
for (const key of Object.keys(item)) {
|
||||
if (!item[key]) {
|
||||
// @ts-expect-error
|
||||
delete config.modResults.UIApplicationShortcutItems[index][key];
|
||||
}
|
||||
}
|
||||
}
|
||||
return config;
|
||||
});
|
||||
};
|
||||
function addQuickActionsAppDelegateImport(src) {
|
||||
return generateCode_1.mergeContents({
|
||||
tag: "react-native-quick-actions-import",
|
||||
src,
|
||||
newSrc: '#import "RNQuickActionManager.h"',
|
||||
anchor: /#import "AppDelegate\.h"/,
|
||||
offset: 1,
|
||||
comment: "//",
|
||||
});
|
||||
}
|
||||
exports.addQuickActionsAppDelegateImport = addQuickActionsAppDelegateImport;
|
||||
function addQuickActionsAppDelegateInit(src) {
|
||||
const newSrc = [];
|
||||
newSrc.push("- (void)application:(UIApplication *)application performActionForShortcutItem:(UIApplicationShortcutItem *)shortcutItem completionHandler:(void (^)(BOOL succeeded)) completionHandler {", " [RNQuickActionManager onQuickActionPress:shortcutItem completionHandler:completionHandler];", "}");
|
||||
return generateCode_1.mergeContents({
|
||||
tag: "react-native-quick-actions-delegate",
|
||||
src,
|
||||
newSrc: newSrc.join("\n"),
|
||||
anchor: /-\s?\(BOOL\)application:\(UIApplication\s?\*\)application/,
|
||||
offset: 0,
|
||||
comment: "//",
|
||||
});
|
||||
}
|
||||
exports.addQuickActionsAppDelegateInit = addQuickActionsAppDelegateInit;
|
||||
const withQuickActionsAppDelegate = (config) => {
|
||||
return config_plugins_1.withAppDelegate(config, (config) => {
|
||||
if (config.modResults.language === "objc") {
|
||||
try {
|
||||
config.modResults.contents = addQuickActionsAppDelegateImport(config.modResults.contents).contents;
|
||||
config.modResults.contents = addQuickActionsAppDelegateInit(config.modResults.contents).contents;
|
||||
}
|
||||
catch (error) {
|
||||
if (error.code === "ERR_NO_MATCH") {
|
||||
throw new Error(`Cannot add QuickActions to the project's AppDelegate because it's malformed. Please report this with a copy of your project AppDelegate.`);
|
||||
}
|
||||
throw error;
|
||||
}
|
||||
}
|
||||
else {
|
||||
throw new Error("Cannot setup QuickActions because the AppDelegate is not Objective C");
|
||||
}
|
||||
return config;
|
||||
});
|
||||
};
|
||||
const pkg = {
|
||||
// Prevent this plugin from being run more than once.
|
||||
// This pattern enables users to safely migrate off of this
|
||||
// out-of-tree `@config-plugins/react-native-quick-actions` to a future
|
||||
// upstream plugin in `react-native-quick-actions`
|
||||
name: "react-native-quick-actions",
|
||||
// Indicates that this plugin is dangerously linked to a module,
|
||||
// and might not work with the latest version of that module.
|
||||
version: "UNVERSIONED",
|
||||
};
|
||||
exports.default = config_plugins_1.createRunOncePlugin(withReactNativeQuickActions, pkg.name, pkg.version);
|
||||
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "@config-plugins/react-native-quick-actions",
|
||||
"version": "1.0.1",
|
||||
"version": "1.0.2",
|
||||
"description": "Config plugin for react-native-quick-actions package",
|
||||
"main": "build/withReactNativeQuickActions.js",
|
||||
"types": "build/withReactNativeQuickActions.d.ts",
|
||||
|
||||
Reference in new issue
Block a user