Repository: microsoft/react-native-test-app
Pull request #1126 (2022-09-20 12:17:09)

hackathon: react-native-viewfinder
### Description

This is a Fix, Hack, Learn (FHL) project.

### Blocked by

- https://github.com/microsoft/react-native-test-app/pull/1124
- https://github.com/microsoft/react-native-test-app/pull/1125
- https://github.com/microsoft/rnx-kit/pull/1894
- https://github.com/microsoft/react-native-test-app/pull/1127

### Platforms affected

- [x] Android
- [x] iOS
- [ ] macOS
- [ ] Windows

### Test plan

```
yarn
node scripts/prepare-viewfinder.mjs
cd example

# Android
yarn build:android
yarn android

# iOS
yarn build:ios
pod install --project-directory=ios
yarn ios
```

| Android | iOS |
| :-----: | :-: |
| ![device-2022-09-21-165034](https://user-images.githubusercontent.com/4123478/191537395-b3beb6ca-499d-412c-ba7d-86220ffdb593.gif) | ![RPReplay_Final1663675736](https://user-images.githubusercontent.com/4123478/191255084-53bdbee8-7eb4-44a7-9f62-4990e9f6364e.gif) |


Patch:
diff --git a/.github/renovate.json b/.github/renovate.json
index 448e7ec..096a19f 100644
--- a/.github/renovate.json
+++ b/.github/renovate.json
@@ -15,6 +15,11 @@
       "matchDatasources": ["maven"],
       "matchPackagePrefixes": ["com.android."]
     },
+    {
+      "groupName": "Android CameraX",
+      "matchDatasources": ["maven"],
+      "matchPackagePrefixes": ["androidx.camera"]
+    },
     {
       "groupName": "Kotlin",
       "matchDatasources": ["maven"],
diff --git a/android/dependencies.gradle b/android/dependencies.gradle
index 178544b..0458de3 100644
--- a/android/dependencies.gradle
+++ b/android/dependencies.gradle
@@ -34,9 +34,9 @@ ext {
      */
     libraries = [
         androidAppCompat            : "androidx.appcompat:appcompat:1.4.2",
-        androidCamera               : "androidx.camera:camera-camera2:1.2.0-beta01",
-        androidCameraMlKitVision    : "androidx.camera:camera-mlkit-vision:1.2.0-beta01",
-        androidCoreKotlinExtensions : "androidx.core:core-ktx:1.8.0",
+        androidCamera               : "androidx.camera:camera-camera2:1.2.0-beta02",
+        androidCameraMlKitVision    : "androidx.camera:camera-mlkit-vision:1.2.0-beta02",
+        androidCoreKotlinExtensions : "androidx.core:core-ktx:1.9.0",
         androidEspressoCore         : "androidx.test.espresso:espresso-core:3.4.0",
         androidJUnit                : "androidx.test.ext:junit:1.1.3",
         androidJUnitKotlinExtensions: "androidx.test.ext:junit-ktx:1.1.3",
diff --git a/android/react-native-build.gradle b/android/react-native-build.gradle
index 4624afd..65137f1 100644
--- a/android/react-native-build.gradle
+++ b/android/react-native-build.gradle
@@ -9,7 +9,7 @@ buildscript {
 
     dependencies {
         classpath "com.android.tools.build:gradle:$androidPluginVersion"
-        classpath 'de.undercouch:gradle-download-task:5.1.3'
+        classpath 'de.undercouch:gradle-download-task:5.2.1'
     }
 }
 
diff --git a/example/android/build.gradle b/example/android/build.gradle
index d166a13..29cea8f 100644
--- a/example/android/build.gradle
+++ b/example/android/build.gradle
@@ -13,7 +13,7 @@ buildscript {
 
         if (isNewArchitectureEnabled(project)) {
             classpath("com.facebook.react:react-native-gradle-plugin")
-            classpath("de.undercouch:gradle-download-task:5.1.3")
+            classpath("de.undercouch:gradle-download-task:5.2.1")
         }
     }
 }
diff --git a/example/package.json b/example/package.json
index 962f05b..a51d4cf 100644
--- a/example/package.json
+++ b/example/package.json
@@ -52,5 +52,37 @@
     "roots": [
       "test"
     ]
+  },
+  "rnx-kit": {
+    "//": "This configuration is only used for Viewfinder",
+    "kitType": "app",
+    "reactNativeVersion": "0.68",
+    "capabilities": [
+      "core-android",
+      "core-ios",
+      "core-macos",
+      "core-windows",
+      "animation",
+      "babel-preset-react-native",
+      "checkbox",
+      "clipboard",
+      "datetime-picker",
+      "filesystem",
+      "floating-action",
+      "gestures",
+      "html",
+      "masked-view",
+      "modal",
+      "navigation/native",
+      "navigation/stack",
+      "netinfo",
+      "popover",
+      "screens",
+      "shimmer",
+      "sqlite",
+      "storage",
+      "svg",
+      "webview"
+    ]
   }
 }
