Skip to content

Commit 08e8180

Browse files
committed
example: add visionos
1 parent 26d76a0 commit 08e8180

File tree

8 files changed

+2278
-2
lines changed

8 files changed

+2278
-2
lines changed

examples/react-native/app.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
"android": ["dist/res", "dist/main.android.jsbundle"],
1212
"ios": ["dist/assets", "dist/main.ios.jsbundle"],
1313
"macos": ["dist/assets", "dist/main.macos.jsbundle"],
14+
"visionos": ["dist/assets", "dist/main.visionos.jsbundle"],
1415
"windows": ["dist/assets", "dist/main.windows.bundle"]
1516
}
1617
}

examples/react-native/metro.config.js

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,12 @@
11
const { makeMetroConfig } = require("@rnx-kit/metro-config");
2+
const { getPlatformResolver } = require("@callstack/out-of-tree-platforms");
3+
24
module.exports = makeMetroConfig({
5+
resolver: {
6+
resolveRequest: getPlatformResolver({
7+
platformNameMap: { visionos: "@callstack/react-native-visionos" },
8+
}),
9+
},
310
transformer: {
411
getTransformOptions: async () => ({
512
transform: {

examples/react-native/package.json

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,12 @@
77
"ios": "react-native run-ios",
88
"windows": "install-windows-test-app && react-native run-windows",
99
"macos": "react-native run-macos",
10+
"visionos": "react-native run-visionos",
1011
"bundle:android": "yarn mkdist && react-native bundle --entry-file index.js --platform android --dev true --bundle-output dist/main.android.jsbundle --assets-dest dist/res",
1112
"bundle:ios": "yarn mkdist && react-native bundle --entry-file index.js --platform ios --dev true --bundle-output dist/main.ios.jsbundle --assets-dest dist",
1213
"bundle:windows": "yarn mkdist && react-native bundle --entry-file index.js --platform windows --dev true --bundle-output dist/main.windows.bundle --assets-dest dist",
1314
"bundle:macos": "yarn mkdist && react-native bundle --entry-file index.js --platform macos --dev true --bundle-output dist/main.macos.bundle --assets-dest dist",
15+
"bundle:visionos": "yarn mkdist && react-native bundle --entry-file index.js --platform ios --dev true --bundle-output dist/main.visionos.bundle --assets-dest dist",
1416
"test:lint": "eslint .",
1517
"test:ts": "tsc --noEmit",
1618
"mkdist": "node -e \"require('node:fs').mkdirSync('dist', { recursive: true, mode: 0o755 })\"",
@@ -20,6 +22,7 @@
2022
"hoistingLimits": "workspaces"
2123
},
2224
"dependencies": {
25+
"@callstack/react-native-visionos": "^0.79.0",
2326
"react": "19.0.0",
2427
"react-native": "0.79.6",
2528
"react-native-macos": "^0.79.0",
@@ -30,6 +33,7 @@
3033
"@babel/core": "^7.25.2",
3134
"@babel/preset-env": "^7.25.3",
3235
"@babel/runtime": "^7.25.0",
36+
"@callstack/out-of-tree-platforms": "^0.77.0",
3337
"@react-native-async-storage/async-storage": "workspace:*",
3438
"@react-native-async-storage/eslint-config": "workspace:*",
3539
"@react-native-community/cli": "18.0.0",

examples/react-native/react-native.config.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,9 @@ const project = (() => {
1111
macos: {
1212
sourceDir: "macos",
1313
},
14+
visionos: {
15+
sourceDir: "visionos",
16+
},
1417
windows: {
1518
sourceDir: "windows",
1619
solutionFile: "Example.sln",

examples/react-native/src/App.tsx

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import React, { useState } from "react";
2-
import { StatusBar, useColorScheme, View } from "react-native";
2+
import { StatusBar, useColorScheme, View, Text, Platform } from "react-native";
33
import { SafeAreaProvider, SafeAreaView } from "react-native-safe-area-context";
44
import { TabButton } from "./components/TabButton";
55
import BasicTests from "./tests/BasicTests";
@@ -11,10 +11,23 @@ function App(): React.JSX.Element {
1111
"basic" | "legacy-basic" | "perf" | "legacy-perf"
1212
>("basic");
1313

14+
function getPlatform() {
15+
switch (Platform.OS) {
16+
case "ios": {
17+
return Platform.isVision ? "visionOS" : "iOS";
18+
}
19+
default:
20+
return Platform.OS;
21+
}
22+
}
23+
1424
return (
1525
<SafeAreaProvider>
16-
<SafeAreaView style={{ flex: 1 }}>
26+
<SafeAreaView style={{ flex: 1, backgroundColor: "white", padding: 16 }}>
1727
<StatusBar barStyle={isDarkMode ? "light-content" : "dark-content"} />
28+
<Text style={{ fontSize: 24, color: "red" }}>
29+
Platform: {getPlatform()}
30+
</Text>
1831

1932
<View
2033
style={{
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
ws_dir = Pathname.new(__dir__)
2+
ws_dir = ws_dir.parent until
3+
File.exist?("#{ws_dir}/node_modules/react-native-test-app/visionos/test_app.rb") ||
4+
ws_dir.expand_path.to_s == '/'
5+
require "#{ws_dir}/node_modules/react-native-test-app/visionos/test_app.rb"
6+
7+
workspace "AsyncStorageVisionExample.xcworkspace"
8+
9+
# 1 - enable new arch, 0 - disable it
10+
ENV["RCT_NEW_ARCH_ENABLED"]="1"
11+
12+
use_test_app! :hermes_enabled => true, :fabric_enabled => true

0 commit comments

Comments
 (0)