Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix Expo plugin issues, dependency issues, and stabilize #247

Merged
merged 2 commits into from
Jan 25, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Fix expo plugin
  • Loading branch information
robertjcolley committed Jan 25, 2024
commit 1017210c9076bb5e3f452dc98e62324e1c20f8b4
2 changes: 1 addition & 1 deletion .prettierrc
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"trailingComma": "es5",
"tabWidth": 2,
"semi": false,
"semi": true,
"singleQuote": false
}
2 changes: 0 additions & 2 deletions .reviewboardrc

This file was deleted.

Empty file added __test__/androidXrMode.ts
Empty file.
161 changes: 161 additions & 0 deletions __test__/infoPlistDefined.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,161 @@
import { DEFAULTS } from "../plugins/withViro";

const TEST_TEXT = "This is not the default text.";

export const infoPlistDefinedTestPluginConfigs = [
{
config: [
"@viro-community/react-viro",
{ ios: { photosPermission: TEST_TEXT } },
],
afterInfoPlist: {
NSPhotoLibraryUsageDescription: TEST_TEXT,
NSPhotoLibraryAddUsageDescription: DEFAULTS.ios.savePhotosPermission,
NSCameraUsageDescription: DEFAULTS.ios.cameraUsagePermission,
NSMicrophoneUsageDescription: DEFAULTS.ios.microphoneUsagePermission,
},
},
{
config: [
"@viro-community/react-viro",
{ ios: { savePhotosPermission: TEST_TEXT } },
],
afterInfoPlist: {
NSPhotoLibraryUsageDescription: DEFAULTS.ios.photosPermission,
NSPhotoLibraryAddUsageDescription: TEST_TEXT,
NSCameraUsageDescription: DEFAULTS.ios.cameraUsagePermission,
NSMicrophoneUsageDescription: DEFAULTS.ios.microphoneUsagePermission,
},
},
{
config: [
"@viro-community/react-viro",
{ ios: { cameraUsagePermission: TEST_TEXT } },
],
afterInfoPlist: {
NSPhotoLibraryUsageDescription: DEFAULTS.ios.photosPermission,
NSPhotoLibraryAddUsageDescription: DEFAULTS.ios.savePhotosPermission,
NSCameraUsageDescription: TEST_TEXT,
NSMicrophoneUsageDescription: DEFAULTS.ios.microphoneUsagePermission,
},
},
{
config: [
"@viro-community/react-viro",
{ ios: { microphoneUsagePermission: TEST_TEXT } },
],
afterInfoPlist: {
NSPhotoLibraryUsageDescription: DEFAULTS.ios.photosPermission,
NSPhotoLibraryAddUsageDescription: DEFAULTS.ios.savePhotosPermission,
NSCameraUsageDescription: DEFAULTS.ios.cameraUsagePermission,
NSMicrophoneUsageDescription: TEST_TEXT,
},
},
{
config: [
"@viro-community/react-viro",
{
ios: {
microphoneUsagePermission: TEST_TEXT,
photosPermission: TEST_TEXT,
savePhotosPermission: TEST_TEXT,
cameraUsagePermission: TEST_TEXT,
},
},
],
afterInfoPlist: {
NSPhotoLibraryUsageDescription: TEST_TEXT,
NSPhotoLibraryAddUsageDescription: TEST_TEXT,
NSCameraUsageDescription: TEST_TEXT,
NSMicrophoneUsageDescription: TEST_TEXT,
},
},
];

export const infoPlistDefinedAppConfigBefore: any = {
name: "Example App Config",
slug: "example-app-config",
version: "1.0.0",
orientation: "portrait",
icon: "./assets/images/icon.png",
scheme: "myapp",
userInterfaceStyle: "automatic",
splash: {
image: "./assets/images/splash.png",
resizeMode: "contain",
backgroundColor: "#ffffff",
},
updates: {
fallbackToCacheTimeout: 0,
},
assetBundlePatterns: ["**/*"],
plugins: [],
ios: {
supportsTablet: true,
bundleIdentifier: "com.example.app.config",
buildNumber: `${Math.floor(Number(Date.now() / 1000))}`,
config: {
usesNonExemptEncryption: false,
},
},
android: {
adaptiveIcon: {
foregroundImage: "./assets/images/adaptive-icon.png",
backgroundColor: "#ffffff",
},
package: "com.example.app.config",
versionCode: Math.floor(Number(Date.now() / 1000)),
},
extra: {
eas: {
projectId: "eef69c9f-ddbe-45f2-933a-51ff4f8948b9",
},
},
};

