@react-native-tvos/config-tv 0.0.3 → 0.0.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -37,7 +37,8 @@ or
37
37
  {
38
38
  "isTV": true,
39
39
  "showVerboseWarnings": false,
40
- "tvosDeploymentTarget": "13.4"
40
+ "tvosDeploymentTarget": "13.4",
41
+ "removeFlipperOnAndroid": true
41
42
  }
42
43
  ]
43
44
  ]
@@ -52,6 +53,7 @@ _Plugin parameters_:
52
53
  - `isTV`: (optional boolean, default false) If true, prebuild should generate or modify Android and iOS files to build for TV (Android TV and Apple TV). If false, the default phone-appropriate files should be generated, and if existing files contain TV changes, they will be reverted. Setting the environment variable EXPO_TV to "true" or "1" will override this value and force a TV build.
53
54
  - `showVerboseWarnings`: (optional boolean, default false) If true, verbose warnings will be shown during plugin execution.
54
55
  - `tvosDeploymentTarget`: (optional string, default '13.4') Used to set the tvOS deployment target version in the Xcode project.
56
+ - `removeFlipperOnAndroid`: (optional boolean, default true) Used to remove the Flipper dependency from `MainApplication.kt` (or `MainApplication.java`) and `android/app/build.gradle`. This is necessary for React Native TV 0.73 and higher, since Flipper integration is removed from these versions. If this causes issues, set the value to false, run `prebuild --clean` again, and then remove Flipper from your Android source manually.
55
57
 
56
58
  _Warning_:
57
59
 
@@ -60,7 +62,7 @@ When this plugin is used to generate files in the iOS directory that build an Ap
60
62
  ```json
61
63
  {
62
64
  "dependencies": {
63
- "react-native": "npm:react-native-tvos@^0.72.5-0"
65
+ "react-native": "npm:react-native-tvos@^0.72.6-1"
64
66
  }
65
67
  }
66
68
  ```
package/build/types.d.ts CHANGED
@@ -3,15 +3,19 @@ export type ConfigData = {
3
3
  * If true, prebuild should generate Android and iOS files for TV (Android TV and Apple TV).
4
4
  * If false, the default phone-appropriate files should be generated.
5
5
  * Setting the environment variable EXPO_TV to "true" or "1" will override
6
- * this value.
6
+ * this value. (Defaults to false.)
7
7
  */
8
8
  isTV?: boolean;
9
9
  /**
10
- * If true, verbose warnings will be shown during plugin execution.
10
+ * If true, verbose warnings will be shown during plugin execution. (Defaults to false.)
11
11
  */
12
12
  showVerboseWarnings?: boolean;
13
13
  /**
14
14
  * If set, this will be used as the tvOS deployment target version instead of the default (13.4).
15
15
  */
16
16
  tvosDeploymentTarget?: string;
17
+ /**
18
+ * If set, Android code that references Flipper will be removed. (Defaults to true.)
19
+ */
20
+ removeFlipperOnAndroid?: boolean;
17
21
  };
package/build/utils.d.ts CHANGED
@@ -2,3 +2,4 @@ import { ConfigData } from './types';
2
2
  export declare function isTVEnabled(params: ConfigData): boolean;
3
3
  export declare function showVerboseWarnings(params: ConfigData): boolean;
4
4
  export declare function tvosDeploymentTarget(params: ConfigData): string;
5
+ export declare function shouldRemoveFlipperOnAndroid(params: ConfigData): boolean;
package/build/utils.js CHANGED
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.tvosDeploymentTarget = exports.showVerboseWarnings = exports.isTVEnabled = void 0;
3
+ exports.shouldRemoveFlipperOnAndroid = exports.tvosDeploymentTarget = exports.showVerboseWarnings = exports.isTVEnabled = void 0;
4
4
  const getenv_1 = require("getenv");