diff --git a/scripts/configure.js b/scripts/configure.js
index b744f20..9d4bed2 100755
--- a/scripts/configure.js
+++ b/scripts/configure.js
@@ -487,7 +487,7 @@ const getConfig = (() => {
               "",
               "        if (isNewArchitectureEnabled(project)) {",
               '            classpath("com.facebook.react:react-native-gradle-plugin")',
-              '            classpath("de.undercouch:gradle-download-task:5.1.2")',
+              '            classpath("de.undercouch:gradle-download-task:5.2.1")',
               "        }",
               "    }",
               "}",
diff --git a/scripts/prepare-viewfinder.mjs b/scripts/prepare-viewfinder.mjs
new file mode 100755
index 0000000..c23a680
--- /dev/null
+++ b/scripts/prepare-viewfinder.mjs
@@ -0,0 +1,64 @@
+#!/usr/bin/env node
+// @ts-check
+
+import { spawnSync } from "node:child_process";
+import * as fs from "node:fs";
+import * as path from "node:path";
+import { fileURLToPath } from "node:url";
+
+const APP_IDENTIFIER = "com.microsoft.ReactNativeViewfinder";
+const PACKAGE_MANAGER = "yarn";
+
+const PROJECT_ROOT = path.resolve(
+  path.dirname(fileURLToPath(import.meta.url)),
+  ".."
+);
+const APP_ROOT = path.resolve(PROJECT_ROOT, "example");
+const APP_MANIFEST = path.resolve(APP_ROOT, "app.json");
+const PROJECT_MANIFEST = path.resolve(APP_ROOT, "package.json");
+
+/**
+ * Configures the app manifest for Viewfinder.
+ */
+function configureAppManifest() {
+  const original = JSON.parse(
+    fs.readFileSync(APP_MANIFEST, { encoding: "utf-8" })
+  );
+
+  const manifest = {
+    ...original,
+    $schema: undefined,
+    name: "Viewfinder",
+    displayName: "Viewfinder",
+    components: [],
+    android: {
+      package: APP_IDENTIFIER,
+    },
+    ios: {
+      bundleIdentifier: APP_IDENTIFIER,
+    },
+  };
+
+  fs.writeFileSync(APP_MANIFEST, JSON.stringify(manifest, null, 2) + "\n");
+}
+
+/**
+ * Runs the specified command.
+ * @param {string} command
+ * @param {string[]} args
+ * @param {Record<string, unknown>=} options
+ */
+function run(command, args, options) {
+  const { error, status } = spawnSync(command, args, {
+    cwd: PROJECT_ROOT,
+    stdio: "inherit",
+    ...options,
+  });
+  if (status !== 0) {
+    throw error ?? new Error(`Command failed: ${command} ${args.join(" ")}`);
+  }
+}
+
+configureAppManifest();
+run("npx", ["@rnx-kit/dep-check", "--write", PROJECT_MANIFEST]);
+run(PACKAGE_MANAGER, ["install"]);


Test patch:
diff --git a/test/android-test-app/test-app-util.test.js b/test/android-test-app/test-app-util.test.js
index ac13428..9a723bd 100644
--- a/test/android-test-app/test-app-util.test.js
+++ b/test/android-test-app/test-app-util.test.js
@@ -17,7 +17,7 @@ describe("test-app-util", () => {
     "",
     "    dependencies {",
     '        classpath("com.android.tools.build:gradle:${androidPluginVersion}")',
-    '        classpath("de.undercouch:gradle-download-task:5.1.2")',
+    '        classpath("de.undercouch:gradle-download-task:5.2.1")',
     "    }",
     "}",
     "",
diff --git a/test/configure/__snapshots__/gatherConfig.test.js.snap b/test/configure/__snapshots__/gatherConfig.test.js.snap
index 58d8f66..4861aeb 100644
--- a/test/configure/__snapshots__/gatherConfig.test.js.snap
+++ b/test/configure/__snapshots__/gatherConfig.test.js.snap
@@ -84,7 +84,7 @@ Object {
 
         if (isNewArchitectureEnabled(project)) {
             classpath(\\"com.facebook.react:react-native-gradle-plugin\\")
-            classpath(\\"de.undercouch:gradle-download-task:5.1.2\\")
+            classpath(\\"de.undercouch:gradle-download-task:5.2.1\\")
         }
     }
 }
@@ -386,7 +386,7 @@ Object {
 
         if (isNewArchitectureEnabled(project)) {
             classpath(\\"com.facebook.react:react-native-gradle-plugin\\")
-            classpath(\\"de.undercouch:gradle-download-task:5.1.2\\")
+            classpath(\\"de.undercouch:gradle-download-task:5.2.1\\")
         }
     }
 }
@@ -537,7 +537,7 @@ Object {
 
         if (isNewArchitectureEnabled(project)) {
             classpath(\\"com.facebook.react:react-native-gradle-plugin\\")
-            classpath(\\"de.undercouch:gradle-download-task:5.1.2\\")
+            classpath(\\"de.undercouch:gradle-download-task:5.2.1\\")
         }
     }
 }