GithubHelp home page GithubHelp logo

vivekvt / react-native-visionos Goto Github PK

View Code? Open in Web Editor NEW

This project forked from callstack/react-native-visionos

0.0 0.0 0.0 284.38 MB

A framework for building native applications using React

Home Page: https://reactnative.dev

License: MIT License

Shell 0.42% JavaScript 17.23% Ruby 2.92% C++ 26.54% C 0.38% Objective-C 9.90% Java 24.45% Assembly 0.11% Kotlin 5.05% TypeScript 0.57% Objective-C++ 11.76% Swift 0.04% HTML 0.01% CMake 0.61%

react-native-visionos's Introduction

Learn once, write anywhere:
Build spatial apps with React.

React Native visionOS allows you to write visionOS with full support for platform SDK. This is a full fork of the main repository with changes needed to support visionOS.

Screenshot

Caution

This project is still at an early stage of development and is not ready for production use.

New project creation

  1. Make sure you have a proper development environment setup
  2. Download the latest Xcode (at least 15.2).
  3. Install visionOS simulator runtime.
  4. Install the latest version of CMake (at least v3.28.0).
  5. Initialize the project using this command:
npx @callstack/react-native-visionos@latest init YourApp
  1. Next, go to YourApp/visionos folder and run following commands to install Pods:
bundle install
bundle exec pod install
  1. Now you can run yarn visionos
  2. (Optional) you also can open project using Xcode (xed YourApp/visionos/YourApp.xcworkspace).
  • Build the app by clicking the "Run" button in Xcode.

Platform guidelines

We suggest you read Human Interface Guidelines for visionOS when creating visionOS apps.

It's important not to cover the translucent background with a solid color, as it helps to ground apps and make them feel like part of the environment.

API Reference

App entry point

React Native visionOS uses SwiftUI lifecycle. The app entry point is now App.swift file (by default it is main.m). This change allows us to use full capabilities of the visionOS SDK.

Here is an example from the template:

// App.swift
@main
struct HelloWorldApp: App {
  @UIApplicationDelegateAdaptor var delegate: AppDelegate
  
  var body: some Scene {
    RCTMainWindow(moduleName: "HelloWorld")
  }
}

We are using @UIApplicationDelegateAdaptor, a property wrapper that allows us to use familiar AppDelegate in SwiftUI life cycle.

AppDelegate extends RCTAppDelegate which does most of React Native initialization.

Hover effect API

This is a prop on <View /> component allowing to add hover effect. It's applied to all Touchable and Pressable components by default.

If you want to customize it you can use the visionos_hoverEffect prop, like so:

<TouchableOpacity visionos_hoverEffect="lift">
  <Text>Click me</Text>
</TouchableOpacity>

The available options are: lift or highlight.

XR API (nightly)

Manage Immersive Experiences.

Methods

requestSession

requestSession: (sessionId?: string) => Promise<void>

Opens a new ImmersiveSpace given it's unique Id.

endSession

endSession: () => Promise<void>

Closes currently open ImmersiveSpace.

Constants

supportsMultipleScenes

supportsMultipleScenes: boolean

A Boolean value that indicates whether the app may display multiple scenes simultaneously. Returns the value of UIApplicationSupportsMultipleScenes key from Info.plist.

Example Usage

  1. Set UIApplicationSupportsMultipleScenes to true in Info.plist:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
	<key>UIApplicationSceneManifest</key>
	<dict>
		<key>UIApplicationPreferredDefaultSceneSessionRole</key>
		<string>UIWindowSceneSessionRoleApplication</string>
		<key>UIApplicationSupportsMultipleScenes</key>
-   <false/>
+		<true/>
		<key>UISceneConfigurations</key>
		<dict/>
	</dict>
</dict>
</plist>
  1. Inside App.swift add new ImmersiveSpace:
@main
struct HelloWorldApp: App {
  @UIApplicationDelegateAdaptor var delegate: AppDelegate
+ @State private var immersionLevel: ImmersionStyle = .mixed
  
  var body: some Scene {
    RCTMainWindow(moduleName: "HelloWorldApp")
+   ImmersiveSpace(id: "TestImmersiveSpace") {
+     // RealityKit content goes here
+   }
+    .immersionStyle(selection: $immersionLevel, in: .mixed, .progressive, .full)
  }
}

For more information about ImmersiveSpace API refer to Apple documentation.

In the above example we set ImmersiveSpace id to TestImmersiveSpace.

Now in our JS code, we can call:

import {XR} from "@callstack/react-native-visionos"
//...
const openXRSession = async () => {
  try {
    if (!XR.supportsMultipleScenes) {
      Alert.alert('Error', 'Multiple scenes are not supported');
      return;
    }
    await XR.requestSession('TestImmersiveSpace'); // Pass the same identifier from `App.swift`
  } catch (e) {
    Alert.alert('Error', e.message);
  }
};

const closeXRSession = async () => {
  await XR.endSession();
};

Caution

Opening an ImmersiveSpace can fail in this secarios:

  • ImmersiveSpace is not declared.
  • UIApplicationSupportsMultipleScenes is set to false.
  • User cancels the request.

For a full example usage, refer to XRExample.js.

Contributing

  1. Follow the same steps as in the New project creation section.
  2. Checkout rn-tester README.md to build React Native from source.

Release process

We use a script called oot-release.js which automatically releases visionos packages and aligns versions of dependencies with React Native core.

Usage:

node ./scripts/oot-release.js --new-version "<visionos-version>" --react-native-version "<react-native-version>" --one-time-password "<otp>"

To test releases and template we use Verdaccio.

react-native-visionos's People

Contributors

shergin avatar mdvacca avatar sammy-sc avatar rsnara avatar javache avatar joshuagross avatar cortinico avatar hramos avatar davidaurelio avatar sahrens avatar yungsters avatar vjeux avatar fkgozali avatar nickgerleman avatar nicklockwood avatar thesavior avatar tadeuzagallo avatar rickhanlonii avatar janicduplessis avatar cpojer avatar cipolleschi avatar frantic avatar motiz88 avatar rubennorte avatar bestander avatar ide avatar martinbigio avatar philiip avatar mkonicek avatar mhorowitz avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.