export const infoPlistDefinedAppConfigAfter: any = {
name: "Example App Config",
slug: "example-app-config",
version: "1.0.0",
orientation: "portrait",
icon: "./assets/images/icon.png",
scheme: "myapp",
userInterfaceStyle: "automatic",
splash: {
image: "./assets/images/splash.png",
resizeMode: "contain",
backgroundColor: "#ffffff",
},
updates: {
fallbackToCacheTimeout: 0,
},
assetBundlePatterns: ["**/*"],
plugins: [],
ios: {
supportsTablet: true,
bundleIdentifier: "com.example.app.config",
buildNumber: `${Math.floor(Number(Date.now() / 1000))}`,
config: {
usesNonExemptEncryption: false,
},
infoPlist: {
NSPhotoLibraryUsageDescription: DEFAULTS.ios.photosPermission,
NSPhotoLibraryAddUsageDescription: DEFAULTS.ios.savePhotosPermission,
NSCameraUsageDescription: DEFAULTS.ios.cameraUsagePermission,
NSMicrophoneUsageDescription: DEFAULTS.ios.microphoneUsagePermission,
},
},
android: {
adaptiveIcon: {
foregroundImage: "./assets/images/adaptive-icon.png",
backgroundColor: "#ffffff",
},
package: "com.example.app.config",
versionCode: Math.floor(Number(Date.now() / 1000)),
},
extra: {
eas: {
projectId: "eef69c9f-ddbe-45f2-933a-51ff4f8948b9",
},
},
};
96 changes: 96 additions & 0 deletions __test__/noInfoPlistDefined.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,96 @@
import { DEFAULTS } from "../plugins/withViro";

export const pluginConfigs = [
"@viro-community/react-viro",
["@viro-community/react-viro", { ios: {} }],
["@viro-community/react-viro", { android: { xRMode: ["GVR"] } }],
["@viro-community/react-viro", { android: { xRMode: ["GVR"] }, ios: {} }],
];

export const noInfoPlistDefinitionsAppConfigBefore: any = {
name: "Example App Config",
slug: "example-app-config",
version: "1.0.0",
orientation: "portrait",
icon: "./assets/images/icon.png",
scheme: "myapp",
userInterfaceStyle: "automatic",
splash: {
image: "./assets/images/splash.png",
resizeMode: "contain",
backgroundColor: "#ffffff",
},
updates: {
fallbackToCacheTimeout: 0,
},
assetBundlePatterns: ["**/*"],
plugins: [],
ios: {
supportsTablet: true,
bundleIdentifier: "com.example.app.config",
buildNumber: `${Math.floor(Number(Date.now() / 1000))}`,
config: {
usesNonExemptEncryption: false,
},
},
android: {
adaptiveIcon: {
foregroundImage: "./assets/images/adaptive-icon.png",
backgroundColor: "#ffffff",
},
package: "com.example.app.config",
versionCode: Math.floor(Number(Date.now() / 1000)),
},
extra: {
eas: {
projectId: "eef69c9f-ddbe-45f2-933a-51ff4f8948b9",
},
},
};

export const noInfoPlistDefinitionsAppConfigAfter: any = {
name: "Example App Config",
slug: "example-app-config",
version: "1.0.0",
orientation: "portrait",
icon: "./assets/images/icon.png",
scheme: "myapp",
userInterfaceStyle: "automatic",
splash: {
image: "./assets/images/splash.png",
resizeMode: "contain",
backgroundColor: "#ffffff",
},
updates: {
fallbackToCacheTimeout: 0,
},
assetBundlePatterns: ["**/*"],
plugins: [],
ios: {
supportsTablet: true,
bundleIdentifier: "com.example.app.config",
buildNumber: `${Math.floor(Number(Date.now() / 1000))}`,
config: {
usesNonExemptEncryption: false,
},
infoPlist: {
NSPhotoLibraryUsageDescription: DEFAULTS.ios.photosPermission,
NSPhotoLibraryAddUsageDescription: DEFAULTS.ios.savePhotosPermission,
NSCameraUsageDescription: DEFAULTS.ios.cameraUsagePermission,
NSMicrophoneUsageDescription: DEFAULTS.ios.microphoneUsagePermission,
},
},
android: {
adaptiveIcon: {
foregroundImage: "./assets/images/adaptive-icon.png",
backgroundColor: "#ffffff",
},
package: "com.example.app.config",
versionCode: Math.floor(Number(Date.now() / 1000)),
},
extra: {
eas: {
projectId: "eef69c9f-ddbe-45f2-933a-51ff4f8948b9",
},
},
};
41 changes: 41 additions & 0 deletions __test__/withViro.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
import { describe, expect, test } from "@jest/globals";
import { withDefaultInfoPlist } from "../plugins/withViroIos";
import {
noInfoPlistDefinitionsAppConfigAfter,
noInfoPlistDefinitionsAppConfigBefore,
pluginConfigs,
} from "./noInfoPlistDefined";
import {
infoPlistDefinedAppConfigAfter,
infoPlistDefinedAppConfigBefore,
infoPlistDefinedTestPluginConfigs,
} from "./infoPlistDefined";

