feat: Add disableFrameProcessors
flag to Expo Config Plugin (#708)
* feat: disableFrameProcessors for android via expo-config-plugin prop
* chore: naming
* feat: fix shared library issues with expo config plug prop flag
* fix: use a glob pattern instead of listing every single shared lib
* fix: use wildcard since libc++ is not enough (libhermes, libjni, libjsi etc)
* fix: use wildcard since libc++ is not enough (libhermes, libjni, libjsi etc)
* feat: 🎉 disable frame processors for iOS as well
* chore: comments
* chore: make eslint/ts happy
* chore: cleanup
* refactor: no need to pass a param here. We just want to disbale it
* chore: remove withDangerouslyHandleAndroidSharedLibrary
* chore: remove danger plugin
This commit is contained in:
parent
0ce01b9543
commit
17a3430c98
23
src/expo-plugin/withDisableFrameProcessorsAndroid.ts
Normal file
23
src/expo-plugin/withDisableFrameProcessorsAndroid.ts
Normal file
@ -0,0 +1,23 @@
|
|||||||
|
import { ConfigPlugin, withGradleProperties } from '@expo/config-plugins';
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Set the `disableFrameProcessors` value in the static `gradle.properties` file.
|
||||||
|
* This is used to disable frame processors if you don't need it for android.
|
||||||
|
*/
|
||||||
|
export const withDisableFrameProcessorsAndroid: ConfigPlugin = (c) => {
|
||||||
|
const disableFrameProcessorsKey = 'disableFrameProcessors';
|
||||||
|
return withGradleProperties(c, (config) => {
|
||||||
|
config.modResults = config.modResults.filter((item) => {
|
||||||
|
if (item.type === 'property' && item.key === disableFrameProcessorsKey) return false;
|
||||||
|
return true;
|
||||||
|
});
|
||||||
|
|
||||||
|
config.modResults.push({
|
||||||
|
type: 'property',
|
||||||
|
key: disableFrameProcessorsKey,
|
||||||
|
value: 'true',
|
||||||
|
});
|
||||||
|
|
||||||
|
return config;
|
||||||
|
});
|
||||||
|
};
|
33
src/expo-plugin/withDisableFrameProcessorsIOS.ts
Normal file
33
src/expo-plugin/withDisableFrameProcessorsIOS.ts
Normal file
@ -0,0 +1,33 @@
|
|||||||
|
/* eslint-disable @typescript-eslint/no-unsafe-assignment */
|
||||||
|
import { ConfigPlugin, withXcodeProject, XcodeProject } from '@expo/config-plugins';
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Set the `disableFrameProcessors` inside of the XcodeProject.
|
||||||
|
* This is used to disable frame processors if you don't need it on iOS. (will save CPU and Memory)
|
||||||
|
*/
|
||||||
|
export const withDisableFrameProcessorsIOS: ConfigPlugin = (c) => {
|
||||||
|
return withXcodeProject(c, (config) => {
|
||||||
|
const xcodeProject: XcodeProject = config.modResults;
|
||||||
|
|
||||||
|
const configurations = xcodeProject.pbxXCBuildConfigurationSection();
|
||||||
|
let key;
|
||||||
|
let buildSettings;
|
||||||
|
|
||||||
|
const inheritKey = '"$(inherited)"';
|
||||||
|
const valueKey = '"VISION_CAMERA_DISABLE_FRAME_PROCESSORS=1"';
|
||||||
|
|
||||||
|
for (key in configurations) {
|
||||||
|
buildSettings = configurations[key].buildSettings;
|
||||||
|
if (typeof buildSettings?.GCC_PREPROCESSOR_DEFINITIONS !== 'undefined') {
|
||||||
|
// alright, this is the DEBUG config, push our setting to it
|
||||||
|
if (buildSettings.GCC_PREPROCESSOR_DEFINITIONS.includes(valueKey) === false)
|
||||||
|
buildSettings.GCC_PREPROCESSOR_DEFINITIONS.push(valueKey);
|
||||||
|
} else if (typeof buildSettings !== 'undefined') {
|
||||||
|
// new projects do not have GCC_PREPROCESSOR_DEFINITIONS for "Release", lets create it
|
||||||
|
// we need to add the inheritKey or it will break the release build.
|
||||||
|
buildSettings.GCC_PREPROCESSOR_DEFINITIONS = [inheritKey, valueKey];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return config;
|
||||||
|
});
|
||||||
|
};
|
@ -1,4 +1,6 @@
|
|||||||
import { withPlugins, AndroidConfig, ConfigPlugin, createRunOncePlugin } from '@expo/config-plugins';
|
import { withPlugins, AndroidConfig, ConfigPlugin, createRunOncePlugin } from '@expo/config-plugins';
|
||||||
|
import { withDisableFrameProcessorsAndroid } from './withDisableFrameProcessorsAndroid';
|
||||||
|
import { withDisableFrameProcessorsIOS } from './withDisableFrameProcessorsIOS';
|
||||||
// eslint-disable-next-line @typescript-eslint/no-var-requires, @typescript-eslint/no-unsafe-assignment
|
// eslint-disable-next-line @typescript-eslint/no-var-requires, @typescript-eslint/no-unsafe-assignment
|
||||||
const pkg = require('../../../package.json');
|
const pkg = require('../../../package.json');
|
||||||
|
|
||||||
@ -9,6 +11,7 @@ type Props = {
|
|||||||
cameraPermissionText?: string;
|
cameraPermissionText?: string;
|
||||||
enableMicrophonePermission?: boolean;
|
enableMicrophonePermission?: boolean;
|
||||||
microphonePermissionText?: string;
|
microphonePermissionText?: string;
|
||||||
|
disableFrameProcessors?: boolean;
|
||||||
};
|
};
|
||||||
|
|
||||||
const withCamera: ConfigPlugin<Props> = (config, props = {}) => {
|
const withCamera: ConfigPlugin<Props> = (config, props = {}) => {
|
||||||
@ -23,6 +26,11 @@ const withCamera: ConfigPlugin<Props> = (config, props = {}) => {
|
|||||||
const androidPermissions = ['android.permission.CAMERA'];
|
const androidPermissions = ['android.permission.CAMERA'];
|
||||||
if (props.enableMicrophonePermission) androidPermissions.push('android.permission.RECORD_AUDIO');
|
if (props.enableMicrophonePermission) androidPermissions.push('android.permission.RECORD_AUDIO');
|
||||||
|
|
||||||
|
if (props.disableFrameProcessors) {
|
||||||
|
config = withDisableFrameProcessorsAndroid(config);
|
||||||
|
config = withDisableFrameProcessorsIOS(config);
|
||||||
|
}
|
||||||
|
|
||||||
return withPlugins(config, [[AndroidConfig.Permissions.withPermissions, androidPermissions]]);
|
return withPlugins(config, [[AndroidConfig.Permissions.withPermissions, androidPermissions]]);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user