Skip to content

Commit 6b7b518

Browse files
author
Robert Colley
authored
Add VR AndroidManifest injection (#104)
* Add VR AndroidManifest injection https://viro-community.readme.io/docs/installation-instructions#for-vr * v2.23.0
1 parent bd2950e commit 6b7b518

File tree

3 files changed

+54
-13
lines changed

3 files changed

+54
-13
lines changed

dist/plugins/withViroAndroid.js

Lines changed: 23 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ const config_plugins_1 = require("@expo/config-plugins");
88
const fs_1 = __importDefault(require("fs"));
99
const path_1 = __importDefault(require("path"));
1010
const insertLinesHelper_1 = require("./util/insertLinesHelper");
11+
let viroPluginConfig = ["AR"];
1112
const withBranchAndroid = (config, props) => {
1213
// Directly edit MainApplication.java
1314
config = (0, config_plugins_1.withDangerousMod)(config, [
@@ -36,6 +37,7 @@ const withBranchAndroid = (config, props) => {
3637
*
3738
* ********************************************************************
3839
* Sample app.json with multiple options for Viro config
40+
* The default configuration is "AR"
3941
* ********************************************************************
4042
* plugins: [
4143
* [
@@ -47,15 +49,12 @@ const withBranchAndroid = (config, props) => {
4749
* ],
4850
* ********************************************************************
4951
* Sample app.json without property config
50-
* The default configuration is "AR"
5152
* ********************************************************************
5253
*
5354
* plugins: [ "@viro-community/react-viro" ],
5455
*
5556
*/
5657
const viroPlugin = config?.plugins?.find((plugin) => Array.isArray(plugin) && plugin[0] === "@viro-community/react-viro");
57-
console.log("viroPlugin", viroPlugin);
58-
let viroPluginConfig = ["AR"];
5958
if (Array.isArray(viroPlugin)) {
6059
if (Array.isArray(viroPlugin[1].androidXrMode)) {
6160
viroPluginConfig = viroPlugin[1].androidXrMode.filter((mode) => ["AR", "GVR", "OVR_MOBILE"].includes(mode));
@@ -64,14 +63,12 @@ const withBranchAndroid = (config, props) => {
6463
viroPluginConfig = [viroPlugin[1]?.androidXrMode];
6564
}
6665
}
67-
console.log("viroPluginConfig", viroPluginConfig);
6866
let target = "";
6967
for (const viroConfig of viroPluginConfig) {
7068
target =
7169
target +
7270
` packages.add(new ReactViroPackage(ReactViroPackage.ViroPlatform.valueOf("${viroConfig}")));\n`;
7371
}
74-
console.log("target", target);
7572
data = (0, insertLinesHelper_1.insertLinesHelper)(target, "List<ReactPackage> packages = new PackageList(this).getPackages();", data);
7673
fs_1.default.writeFile(mainApplicationPath, data, "utf-8", function (err) {
7774
if (err)
@@ -118,6 +115,27 @@ const withViroManifest = (config) => (0, config_plugins_1.withAndroidManifest)(c
118115
"android:value": "optional",
119116
},
120117
});
118+
if (viroPluginConfig.includes("GVR") ||
119+
viroPluginConfig.includes("OVR_MOBILE")) {
120+
console.log(contents?.manifest?.application?.[0]?.activity[0]["intent-filter"][0]
121+
.category);
122+
// <!-- Add the following line for cardboard -->
123+
// <category android:name="com.google.intent.category.CARDBOARD" />
124+
contents?.manifest?.application?.[0]?.activity[0]["intent-filter"][0].category.push({
125+
$: {
126+
"android:name": "com.google.intent.category.CARDBOARD",
127+
},
128+
});
129+
// <!-- Add the following line for daydream -->
130+
// <category android:name="com.google.intent.category.DAYDREAM" />
131+
contents?.manifest?.application?.[0]?.activity[0]["intent-filter"][0].category.push({
132+
$: {
133+
"android:name": "com.google.intent.category.DAYDREAM",
134+
},
135+
});
136+
console.log(contents?.manifest?.application?.[0]?.activity[0]["intent-filter"][0]
137+
.category);
138+
}
121139
contents.manifest.queries = [
122140
{
123141
package: [

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
"main": "dist/index.js",
44
"module": "dist/index.js",
55
"types": "dist/index.d.ts",
6-
"version": "2.22.0",
6+
"version": "2.23.0",
77
"license": "MIT",
88
"publishConfig": {
99
"registry": "https://registry.npmjs.org/"

plugins/withViroAndroid.ts

Lines changed: 30 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,20 @@
11
import {
2-
withPlugins,
3-
withDangerousMod,
42
ConfigPlugin,
3+
ExportedConfigWithProps,
54
withAndroidManifest,
5+
withAppBuildGradle,
6+
withDangerousMod,
7+
withPlugins,
68
withProjectBuildGradle,
79
withSettingsGradle,
8-
ExportedConfigWithProps,
9-
withAppBuildGradle,
1010
} from "@expo/config-plugins";
11-
import { Manifest } from "@expo/config-plugins/build/android";
12-
import { GradleProjectFile } from "@expo/config-plugins/build/android/Paths";
1311
import { ExpoConfig } from "@expo/config-types";
1412
import fs from "fs";
1513
import path from "path";
1614
import { insertLinesHelper } from "./util/insertLinesHelper";
1715

16+
let viroPluginConfig = ["AR"];
17+
1818
const withBranchAndroid = (config: ExpoConfig, props: any) => {
1919
// Directly edit MainApplication.java
2020
config = withDangerousMod(config, [
@@ -80,7 +80,6 @@ const withBranchAndroid = (config: ExpoConfig, props: any) => {
8080
Array.isArray(plugin) && plugin[0] === "@viro-community/react-viro"
8181
);
8282

83-
let viroPluginConfig = ["AR"];
8483
if (Array.isArray(viroPlugin)) {
8584
if (Array.isArray(viroPlugin[1].androidXrMode)) {
8685
viroPluginConfig = (viroPlugin[1].androidXrMode as string[]).filter(
@@ -173,6 +172,30 @@ const withViroManifest = (config: ExpoConfig) =>
173172
},
174173
});
175174

175+
if (
176+
viroPluginConfig.includes("GVR") ||
177+
viroPluginConfig.includes("OVR_MOBILE")
178+
) {
179+
// <!-- Add the following line for cardboard -->
180+
// <category android:name="com.google.intent.category.CARDBOARD" />
181+
contents?.manifest?.application?.[0]?.activity[0][
182+
"intent-filter"
183+
][0].category.push({
184+
$: {
185+
"android:name": "com.google.intent.category.CARDBOARD",
186+
},
187+
});
188+
// <!-- Add the following line for daydream -->
189+
// <category android:name="com.google.intent.category.DAYDREAM" />
190+
contents?.manifest?.application?.[0]?.activity[0][
191+
"intent-filter"
192+
][0].category.push({
193+
$: {
194+
"android:name": "com.google.intent.category.DAYDREAM",
195+
},
196+
});
197+
}
198+
176199
contents.manifest.queries = [
177200
{
178201
package: [

0 commit comments

Comments
 (0)