describe("withViro", () => {
test("should correctly set InfoPlist config if no InfoPlist values are configured", () => {
for (const configuration of pluginConfigs) {
noInfoPlistDefinitionsAppConfigBefore.plugins = [configuration];
noInfoPlistDefinitionsAppConfigAfter.plugins = [configuration];
expect(
withDefaultInfoPlist(
noInfoPlistDefinitionsAppConfigBefore,
undefined as any
)
).toStrictEqual(noInfoPlistDefinitionsAppConfigAfter);
}
});

test("should correctly set InfoPlist config if InfoPlist values are configured", () => {
for (const scenario of infoPlistDefinedTestPluginConfigs) {
infoPlistDefinedAppConfigBefore.ios.infoPlist = undefined;
infoPlistDefinedAppConfigBefore.plugins = [scenario.config];
infoPlistDefinedAppConfigAfter.plugins = [scenario.config];
infoPlistDefinedAppConfigAfter.ios.infoPlist = scenario.afterInfoPlist;
expect(
withDefaultInfoPlist(infoPlistDefinedAppConfigBefore, undefined as any)
).toStrictEqual(infoPlistDefinedAppConfigAfter);
}
});

// TODO: Testing that withViro updates files correctly (Podfile, Android files, etc.)
});
6 changes: 6 additions & 0 deletions babel.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
module.exports = {
presets: [
['@babel/preset-env', {targets: {node: 'current'}}],
'@babel/preset-typescript',
],
};
25 changes: 21 additions & 4 deletions dist/plugins/withViro.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,19 @@ export type XrMode = "GVR" | "AR" | "OVR_MOBILE";
* Options interface for configuring expo plugin
*/
export interface ViroConfigurationOptions {
ios: {
ios?: {
/**
* String for app to use for camera usage.
*
* DEFAULTS TO: 'Allow $(PRODUCT_NAME) to use your camera'
*/
cameraUsagePermission?: string;
/**
* String for app to use for microphone usage.
*
* DEFAULTS TO: "Allow $(PRODUCT_NAME) to use your microphone"
*/
microphoneUsagePermission?: string;
/**
* String for app to read photos.
*
Expand All @@ -23,14 +30,24 @@ export interface ViroConfigurationOptions {
*/
savePhotosPermission?: string;
};
android: {
xRMode: XrMode[];
android?: {
xRMode?: XrMode[];
};
}
/**
* Default options
*/
export declare const DEFAULTS: ViroConfigurationOptions;
export declare const DEFAULTS: {
ios: {
cameraUsagePermission: string;
microphoneUsagePermission: string;
photosPermission: string;
savePhotosPermission: string;
};
android: {
xRMode: string[];
};
};
/**
* Configures Viro to work with Expo projects.
*
Expand Down
14 changes: 8 additions & 6 deletions dist/plugins/withViro.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,21 +3,23 @@ Object.defineProperty(exports, "__esModule", { value: true });
exports.DEFAULTS = void 0;
const withViroAndroid_1 = require("./withViroAndroid");
const withViroIos_1 = require("./withViroIos");
const CAMERA_USAGE = 'Allow $(PRODUCT_NAME) to use your camera';
const READ_PHOTOS_USAGE = 'Allow $(PRODUCT_NAME) to access your photos';
const WRITE_PHOTOS_USAGE = 'Allow $(PRODUCT_NAME) to save photos';
const CAMERA_USAGE = "Allow $(PRODUCT_NAME) to use your camera";
const MICROPHONE_USAGE = "Allow $(PRODUCT_NAME) to use your microphone";
const READ_PHOTOS_USAGE = "Allow $(PRODUCT_NAME) to access your photos";
const WRITE_PHOTOS_USAGE = "Allow $(PRODUCT_NAME) to save photos";
/**
* Default options
*/
exports.DEFAULTS = {
ios: {
cameraUsagePermission: CAMERA_USAGE,
microphoneUsagePermission: MICROPHONE_USAGE,
photosPermission: READ_PHOTOS_USAGE,
savePhotosPermission: WRITE_PHOTOS_USAGE
savePhotosPermission: WRITE_PHOTOS_USAGE,
},
android: {
xRMode: ["GVR", "AR"]
}
xRMode: ["GVR", "AR"],
},
};
/**
* Configures Viro to work with Expo projects.
Expand Down
Loading