Skip to content

Commit e853b84

Browse files
committed
wip
1 parent c16a391 commit e853b84

29 files changed

+3338
-85
lines changed

lerna.json

+8
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
{
2+
"npmClient": "yarn",
3+
"registry": "https://registry.npmjs.org/",
4+
"useWorkspaces": true,
5+
"version": "independent",
6+
"packages": ["packages/*"]
7+
}
8+

package.json

+6-2
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,17 @@
11
{
22
"private": true,
33
"scripts": {
4-
"postinstall": "expo-yarn-workspaces check-workspace-dependencies"
4+
"postinstall": "expo-yarn-workspaces check-workspace-dependencies",
5+
"start": "lerna run build --parallel -- --watch"
56
},
67
"workspaces": [
78
"apps/*",
89
"packages/*"
910
],
1011
"devDependencies": {
11-
"expo-yarn-workspaces": "^1.5.1"
12+
"expo-yarn-workspaces": "^1.5.1",
13+
"lerna": "3.4.1",
14+
"prettier": "^2.2.1",
15+
"typescript": "^4.2.4"
1216
}
1317
}

packages/detox/build/withDetox.js

+1
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ const withDetox = (config, { skipProguard, subdomains } = {}) => {
3232
};
3333
let pkg = {
3434
name: "detox",
35+
// UNVERSIONED...
3536
};
3637
try {
3738
const detoxPkg = require("detox/package.json");

packages/detox/build/withDetoxTestClass.js

+2-1
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ public class DetoxTest {
7171
/**
7272
* [Step 5](https://github.com/wix/Detox/blob/master/docs/Introduction.Android.md#5-create-a-detox-test-class). Create `DetoxTest.java`
7373
*/
74-
exports.withDetoxTestClass = (config) => {
74+
const withDetoxTestClass = (config) => {
7575
return config_plugins_1.withDangerousMod(config, [
7676
"android",
7777
async (config) => {
@@ -85,3 +85,4 @@ exports.withDetoxTestClass = (config) => {
8585
},
8686
]);
8787
};
88+
exports.withDetoxTestClass = withDetoxTestClass;

packages/detox/build/withNetworkSecurityConfig.js

+2-1
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ const withNetworkSecurityConfigFile = (config, { subdomains }) => {
5959
/**
6060
* [Step 6](https://github.com/wix/Detox/blob/master/docs/Introduction.Android.md#6-enable-clear-text-unencrypted-traffic-for-detox). Link the `network_security_config.xml` file to the `AndroidManifest.xml`.
6161
*/
62-
exports.withNetworkSecurityConfigManifest = (config, props) => {
62+
const withNetworkSecurityConfigManifest = (config, props) => {
6363
if (!props || !props.subdomains) {
6464
// (*) 10.0.2.2 for Google emulators, 10.0.3.2 for Genymotion emulators.
6565
// https://developer.android.com/training/articles/security-config
@@ -73,3 +73,4 @@ exports.withNetworkSecurityConfigManifest = (config, props) => {
7373
return config;
7474
});
7575
};
76+
exports.withNetworkSecurityConfigManifest = withNetworkSecurityConfigManifest;

packages/ios-stickers/build/withStickerAssets.js

+2-1
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ function createSticker({ stickerpackPath, name, imageBuffer, extension, accessib
4444
name: stickerName,
4545
};
4646
}
47-
exports.withStickerAssets = (config, { stickers, icon, size }) => {
47+
const withStickerAssets = (config, { stickers, icon, size }) => {
4848
// Default to using the app icon
4949
if (!icon) {
5050
icon = (config.ios || {}).icon || config.icon;
@@ -118,3 +118,4 @@ exports.withStickerAssets = (config, { stickers, icon, size }) => {
118118
},
119119
]);
120120
};
121+
exports.withStickerAssets = withStickerAssets;

packages/ios-stickers/build/xcodeSticker.d.ts

+3-3
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,8 @@ export declare function addStickersTarget(proj: XcodeProject, name: string, bund
1313
productReference: any;
1414
productType: string;
1515
buildConfigurationList: any;
16-
buildPhases: {};
17-
buildRules: {};
18-
dependencies: {};
16+
buildPhases: never[];
17+
buildRules: never[];
18+
dependencies: never[];
1919
};
2020
};

packages/react-native-ble-plx/build/withBLEAndroidManifest.js

+2-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
Object.defineProperty(exports, "__esModule", { value: true });
44
exports.addBLEHardwareFeatureToManifest = exports.addFineControlPermissionToManifest = exports.withBLEAndroidManifest = void 0;
55
const config_plugins_1 = require("@expo/config-plugins");
6-
exports.withBLEAndroidManifest = (config, { isBackgroundEnabled }) => {
6+
const withBLEAndroidManifest = (config, { isBackgroundEnabled }) => {
77
return config_plugins_1.withAndroidManifest(config, (config) => {
88
config.modResults = addFineControlPermissionToManifest(config.modResults);
99
if (isBackgroundEnabled) {
@@ -12,6 +12,7 @@ exports.withBLEAndroidManifest = (config, { isBackgroundEnabled }) => {
1212
return config;
1313
});
1414
};
15+
exports.withBLEAndroidManifest = withBLEAndroidManifest;
1516
function addFineControlPermissionToManifest(androidManifest) {
1617
var _a;
1718
// Add `<uses-permission-sdk-23 android:name="android.permission.ACCESS_FINE_LOCATION"/>` to the AndroidManifest.xml

packages/react-native-ble-plx/build/withBLEBackgroundModes.js

+2-1
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ const peripheralKey = 'bluetooth-peripheral';
1919
/**
2020
* Append `UIBackgroundModes` to the `Info.plist`.
2121
*/
22-
exports.withBLEBackgroundModes = (c, modes) => {
22+
const withBLEBackgroundModes = (c, modes) => {
2323
return config_plugins_1.withInfoPlist(c, config => {
2424
if (!Array.isArray(config.modResults.UIBackgroundModes)) {
2525
config.modResults.UIBackgroundModes = [];
@@ -37,3 +37,4 @@ exports.withBLEBackgroundModes = (c, modes) => {
3737
return config;
3838
});
3939
};
40+
exports.withBLEBackgroundModes = withBLEBackgroundModes;

packages/react-native-ble-plx/build/withBluetoothAlwaysPermission.js

+2-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
44
exports.withBluetoothAlwaysPermission = void 0;
55
const config_plugins_1 = require("@expo/config-plugins");
66
const BLUETOOTH_ALWAYS = 'Allow $(PRODUCT_NAME) to connect to bluetooth devices';
7-
exports.withBluetoothAlwaysPermission = (c, { bluetoothAlwaysPermission } = {}) => {
7+
const withBluetoothAlwaysPermission = (c, { bluetoothAlwaysPermission } = {}) => {
88
if (bluetoothAlwaysPermission === false) {
99
return c;
1010
}
@@ -14,3 +14,4 @@ exports.withBluetoothAlwaysPermission = (c, { bluetoothAlwaysPermission } = {})
1414
return config;
1515
});
1616
};
17+
exports.withBluetoothAlwaysPermission = withBluetoothAlwaysPermission;

packages/react-native-callkeep/build/withCallkeep.js

+2-1
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@ const withCallkeep = (config) => {
9292
config = withAndroidManifestService(config);
9393
return config;
9494
};
95-
exports.withXcodeLinkBinaryWithLibraries = (config, { library, status }) => {
95+
const withXcodeLinkBinaryWithLibraries = (config, { library, status }) => {
9696
return config_plugins_1.withXcodeProject(config, (config) => {
9797
const options = status === "optional" ? { settings: { ATTRIBUTES: ["Weak"] } } : {};
9898
const target = config_plugins_1.IOSConfig.XcodeUtils.getApplicationNativeTarget({
@@ -106,4 +106,5 @@ exports.withXcodeLinkBinaryWithLibraries = (config, { library, status }) => {
106106
return config;
107107
});
108108
};
109+
exports.withXcodeLinkBinaryWithLibraries = withXcodeLinkBinaryWithLibraries;
109110
exports.default = withCallkeep;
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
// @generated by expo-module-scripts
2+
module.exports = require('expo-module-scripts/eslintrc.base.js');
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
# config-plugins/react-native-google-cast
2+
3+
Config plugin to auto configure react-native-google-cast when the native code is generated (`expo prebuild`).
4+
5+
## Expo installation
6+
7+
> This package cannot be used in the "Expo Go" app because [it requires custom native code](https://docs.expo.io/workflow/customizing/).
8+
> First install the package with yarn, npm, or [`expo install`](https://docs.expo.io/workflow/expo-cli/#expo-install).
9+
10+
```sh
11+
yarn add react-native-google-cast @config-plugins/react-native-google-cast
12+
```
13+
14+
After installing this npm package, add the [config plugin](https://docs.expo.io/guides/config-plugins/) to the [`plugins`](https://docs.expo.io/versions/latest/config/app/#plugins) array of your `app.json` or `app.config.js`:
15+
16+
```json
17+
{
18+
"expo": {
19+
"plugins": ["@config-plugins/react-native-google-cast"]
20+
}
21+
}
22+
```
23+
24+
Next, rebuild your app as described in the ["Adding custom native code"](https://docs.expo.io/workflow/customizing/) guide.
25+
26+
## API
27+
28+
The plugin provides props for extra customization. Every time you change the props or plugins, you'll need to rebuild (and `prebuild`) the native app. If no extra properties are added, defaults will be used.
29+
30+
- `iosReceiverAppId` (_string_): TODO. Default `CC1AD845`
31+
- `androidReceiverAppId` (_string_): TODO.
32+
- `androidPlayServicesCastFrameworkVersion` (_string_): TODO. Default `+`
33+
34+
#### Example
35+
36+
```json
37+
{
38+
"expo": {
39+
"plugins": [
40+
[
41+
"@config-plugins/react-native-google-cast",
42+
{
43+
"iosReceiverAppId": "...",
44+
"androidReceiverAppId": "...",
45+
"androidPlayServicesCastFrameworkVersion": "..."
46+
}
47+
]
48+
]
49+
}
50+
}
51+
```
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
module.exports = require("./build/withGoogleCast");
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
import { ConfigPlugin } from "@expo/config-plugins";
2+
export declare const withAndroidGoogleCast: ConfigPlugin<{
3+
/**
4+
* @default '+'
5+
*/
6+
androidPlayServicesCastFrameworkVersion?: string;
7+
/**
8+
* ??
9+
*/
10+
receiverAppId?: string;
11+
}>;
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,89 @@
1+
"use strict";
2+
var __importDefault = (this && this.__importDefault) || function (mod) {
3+
return (mod && mod.__esModule) ? mod : { "default": mod };
4+
};
5+
Object.defineProperty(exports, "__esModule", { value: true });
6+
exports.withAndroidGoogleCast = void 0;
7+
const config_plugins_1 = require("@expo/config-plugins");
8+
const generateCode_1 = require("@expo/config-plugins/build/utils/generateCode");
9+
const fs_1 = __importDefault(require("fs"));
10+
const { addMetaDataItemToMainApplication, getMainApplicationOrThrow } = config_plugins_1.AndroidConfig.Manifest;
11+
const META_PROVIDER_CLASS = "com.google.android.gms.cast.framework.OPTIONS_PROVIDER_CLASS_NAME";
12+
const META_RECEIVER_APP_ID = "com.reactnative.googlecast.RECEIVER_APPLICATION_ID";
13+
const withAndroidManifestCast = (config, { receiverAppId } = {}) => {
14+
return config_plugins_1.withAndroidManifest(config, (config) => {
15+
const mainApplication = getMainApplicationOrThrow(config.modResults);
16+
addMetaDataItemToMainApplication(mainApplication, META_PROVIDER_CLASS,
17+
// This is the native Java class
18+
"com.reactnative.googlecast.GoogleCastOptionsProvider");
19+
if (receiverAppId) {
20+
addMetaDataItemToMainApplication(mainApplication, META_RECEIVER_APP_ID, receiverAppId);
21+
}
22+
return config;
23+
});
24+
};
25+
const withAppBuildGradleImport = (config, { version }) => {
26+
return config_plugins_1.withAppBuildGradle(config, (config) => {
27+
if (config.modResults.language !== "groovy")
28+
throw new Error("react-native-google-cast config plugin does not support Kotlin app/build.gradle yet.");
29+
config.modResults.contents = addGoogleCastImport(config.modResults.contents, {
30+
version,
31+
}).contents;
32+
return config;
33+
});
34+
};
35+
const withMainActivityLazyLoading = (config) => {
36+
return config_plugins_1.withDangerousMod(config, [
37+
"android",
38+
async (config) => {
39+
const file = await config_plugins_1.AndroidConfig.Paths.getMainActivityAsync(config.modRequest.projectRoot);
40+
if (file.language === "java") {
41+
const src = addGoogleCastLazyLoadingImport(file.contents).contents;
42+
await fs_1.default.promises.writeFile(file.path, src, "utf-8");
43+
}
44+
else {
45+
throw new Error("react-native-google-cast config plugin does not support kotlin MainActivity yet.");
46+
}
47+
return config;
48+
},
49+
]);
50+
};
51+
const withAndroidGoogleCast = (config, props) => {
52+
var _a;
53+
config = withAndroidManifestCast(config, {
54+
receiverAppId: props.receiverAppId,
55+
});
56+
config = withMainActivityLazyLoading(config);
57+
config = withAppBuildGradleImport(config, {
58+
// gradle dep version
59+
version: (_a = props.androidPlayServicesCastFrameworkVersion) !== null && _a !== void 0 ? _a : "+",
60+
});
61+
return config;
62+
};
63+
exports.withAndroidGoogleCast = withAndroidGoogleCast;
64+
function addGoogleCastLazyLoadingImport(src) {
65+
const newSrc = [];
66+
newSrc.push(" CastContext.getSharedInstance(this);");
67+
return generateCode_1.mergeContents({
68+
tag: "react-native-google-cast-onCreate",
69+
src,
70+
newSrc: newSrc.join("\n"),
71+
anchor: /super\.onCreate\(\w+\);/,
72+
offset: 1,
73+
comment: "//",
74+
});
75+
}
76+
// TODO: Add this ability to autolinking
77+
// dependencies { implementation "com.google.android.gms:play-services-cast-framework:+" }
78+
function addGoogleCastImport(src, { version } = {}) {
79+
const newSrc = [];
80+
newSrc.push(` implementation "com.google.android.gms:play-services-cast-framework:${version || "+"}"`);
81+
return generateCode_1.mergeContents({
82+
tag: "react-native-google-cast-dependencies",
83+
src,
84+
newSrc: newSrc.join("\n"),
85+
anchor: /dependencies(?:\s+)?\{/,
86+
offset: 1,
87+
comment: "//",
88+
});
89+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
import { ConfigPlugin } from "@expo/config-plugins";
2+
declare const _default: ConfigPlugin<void | {
3+
/**
4+
* @default '+'
5+
*/
6+
androidPlayServicesCastFrameworkVersion?: string | undefined;
7+
/**
8+
* @default 'CC1AD845'
9+
*/
10+
iosReceiverAppId?: string | undefined;
11+
/**
12+
* ??
13+
*/
14+
androidReceiverAppId?: string | undefined;
15+
}>;
16+
export default _default;
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
"use strict";
2+
Object.defineProperty(exports, "__esModule", { value: true });
3+
const config_plugins_1 = require("@expo/config-plugins");
4+
const withAndroidGoogleCast_1 = require("./withAndroidGoogleCast");
5+
const withIosGoogleCast_1 = require("./withIosGoogleCast");
6+
const withGoogleCast = (config, _props) => {
7+
const props = _props || {};
8+
// TODO: Are the Android and iOS receiverAppId values the same?
9+
config = withIosGoogleCast_1.withIosGoogleCast(config, {
10+
receiverAppId: props.iosReceiverAppId,
11+
// disableDiscoveryAutostart?: boolean;
12+
// startDiscoveryAfterFirstTapOnCastButton?: boolean;
13+
});
14+
config = withAndroidGoogleCast_1.withAndroidGoogleCast(config, {
15+
receiverAppId: props.androidReceiverAppId,
16+
androidPlayServicesCastFrameworkVersion: props.androidPlayServicesCastFrameworkVersion,
17+
});
18+
return config;
19+
};
20+
const pkg = { name: "react-native-google-cast", version: "UNVERSIONED" };
21+
exports.default = config_plugins_1.createRunOncePlugin(withGoogleCast, pkg.name, pkg.version);
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
import { ConfigPlugin } from "@expo/config-plugins";
2+
export declare const withIosGoogleCast: ConfigPlugin<{
3+
/**
4+
* @default 'CC1AD845'
5+
*/
6+
receiverAppId?: string;
7+
}>;

0 commit comments

Comments
 (0)