5
5
  class Env {
6
6
  /** Enable prebuild for TV */
@@ -22,3 +22,7 @@ function tvosDeploymentTarget(params) {
22
22
  return params?.tvosDeploymentTarget ?? defaultTvosDeploymentVersion;
23
23
  }
24
24
  exports.tvosDeploymentTarget = tvosDeploymentTarget;
25
+ function shouldRemoveFlipperOnAndroid(params) {
26
+ return params?.removeFlipperOnAndroid ?? true;
27
+ }
28
+ exports.shouldRemoveFlipperOnAndroid = shouldRemoveFlipperOnAndroid;
package/build/withTV.d.ts CHANGED
@@ -1,4 +1,4 @@
1
- import { ConfigPlugin } from "expo/config-plugins";
2
- import { ConfigData } from "./types";
1
+ import { ConfigPlugin } from 'expo/config-plugins';
2
+ import { ConfigData } from './types';
3
3
  declare const _default: ConfigPlugin<ConfigData>;
4
4
  export default _default;
package/build/withTV.js CHANGED
@@ -5,12 +5,14 @@ const withTVAndroidManifest_1 = require("./withTVAndroidManifest");
5
5
  const withTVPodfile_1 = require("./withTVPodfile");
6
6
  const withTVSplashScreen_1 = require("./withTVSplashScreen");
7
7
  const withTVXcodeProject_1 = require("./withTVXcodeProject");
8
+ const withTVAndroidRemoveFlipper_1 = require("./withTVAndroidRemoveFlipper");
8
9
  const withTVPlugin = (config, params = {}) => {
9
10
  config = (0, withTVXcodeProject_1.withTVXcodeProject)(config, params);
10
11
  config = (0, withTVPodfile_1.withTVPodfile)(config, params);
11
12
  config = (0, withTVSplashScreen_1.withTVSplashScreen)(config, params);
12
13
  config = (0, withTVAndroidManifest_1.withTVAndroidManifest)(config, params);
14
+ config = (0, withTVAndroidRemoveFlipper_1.withTVAndroidRemoveFlipper)(config, params);
13
15
  return config;
14
16
  };
15
- const pkg = require("../package.json");
17
+ const pkg = require('../package.json');
16
18
  exports.default = (0, config_plugins_1.createRunOncePlugin)(withTVPlugin, pkg.name, pkg.version);
@@ -0,0 +1,4 @@
1
+ import { ConfigPlugin } from 'expo/config-plugins';
2
+ import { ConfigData } from './types';
3
+ /** Dangerously makes or reverts TV changes in the project Podfile. */
4
+ export declare const withTVAndroidRemoveFlipper: ConfigPlugin<ConfigData>;
@@ -0,0 +1,65 @@
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.withTVAndroidRemoveFlipper = void 0;
7
+ const config_plugins_1 = require("expo/config-plugins");
8
+ const fs_1 = require("fs");
9
+ const glob_1 = __importDefault(require("glob"));
10
+ const path_1 = __importDefault(require("path"));
11
+ const utils_1 = require("./utils");
12
+ const pkg = require('../package.json');
13
+ /** Dangerously makes or reverts TV changes in the project Podfile. */
14
+ const withTVAndroidRemoveFlipper = (c, params = {}) => {
15
+ const isTV = (0, utils_1.isTVEnabled)(params);
16
+ const verbose = (0, utils_1.showVerboseWarnings)(params);
17
+ const androidRemoveFlipper = (0, utils_1.shouldRemoveFlipperOnAndroid)(params);
18
+ return (0, config_plugins_1.withDangerousMod)(c, [
19
+ 'android',
20
+ // eslint-disable-next-line @typescript-eslint/explicit-function-return-type
21
+ async (config) => {
22
+ if (isTV && androidRemoveFlipper) {
23
+ // Modify main application
24
+ const mainApplicationFile = mainApplicationFilePath(config.modRequest.platformProjectRoot);
25
+ if (verbose) {
26
+ config_plugins_1.WarningAggregator.addWarningAndroid('source', `${pkg.name}@${pkg.version}: removing Flipper from MainApplication file`);
27
+ }
28
+ const mainApplicationContents = await fs_1.promises.readFile(mainApplicationFile, 'utf8');
29
+ const mainApplicationModifiedContents = commentOutLinesWithString(mainApplicationContents, 'Flipper');
30
+ await fs_1.promises.writeFile(mainApplicationFile, mainApplicationModifiedContents, 'utf-8');
31
+ // Modify app/build.gradle
32
+ const buildGradleFile = appBuildGradleFilePath(config.modRequest.platformProjectRoot);
33
+ if (verbose) {
34
+ config_plugins_1.WarningAggregator.addWarningAndroid('source', `${pkg.name}@${pkg.version}: removing Flipper from android/app/build.gradle`);
35
+ }
36
+ const buildGradleContents = await fs_1.promises.readFile(buildGradleFile, 'utf-8');
37
+ const buildGradleModifiedContents = commentOutLinesWithString(buildGradleContents, 'flipper');
38
+ await fs_1.promises.writeFile(buildGradleFile, buildGradleModifiedContents, 'utf-8');
39
+ }
40
+ return config;
41
+ },
42
+ ]);
43
+ };
44
+ exports.withTVAndroidRemoveFlipper = withTVAndroidRemoveFlipper;
45
+ const mainApplicationFilePath = (androidRoot) => {
46
+ const paths = glob_1.default.sync(`${androidRoot}/**/MainApplication.*`);
47
+ if (paths.length > 0) {
48
+ return paths[0];
49
+ }
50
+ else {
51
+ throw new Error('AndroidApplication path not found');
52
+ }
53
+ };
54
+ const appBuildGradleFilePath = (androidRoot) => path_1.default.resolve(androidRoot, 'app', 'build.gradle');
55
+ const commentOutLinesWithString = (contents, searchString) => {
56
+ return contents
57
+ .split('\n')
58
+ .map((line) => {
59
+ if (line.indexOf(searchString) !== -1) {
60
+ return line.replace(/^/, '// ');
61
+ }
62
+ return line;
63
+ })
64
+ .join('\n');
65
+ };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@react-native-tvos/config-tv",
3
- "version": "0.0.3",
3
+ "version": "0.0.4",
4
4
  "description": "Config plugin to reconfigure native directories for Apple TV and Android TV development if needed",
5
5
  "main": "build/withTV.js",
6
6
  "types": "build/withTV.d.ts",
@@ -34,7 +34,7 @@
34
34
  "react-native-tvos"
35
35
  ],
36
36
  "peerDependencies": {
37
- "expo": "^50.0.0.alpha.5"
37
+ "expo": "^50.0.0-alpha.7"
38
38
  },
39
39
  "devDependencies": {
40
40
  "@types/getenv": "^1.0.1",