diff --git a/.github/workflows/append_release.yml b/.github/workflows/append_release.yml new file mode 100644 index 000000000..71cd9b042 --- /dev/null +++ b/.github/workflows/append_release.yml @@ -0,0 +1,154 @@ +name: 'Append Release' + +on: + workflow_call: + inputs: + release-name: + required: true + type: string + is-preview: + required: true + type: boolean +jobs: + Build: + runs-on: ubuntu-latest + steps: + - name: Download Assembled Folder + uses: actions/download-artifact@v2 + with: + name: 'Assembled' + path: Package/react-native + + - name: Compress Package react-native + run: | + tar --exclude='readme.md' --exclude='package.json' -czvf react-native.tar.gz -C Package/react-native/ . + + - name: Download Assembled-BaseKit-iOSAndroid 0.69 Folder + uses: actions/download-artifact@v2 + with: + name: 'Assembled-BaseKit-iOSAndroid0.69' + path: Package/iOSAndroid0.69 + - name: Compress Package iOSAndroid0.69 + uses: a7ul/tar-action@v1.1.3 + id: compressiosandroid069 + with: + command: c + cwd: Package/iOSAndroid0.69/ + files: | + android + ios + react-native-babylon.podspec + outPath: iOSAndroid0.69.tar.gz + + - name: Download Assembled-BaseKit-iOSAndroid 0.70 Folder + uses: actions/download-artifact@v2 + with: + name: 'Assembled-BaseKit-iOSAndroid0.70' + path: Package/iOSAndroid0.70 + - name: Compress Package iOSAndroid0.70 + uses: a7ul/tar-action@v1.1.3 + id: compressiosandroid070 + with: + command: c + cwd: Package/iOSAndroid0.70/ + files: | + android + ios + react-native-babylon.podspec + outPath: iOSAndroid0.70.tar.gz + + - name: Download Assembled-BaseKit-iOSAndroid 0.71 Folder + uses: actions/download-artifact@v2 + with: + name: 'Assembled-BaseKit-iOSAndroid0.71' + path: Package/iOSAndroid0.71 + - name: Compress Package iOSAndroid0.71 + uses: a7ul/tar-action@v1.1.3 + id: compressiosandroid071 + with: + command: c + cwd: Package/iOSAndroid0.71/ + files: | + android + ios + react-native-babylon.podspec + outPath: iOSAndroid0.71.tar.gz + + - name: Download Assembled-BaseKit-Windows 0.69 Folder + uses: actions/download-artifact@v2 + with: + name: 'Assembled-BaseKit-Windows0.69' + path: Package/Windows0.69 + - name: Compress Package Windows0.69 + uses: a7ul/tar-action@v1.1.3 + id: compresswindows069 + with: + command: c + cwd: Package/Windows0.69/ + files: | + windows + index.ts + outPath: Windows0.69.tar.gz + + - name: Download Assembled-BaseKit-Windows 0.70 Folder + uses: actions/download-artifact@v2 + with: + name: 'Assembled-BaseKit-Windows0.70' + path: Package/Windows0.70 + - name: Compress Package Windows0.70 + uses: a7ul/tar-action@v1.1.3 + id: compresswindows070 + with: + command: c + cwd: Package/Windows0.70/ + files: | + windows + index.ts + outPath: Windows0.70.tar.gz + + - name: Download Assembled-BaseKit-Windows 0.71 Folder + uses: actions/download-artifact@v2 + with: + name: 'Assembled-BaseKit-Windows0.71' + path: Package/Windows0.71 + - name: Compress Package Windows0.71 + uses: a7ul/tar-action@v1.1.3 + id: compresswindows071 + with: + command: c + cwd: Package/Windows0.71/ + files: | + windows + index.ts + outPath: Windows0.71.tar.gz + + - name: Preview Release + if: ${{ inputs.is-preview == true }} + uses: softprops/action-gh-release@v1 + with: + files: | + react-native.tar.gz + Windows0.69.tar.gz + Windows0.70.tar.gz + Windows0.71.tar.gz + iOSAndroid0.69.tar.gz + iOSAndroid0.70.tar.gz + iOSAndroid0.71.tar.gz + tag_name: ${{ inputs.release-name }} + name: ${{ inputs.release-name }} + body: "Preview release for ${{ inputs.release-name }}" + draft: true + prerelease: true + + - name: Release + if: ${{ inputs.is-preview == false }} + uses: softprops/action-gh-release@v1 + with: + files: | + react-native.tar.gz + Windows0.69.tar.gz + Windows0.70.tar.gz + Windows0.71.tar.gz + iOSAndroid0.69.tar.gz + iOSAndroid0.70.tar.gz + iOSAndroid0.71.tar.gz diff --git a/.github/workflows/bn_master_commit.yml b/.github/workflows/bn_master_commit.yml index 5549249a9..b61178c86 100644 --- a/.github/workflows/bn_master_commit.yml +++ b/.github/workflows/bn_master_commit.yml @@ -35,6 +35,12 @@ jobs: - name: NPM Install (Binary Package) run: npm install working-directory: ./Package + - name: Setup Java + uses: actions/setup-java@v3 + with: + distribution: 'temurin' + java-version: '17' + check-latest: true - name: Gulp (Android) run: npx gulp buildAndroid working-directory: ./Package diff --git a/.github/workflows/ios_android.yml b/.github/workflows/ios_android.yml index 996ecf749..f887e8384 100644 --- a/.github/workflows/ios_android.yml +++ b/.github/workflows/ios_android.yml @@ -33,6 +33,12 @@ jobs: run: brew install ninja - name: 'Select XCode ${{ inputs.xcode-version }}' run: sudo xcode-select --switch /Applications/Xcode_${{ inputs.xcode-version }}.app/Contents/Developer + - name: Setup Java + uses: actions/setup-java@v3 + with: + distribution: 'temurin' + java-version: '17' + check-latest: true - name: NPM Install (Playground) run: npm install working-directory: ./Apps/Playground diff --git a/.github/workflows/pr.yml b/.github/workflows/pr.yml index 305b1caaa..9caaa44ef 100644 --- a/.github/workflows/pr.yml +++ b/.github/workflows/pr.yml @@ -33,6 +33,12 @@ jobs: - name: NPM Install (Binary Package) run: npm install working-directory: ./Package + - name: Setup Java + uses: actions/setup-java@v3 + with: + distribution: 'temurin' + java-version: '17' + check-latest: true - name: Gulp (Android) run: npx gulp buildAndroid working-directory: ./Package @@ -80,6 +86,12 @@ jobs: cmake-version: '3.26.3' - name: Setup Ninja run: brew install ninja + - name: Setup Java + uses: actions/setup-java@v3 + with: + distribution: 'temurin' + java-version: '17' + check-latest: true - name: NPM Install (Playground) run: npm install working-directory: ./Apps/Playground diff --git a/.github/workflows/publish.yml b/.github/workflows/publish.yml index ebe3bf4a6..4a8c0a098 100644 --- a/.github/workflows/publish.yml +++ b/.github/workflows/publish.yml @@ -68,6 +68,13 @@ jobs: with: release-version: ${GITHUB_REF/refs\/tags\//} + append-release: + needs: [build-typescript, build-android-ios-069, build-android-ios-070, build-android-ios-071, build-windows-069, build-windows-070, build-windows-071] + uses: ./.github/workflows/append_release.yml + with: + release-name: ${GITHUB_REF/refs\/tags\//} + is-preview: false + package: needs: [build-typescript, build-android-ios-064, build-android-ios-065, build-android-ios-069, build-android-ios-070, build-android-ios-071, build-windows-064, build-windows-065, build-windows-069, build-windows-070, build-windows-071] runs-on: macos-latest @@ -292,5 +299,13 @@ jobs: npm version --no-git-tag-version ${GITHUB_REF/refs\/tags\//} npm publish --access public working-directory: ./Package/Assembled-BaseKit-Windows0.71 + env: + NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }} +# ROOT Basekit package + - name: Version & Publish Package @babylonjs/react-native-basekit + run: | + npm version --no-git-tag-version ${GITHUB_REF/refs\/tags\//} + npm publish --access public + working-directory: ./Modules/@babylonjs/react-native-basekit env: NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }} \ No newline at end of file diff --git a/.github/workflows/publish_preview.yml b/.github/workflows/publish_preview.yml index 6203abc0f..b94534f48 100644 --- a/.github/workflows/publish_preview.yml +++ b/.github/workflows/publish_preview.yml @@ -84,6 +84,13 @@ jobs: with: release-version: ${{ github.event.inputs.release_version }} + append-release: + needs: [build-typescript, build-android-ios-069, build-android-ios-070, build-android-ios-071, build-windows-069, build-windows-070, build-windows-071] + uses: ./.github/workflows/append_release.yml + with: + release-name: ${{ github.event.inputs.release_version }} + is-preview: true + package: needs: [build-typescript, build-android-ios-064, build-android-ios-065, build-android-ios-069, build-android-ios-070, build-android-ios-071, build-windows-064, build-windows-065, build-windows-069, build-windows-070, build-windows-071] runs-on: macos-latest @@ -309,5 +316,13 @@ jobs: npm version --no-git-tag-version ${{ github.event.inputs.release_version }} npm publish --access public --tag ${{ github.event.inputs.NPM_tag }} ${{ github.event.inputs.NPM_publish_arg }} working-directory: ./Package/Assembled-BaseKit-Windows0.71 + env: + NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }} +# ROOT Basekit package + - name: Version & Publish Package @babylonjs/react-native-basekit + run: | + npm version --no-git-tag-version ${{ github.event.inputs.release_version }} + npm publish --access public --tag ${{ github.event.inputs.NPM_tag }} ${{ github.event.inputs.NPM_publish_arg }} + working-directory: ./Modules/@babylonjs/react-native-basekit env: NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }} \ No newline at end of file diff --git a/.github/workflows/test_version.yml b/.github/workflows/test_version.yml index 0f639e9d8..7554a9c83 100644 --- a/.github/workflows/test_version.yml +++ b/.github/workflows/test_version.yml @@ -66,6 +66,12 @@ jobs: uses: actions/setup-node@v3 with: node-version: 16 + - name: Setup Java + uses: actions/setup-java@v3 + with: + distribution: 'temurin' + java-version: '17' + check-latest: true - name: Build Playground Android run: | npm uninstall -g react-native-cli @react-native-community/cli diff --git a/Modules/@babylonjs/react-native-basekit/.gitattributes b/Modules/@babylonjs/react-native-basekit/.gitattributes new file mode 100644 index 000000000..d42ff1835 --- /dev/null +++ b/Modules/@babylonjs/react-native-basekit/.gitattributes @@ -0,0 +1 @@ +*.pbxproj -text diff --git a/Modules/@babylonjs/react-native-basekit/.gitignore b/Modules/@babylonjs/react-native-basekit/.gitignore new file mode 100644 index 000000000..1de26d81c --- /dev/null +++ b/Modules/@babylonjs/react-native-basekit/.gitignore @@ -0,0 +1,51 @@ +# OSX +# +.DS_Store + +# node.js +# +node_modules/ +npm-debug.log +yarn-error.log + +# Xcode +# +build/ +*.pbxuser +!default.pbxuser +*.mode1v3 +!default.mode1v3 +*.mode2v3 +!default.mode2v3 +*.perspectivev3 +!default.perspectivev3 +xcuserdata +*.xccheckout +*.moved-aside +DerivedData +*.hmap +*.ipa +*.xcuserstate +project.xcworkspace + +# Android/IntelliJ +# +build/ +.idea +.gradle +local.properties +*.iml + +# BUCK +buck-out/ +\.buckd/ +*.keystore + +# CMake +CMakeFiles +CMakeScripts +CMakeCache.txt +cmake_install.cmake +ReactNativeBabylon.xcodeproj +*.tgz +jsi \ No newline at end of file diff --git a/Modules/@babylonjs/react-native-basekit/.npmignore b/Modules/@babylonjs/react-native-basekit/.npmignore new file mode 100644 index 000000000..673b6c072 --- /dev/null +++ b/Modules/@babylonjs/react-native-basekit/.npmignore @@ -0,0 +1,60 @@ +# OSX +# +.DS_Store + +# node.js +# +node_modules/ +npm-debug.log +yarn-error.log + +# Xcode +# +build/ +*.pbxuser +!default.pbxuser +*.mode1v3 +!default.mode1v3 +*.mode2v3 +!default.mode2v3 +*.perspectivev3 +!default.perspectivev3 +xcuserdata +*.xccheckout +*.moved-aside +DerivedData +*.hmap +*.ipa +*.xcuserstate +project.xcworkspace + +# Android/IntelliJ +# +build/ +.idea +.gradle +local.properties +*.iml + +# BUCK +buck-out/ +\.buckd/ +*.keystore + +# CMake +CMakeFiles +CMakeScripts +CMakeCache.txt +cmake_install.cmake +ReactNativeBabylon.xcodeproj +*.tgz + +# Package-specific ignores +#submodules/BabylonNative/Apps +submodules/BabylonNative/Dependencies/bgfx.cmake/bgfx/examples/* +!submodules/BabylonNative/Dependencies/bgfx.cmake/bgfx/examples/common +submodules/BabylonNative/Dependencies/glslang/Test +submodules/BabylonNative/Dependencies/xr/Dependencies/arcore-android-sdk/media +submodules/BabylonNative/Dependencies/xr/Dependencies/arcore-android-sdk/tools +submodules/BabylonNative/Dependencies/xr/Dependencies/arcore-android-sdk/assets +submodules/BabylonNative/Dependencies/xr/Dependencies/arcore-android-sdk/samples diff --git a/Modules/@babylonjs/react-native-basekit/README.md b/Modules/@babylonjs/react-native-basekit/README.md new file mode 100644 index 000000000..7945af469 --- /dev/null +++ b/Modules/@babylonjs/react-native-basekit/README.md @@ -0,0 +1,119 @@ +# Babylon React Native Basekit + +## Usage + +This quick overview will help you understand the constructs provided by Babylon React Native and how to use them in a React Native application. + +### Dependencies + +This package has several **peer dependencies**. If these dependencies are unmet, `npm install` will emit warnings. Be sure to add these dependencies to your project. + +### Installation Configuration + +Downloaded dependencies are cached by default in directory specified by `npm_config_cache`. It's possible to specify a new cache directory by setting `npm_config_babylon_binary_cache` environment variable. + +Also, it's possible to set the source of these downloaded dependencies. By default, it's using main Github repo releases: `https://github.com/BabylonJS/BabylonReactNative/releases/download`. +Other possibilities are: +- By command argument for `npm install --brn-binary-site https://mysite.com/downloads` +- By environment variable. on MacOS/Linux: `export npm_config_brn_binary_site=https://mysite.com/downloads` + +These case location must respect same hierarchy as the main Github repo releases. + +### Android Configuration + +The minimum Android SDK version is 18. This must be set as `minSdkVersion` in the consuming project's `build.gradle` file. + +### iOS Configuration + +The minimum deployment target version is 12. This must be set as `iOS Deployment Target` in the consuming project's `project.pbxproj`, and must also be set as `platform` in the consuming project's `podfile`. + +### Platform Native Packages + +Babylon React Native supports react-native from 0.69 to 0.71+. See project Github main readme for supported versions. + +### `useEngine` + +`useEngine` is a **custom React hook** that manages the lifecycle of a Babylon engine instance in the context of an owning React component. `useEngine` creates an engine instance **asynchronously** which is used to create and configure scenes. Typically scene initialization code should exist in a `useEffect` triggered by an `engine` state change. For example: + +```tsx +import { useEngine } from '@babylonjs/react-native-basekit'; +import { Engine, Scene } from '@babylonjs/core'; + +const MyComponent: FunctionComponent = (props: MyComponentProps) => { + const engine = useEngine(); + + useEffect(() => { + if (engine) { + const scene = new Scene(engine); + // Setup the scene! + } + }, [engine]); + + return ( + <> + + ); +} +``` + +### `EngineView` + +`EngineView` is a **custom React Native view** that presents a `camera` from a Babylon `scene`. A `camera` therefore is assigned to the `EngineView`. For example: + +```tsx +import { useEngine, EngineView } from '@babylonjs/react-native-basekit'; +import { Engine, Scene, Camera } from '@babylonjs/core'; + +const MyComponent: FunctionComponent = (props: MyComponentProps) => { + const engine = useEngine(); + const [camera, setCamera] = useState(); + + useEffect(() => { + if (engine) { + const scene = new Scene(engine); + scene.createDefaultCamera(true); + setCamera(scene.activeCamera!); + // Setup the scene! + } + }, [engine]); + + return ( + <> + + + ); +} +``` + +Also the `EngineView` has a boolean `isTransparent` flag which defines whether the background of the scene should be transparent or not. + +e.g. + +```tsx + +``` +To configure anti-aliasing, a property called `antiAliasing` can be changed to a value of 0 or 1 (disable anti-aliasing, default), 2, 4, 8 or 16 (anti-aliasing samples). + +e.g. + +```tsx + +``` + +Note: Currently only one `EngineView` can be active at any given time. Multi-view will be supported in a future release. + +The Android specific `androidView` property can help set the type of the view used for rendering. Depending on user needs and performance, refer to the table below. [`TextureView`](https://developer.android.com/reference/android/view/TextureView) can be inserted anywhere in the view hierarchy, but is less efficient. [`SurfaceView`](https://developer.android.com/reference/android/view/SurfaceView) can only be full above or fully below the rest of the UI, but is more efficient. + +| isTransparent | androidView | Description | +| ----------- | ------------------------ | ----------- | +| False | TextureView | Opaque TextureView. +| False | SurfaceView | Simple surfaceView (default when no `androidView` set with `isTransparent=false`). +| False | SurfaceViewZTopMost | SurfaceView with [ZTopMost](https://developer.android.com/reference/android/view/SurfaceView#setZOrderOnTop(boolean)) set to `true`. +| False | SurfaceViewZMediaOverlay | SurfaceView with [ZMediaOverlay](https://developer.android.com/reference/android/view/SurfaceView#setZOrderMediaOverlay(boolean)) set to `true`. +| True | TextureView | Transparent TextureView. +| True | SurfaceView | SurfaceView will stay opaque +| True | SurfaceViewZTopMost | SurfaceView with [ZTopMost](https://developer.android.com/reference/android/view/SurfaceView#setZOrderOnTop(boolean)) set to `true`. Transparent but top most. (default when no `androidView` set with `isTransparent=true`) +| True | SurfaceViewZMediaOverlay | SurfaceView with [ZMediaOverlay](https://developer.android.com/reference/android/view/SurfaceView#setZOrderMediaOverlay(boolean)) set to `true`. Only Transparent on top of other SurfaceViews. + +More infos on TextureView Vs SurfaceView performance here: +https://developer.android.com/reference/android/view/TextureView diff --git a/Modules/@babylonjs/react-native-basekit/package.json b/Modules/@babylonjs/react-native-basekit/package.json new file mode 100644 index 000000000..6b332627b --- /dev/null +++ b/Modules/@babylonjs/react-native-basekit/package.json @@ -0,0 +1,60 @@ +{ + "name": "@babylonjs/react-native-basekit", + "title": "React Native Babylon Basekit", + "version": "0.0.1", + "description": "Babylon Native integration into React Native", + "main": "index.js", + "scripts": { + "test": "echo \"Error: no test specified\" && exit 1", + "postinstall": "node scripts/install.js" + }, + "repository": { + "type": "git", + "url": "git+https://github.com/babylonjs/BabylonReactNative.git", + "baseUrl": "https://github.com/babylonjs/BabylonReactNative" + }, + "keywords": [ + "react-native" + ], + "author": { + "name": "Your Name", + "email": "yourname@email.com" + }, + "homepage": "https://github.com/BabylonJS/BabylonReactNative#readme", + "license": "MIT", + "licenseFilename": "LICENSE", + "readmeFilename": "README.md", + "dependencies": { + "base-64": "^0.1.0", + "https": "^1.0.0", + "path": "^0.12.7", + "semver": "^7.3.2", + "tar": "^6.2.0", + "zlib": "^1.0.5" + }, + "peerDependencies": { + "@babylonjs/core": "^6.14.0", + "@babylonjs/loaders": "^6.14.0", + "react": ">=16.13.1", + "react-native": ">=0.69.1" + }, + "devDependencies": { + "@babel/core": "^7.8.4", + "@babel/runtime": "^7.8.4", + "@babylonjs/core": "6.14.0", + "@rnw-scripts/eslint-config": "0.1.6", + "@rnw-scripts/ts-config": "0.1.0", + "@types/base-64": "^0.1.3", + "@types/jest": "^25.2.1", + "@types/react": "^16.9.32", + "@types/react-native": "^0.63.1", + "@types/react-native-permissions": "^2.0.0", + "@types/react-test-renderer": "^16.9.2", + "@types/semver": "^7.3.4", + "eslint": "7.12.0", + "just-scripts": "^0.44.7", + "metro-react-native-babel-preset": "^0.56.0", + "prettier": "1.19.1", + "typescript": "^4.3.5" + } +} diff --git a/Modules/@babylonjs/react-native-basekit/scripts/install.js b/Modules/@babylonjs/react-native-basekit/scripts/install.js new file mode 100644 index 000000000..c1b83140e --- /dev/null +++ b/Modules/@babylonjs/react-native-basekit/scripts/install.js @@ -0,0 +1,225 @@ +const https = require("https"); +const zlib = require("zlib"); +const tar = require("tar"); +const path = require("path"); +const fs = require("fs"); + +function getCachePathCandidates() { + return [ + process.env.npm_config_babylon_binary_cache, + process.env.npm_config_cache, + ].filter(function(_) { + return _; + }); +} + +function getCached(package, binaryFilename) { + return [ + getCachePathCandidates(), + "BabylonReactNative", + package.version, + binaryFilename, + ].join("/"); +} + +function useCachedFile(filePath) { + return new Promise((resolve, reject) => { + if (fs.existsSync(filePath)) { + const gunzip = zlib.createGunzip(); + const untar = tar.extract({ cwd: process.cwd() }); // Extract to the current working directory + + const sourceStream = fs.createReadStream(filePath); + sourceStream + .pipe(gunzip) // Decompress the .tar.gz file + .pipe(untar) // Extract the tar contents to the cwd + .on("error", (err) => { + reject(err); + }) + .on("end", () => { + resolve(true); + }); + } else { + resolve(false); + } + }); +} + +function getArgument(name) { + const flags = process.argv.slice(2); + const index = flags.lastIndexOf(name); + + if (index === -1 || index + 1 >= flags.length) { + return null; + } + + return flags[index + 1]; +} + +function getBinaryUrl(package, binaryFilename) { + const site = + getArgument("--brn-binary-site") || + process.env.BRN_BINARY_SITE || + process.env.npm_config_brn_binary_site || + "https://github.com/BabylonJS/BabylonReactNative/releases/download"; + + return [site, package.version, binaryFilename].join("/"); +} + +function downloadExtractAndCache(url, cachedFilePath, cb) { + const options = { + followRedirects: true, // Follow HTTP 3xx redirects + }; + + https.get(url, options, (response) => { + if ([301, 302, 303, 307, 308].includes(response.statusCode)) { + // If the response is a redirect, recursively call downloadExtractAndCache with the new URL + downloadExtractAndCache(response.headers.location, cachedFilePath, cb); + } else if (response.statusCode === 200) { + const gunzip = zlib.createGunzip(); + const untar = tar.extract({ cwd: process.cwd() }); // Extract to the current working directory + + // create cache directory to store download file + const dir = path.dirname(cachedFilePath); + try { + if (!fs.existsSync(dir)) { + fs.mkdirSync(dir, { recursive: true }); + } + } catch (err) { + cb(err); + } + + var file = fs.createWriteStream(cachedFilePath); + + response + .pipe(gunzip) // Unzip the response + .pipe(untar) // Extract the tar file + .on("error", (err) => { + cb(err); + }); + response.pipe(file); + file.on("finish", () => { + file.close((err) => { + if (err) { + cb(err); + } else { + cb(); + } + }); // close() is async, call cb after close completes. + }); + } else { + cb( + `Failed to download the file. Status code: ${response.statusCode}` + ); + } + }) + .on("error", (err) => { + cb(err); + }); +} + +function installZip(filePath, fileURL) { + return new Promise((resolve, reject) => { + useCachedFile(filePath) + .then((result) => { + if (result) { + resolve(true); + } else { + // File does not exist in cache + downloadExtractAndCache(fileURL, filePath, (err) => { + if (err) { + reject(err); + } else { + resolve(true); + } + }); + } + }) + .catch((err) => { + reject(err); + }); + }); +} + +function install() { + // get Babylon React Native package version + const packageJsonPath = process.env.npm_package_json; + const packageJson = require(packageJsonPath); + if (!packageJson.version) { + console.err("Babylon React Native version not found"); + process.exit(1); + } + // get user project react-native version + const projectPackageJsonPath = + process.env.npm_config_local_prefix + "/package.json"; + + // Read the project's package.json file + const projectPackageJson = require(projectPackageJsonPath); + // Check if the project's package.json has a 'react-native' dependency + if ( + projectPackageJson.dependencies && + projectPackageJson.dependencies["react-native"] + ) { + const reactNativeVersion = projectPackageJson.dependencies["react-native"]; + console.log(`Detected React Native version: ${reactNativeVersion}`); + + const [_, packageMinor] = reactNativeVersion.split('.').map(Number); + + reactNativePostfix = ""; + if (packageMinor >= "71") { + reactNativePostfix = "0.71"; + } else if (packageMinor >= "70") { + reactNativePostfix = "0.70"; + } else if (packageMinor >= "69") { + reactNativePostfix = "0.69"; + } else { + console.error("Unsupported react native version."); + process.exit(1); + } + console.log( + `Using Babylon React Native version ${reactNativePostfix} from Package version ${packageJson.version}.` + ); + + const jsArchive = "react-native.tar.gz"; + const iosAndroidArchive = `iOSAndroid${reactNativePostfix}.tar.gz`; + const windowsArchive = `Windows${reactNativePostfix}.tar.gz`; + + const jsArchiveCachedPath = getCached(packageJson, jsArchive); + const iosAndroidArchiveCachedPath = getCached( + packageJson, + iosAndroidArchive + ); + const windowsArchiveCachedPath = getCached(packageJson, windowsArchive); + + const jsArchiveURL = getBinaryUrl(packageJson, jsArchive); + const iOSAndroidArchiveURL = getBinaryUrl(packageJson, iosAndroidArchive); + const windowsArchiveURL = getBinaryUrl(packageJson, windowsArchive); + + const reactNativeWindowsVersion = + projectPackageJson.dependencies["react-native-windows"]; + installZip(jsArchiveCachedPath, jsArchiveURL) + .then((result) => { + installZip(iosAndroidArchiveCachedPath, iOSAndroidArchiveURL) + .then((result) => { + if (reactNativeWindowsVersion) { + installZip(windowsArchiveCachedPath, windowsArchiveURL) + .then((result) => {}) + .catch((err) => { + reject(err); + }); + } + }) + .catch((err) => { + reject(err); + }); + }) + .catch((err) => { + console.error("Error install BabylonReactNative archive:", err); + process.exit(1); + }); + } else { + console.error("No react-native version found for BabylonReactNative."); + process.exit(1); + } +} + +install(); diff --git a/Modules/@babylonjs/react-native-windows/windows/BabylonReactNative/BabylonReactNative.vcxproj b/Modules/@babylonjs/react-native-windows/windows/BabylonReactNative/BabylonReactNative.vcxproj index a3bff28d8..4843178eb 100644 --- a/Modules/@babylonjs/react-native-windows/windows/BabylonReactNative/BabylonReactNative.vcxproj +++ b/Modules/@babylonjs/react-native-windows/windows/BabylonReactNative/BabylonReactNative.vcxproj @@ -22,12 +22,15 @@ $(ProjectDir)\..\..\..\..\..\node_modules\react-native-windows\ + + $(ProjectDir)\..\..\..\..\..\node_modules\react-native-basekit\ $(SolutionDir)\..\node_modules\react-native-windows\ $(ProjectDir)\..\..\..\..\..\Apps\Playground\Playground\node_modules\react-native-windows\ + $(ProjectDir)..\..\..\react-native-basekit\ $(ProjectDir)..\..\..\react-native-iosandroid\ $(ProjectDir)..\..\..\react-native\ $(BabylonReactNativeDir)Build\ @@ -167,6 +170,7 @@ $(BabylonReactNativeDir)shared;%(AdditionalIncludeDirectories) $(BabylonNativeIOSAndroidProjDir)shared;%(AdditionalIncludeDirectories) + $(BabylonNativeBasekitProjDir)shared;%(AdditionalIncludeDirectories) %(IgnoreSpecificDefaultLibraries)