Skip to content

Commit

Permalink
feat: add visionos support
Browse files Browse the repository at this point in the history
fix: address issues with scale, ScrollView prop

feat: move min_visionos_version_supported to Helpers

feat: implement `visionos_hoverStyle` prop

chore: update README.MD

fix: refactor visionos_hoverStyle to take a string and new arch support

docs: add link to rn-tester's README.md (#5)

chore: change VisionOS to visionOS (#13)

chore: use `min_supported_versions` for third-party-podspecs (#18)

chore: remove not necessary ifs TARGET_OS_VISION, minimise code diff (#22)

feat: add visionos support

add warning when using InputAccessoryView

update platform naming

fix: remove keyboard listerners and mark as unsupported (#25)

* fix: remove keyboard listerners and mark as unsupported

* chore: replace warn with warnOnce

feat: support building visionOS with dynamic frameworks enabled (#28)

chore: sync Podfile.lock with upstream, remove unnecessary #endif

feat: add visionOS as separate target to fix iOS tests (#31)

* feat: add visionOS as separate target to fix iOS tests

* fix: disable multiple windows support

* feat: add visionOS App Icon

* fix: creating Release build

Update README.md (#36)

* Update README.md

* fix: update README link

* feat: add caution section

* fix: bring back info about Hermes

Add platform guidelines to README (#37)

* Add platform guidelines to README

* fix: link to docs

Rename react-native package to @callstack/react-native-visionos (#35)

* rename react-native package to @callstack/react-native-visionos

* fix typo

* Make JS and TS tests independent of react-native package name

* change name in template

* replace more refs in e2e tests

* revert tests changes

* disable js e2e tests for visionos

* bring back react-native for other platforms compat

* ci: run js, no e2e js

Fix codegen issues for RNTester after renaming package (#40)

feat: make hermes build for visionOS (#26)

* [WIP] feat: make hermes build for visionOS

* feat: point to callstack/hermes-visionos fork, update README

* fix: remove USE_HERMES from project.pbxproj

feat: align unnecessary compiler conditionals (#51)

chore: sync Podfile.lock

feat: implement OOT release script (#43)

* feat: implement OOT release script

* docs: add readme on Release process

* fix: remove header file

Co-authored-by: Michał Pierzchała <thymikee@gmail.com>

* add reference

---------

Co-authored-by: Michał Pierzchała <thymikee@gmail.com>

feat: add visionOS template (#34)

* Update CLI to v12.1.1

* feat: implement visionos react-native template

* feat: modify template look

* feat: add `@callstack/out-of-tree-platforms` to metro config

* fix: metro config

* feat: update supported platforms

---------

Co-authored-by: szymonrybczak <szymon.rybczak@gmail.com>

task(StatusBar component): show warn when using StatusBar (#49)

* task(StatusBar component): show warn when using StatusBar

* pr suggestions

docs: update CMake instructions (#55)

Fix iOS native tests (#58)

* fix: remove unnecessary libevent.podspec

* fix: make OCMock build for visionOS

fix: remove unnecessary YogaKit pod (#61)

feat: add warning while building Hermes that at least CMake 3.28.0 is required (#63)

fix: RCTAlertController transparent background override

added cornerRadius for hover style (#66)

* added corner radius for hover style

* fix: implement proper handling for old arch, reformat code

---------

Co-authored-by: Oskar Kwaśniewski <oskarkwasniewski@icloud.com>

chore: sync Podfile.lock

fix: don't warn users about the Keyboard API (#71)

feat: implement visionos cli commands (#64)

fix: use isVision instead of isVisionOS (#76)

fix: release build bundle (#74)

fix: remove duplicated isVision key (#78)

fix: change resolver option name (#79)

fix: RCTDeviceInfo UIApplicationDidChangeStatusBarOrientationNotification method

fix: update README.md with corrected capitalization (#84)

fix: upstream sync ifdefs

fix: providing unsupported value to hoverStyle crashed the app (#88)

fix: pointer events (#114)

fix: hoverEffect for bridgeless mode (#92)

refactor: remove unused RCTForegroundWindow (#94)

fix: properly retrieve window when clicking DevMenu action (#95)

sync with upstream

chore: sync Podfile.lock

docs: add how is it different from iOS version section (#91)

docs: move to documentation website (#119)

Update README.md (#121)

* Update README.md

* Update README.md

Co-authored-by: Kacper Rożniata <56474758+krozniata@users.noreply.github.com>

---------

Co-authored-by: Kacper Rożniata <56474758+krozniata@users.noreply.github.com>

Update getting started link in Readme. (#123)

Co-authored-by: christinamartinez <christina.martinez@faithlife.com>

chore: remove hover effect & add cursor: pointer (#122)

* chore: remove hover effect

* fix: set cursor pointer by default, update tests

* feat(iOS): Implement cursor style prop

---------

Co-authored-by: Saad Najmi <sanajmi@microsoft.com>

chore: resync with upstream

fix: change versio of @callstack/out-of-tree-platforms

feat: make SwiftUI React Native entry point (#68)

* feat: add Swift entrypoint

[wip] add module maps to some RN modules to allow for swift c++ imports

feat: implement RCTReactController and RCTSwiftUIAppDelegate

feat: introduce new method to RCTAppDelegate

* feat: modify template to use SwiftUI

* fix: dimensions, use RCTMainWindow()

* fix: fallback to DarkMode on visionOS

* fix: use KeyWindow() in RCTPerfMonitor

feat: update docs (#80)

* feat: update docs

* Update README.md

Co-authored-by: Michał Pierzchała <thymikee@gmail.com>

* Update README.md

Co-authored-by: Michał Pierzchała <thymikee@gmail.com>

* Update README.md

Co-authored-by: Michał Pierzchała <thymikee@gmail.com>

* Update README.md

Co-authored-by: Michał Pierzchała <thymikee@gmail.com>

* Update README.md

Co-authored-by: Michał Pierzchała <thymikee@gmail.com>

---------

Co-authored-by: Michał Pierzchała <thymikee@gmail.com>

feat: add UIApplicationSceneManifest to template

Create custom resolver and utils package for out-of-tree platforms (#32)

* rename react-native package to @callstack/react-native-visionos

* wip: metro setup for other platform

* fix(flow): add .ios.visionos as support platform

* fix some flow errors

* fix flow

* revert Platform.select change

* revert KeyboardAvoidingView change

* fix type

* change kBundlePath to ios.visionos

* fix: remove redundant isVisionOS

* use custom resolver options to read platform for OOT

* fix types

* remove formatting

* add/remove platform checks

* document variant behavior

* use visionOS Keyboard mock

* use visionOS KeyboardAvoidingView mock

* use visionOS InputAccessoryView mock

* test: add test for metroPlatformResolver

* move implementation to user space

* create out-of-tree-platforms package and bring back resolver options

* revert flow changes

* revert sourceExts changes

* update links

* add comments

* fix visionos typo

* adjust lockfile

* revert loadMetroConfig change

* remove podfile lock

* revert scripts changes

Fix build step for `@callstack/out-of-tree-platforms`  (#46)

* feat: setup @callstack/out-of-tree-platforms to build properly

* feat: add build packages step to `oot-release.js` script

* chore: format package.json

fix(#48) local build of @callstack/out-of-tree-platforms (#50)
  • Loading branch information
okwasniewski committed Jun 24, 2024
1 parent d1e2a35 commit b23b7ce
Show file tree
Hide file tree
Showing 124 changed files with 2,886 additions and 328 deletions.
4 changes: 2 additions & 2 deletions .circleci/configurations/jobs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -96,8 +96,8 @@ jobs:
- run:
name: "Run Tests: JavaScript Tests"
command: node ./scripts/run-ci-javascript-tests.js --maxWorkers 2
- run_e2e:
platform: js
# - run_e2e:
# platform: js

# Optionally, run disabled tests
- when:
Expand Down
147 changes: 26 additions & 121 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,147 +1,52 @@
<h1 align="center">
<a href="https://reactnative.dev/">
React Native
<a href="https://callstack.github.io/react-native-visionos-docs">
React Native visionOS
</a>
</h1>

<p align="center">
<strong>Learn once, write anywhere:</strong><br>
Build mobile apps with React.
Build spatial apps with React.
</p>

<p align="center">
<a href="https://github.com/facebook/react-native/blob/HEAD/LICENSE">
<img src="https://img.shields.io/badge/license-MIT-blue.svg" alt="React Native is released under the MIT license." />
</a>
<a href="https://circleci.com/gh/facebook/react-native">
<img src="https://circleci.com/gh/facebook/react-native.svg?style=shield" alt="Current CircleCI build status." />
</a>
<a href="https://www.npmjs.org/package/react-native">
<img src="https://img.shields.io/npm/v/react-native?color=brightgreen&label=npm%20package" alt="Current npm package version." />
</a>
<a href="https://reactnative.dev/docs/contributing">
<img src="https://img.shields.io/badge/PRs-welcome-brightgreen.svg" alt="PRs welcome!" />
</a>
<a href="https://twitter.com/intent/follow?screen_name=reactnative">
<img src="https://img.shields.io/twitter/follow/reactnative.svg?label=Follow%20@reactnative" alt="Follow @reactnative" />
</a>
</p>

<h3 align="center">
<a href="https://reactnative.dev/docs/getting-started">Getting Started</a>
<span> · </span>
<a href="https://reactnative.dev/docs/tutorial">Learn the Basics</a>
<span> · </span>
<a href="https://reactnative.dev/showcase">Showcase</a>
<span> · </span>
<a href="https://reactnative.dev/docs/contributing">Contribute</a>
<span> · </span>
<a href="https://reactnative.dev/help">Community</a>
<span> · </span>
<a href="https://github.com/facebook/react-native/blob/HEAD/.github/SUPPORT.md">Support</a>
</h3>

React Native brings [**React**'s][r] declarative UI framework to iOS and Android. With React Native, you use native UI controls and have full access to the native platform.

- **Declarative.** React makes it painless to create interactive UIs. Declarative views make your code more predictable and easier to debug.
- **Component-Based.** Build encapsulated components that manage their state, then compose them to make complex UIs.
- **Developer Velocity.** See local changes in seconds. Changes to JavaScript code can be live reloaded without rebuilding the native app.
- **Portability.** Reuse code across iOS, Android, and [other platforms][p].

React Native is developed and supported by many companies and individual core contributors. Find out more in our [ecosystem overview][e].

[r]: https://react.dev/
[p]: https://reactnative.dev/docs/out-of-tree-platforms
[e]: https://github.com/facebook/react-native/blob/HEAD/ECOSYSTEM.md

## Contents

- [Requirements](#-requirements)
- [Building your first React Native app](#-building-your-first-react-native-app)
- [Documentation](#-documentation)
- [Upgrading](#-upgrading)
- [How to Contribute](#-how-to-contribute)
- [Code of Conduct](#code-of-conduct)
- [License](#-license)


## 📋 Requirements

React Native apps may target iOS 13.4 and Android 6.0 (API 23) or newer. You may use Windows, macOS, or Linux as your development operating system, though building and running iOS apps is limited to macOS. Tools like [Expo](https://expo.dev) can be used to work around this.
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.

## 🎉 Building your first React Native app
![Screenshot](https://github.com/callstack/react-native-visionos/assets/52801365/0fcd5e5f-628c-49ef-84ab-d1d4675a011a)

Follow the [Getting Started guide](https://reactnative.dev/docs/getting-started). The recommended way to install React Native depends on your project. Here you can find short guides for the most common scenarios:
## 🎉 Building your first spatial React Native app
Follow the [Getting Started](https://callstack.github.io/react-native-visionos-docs/category/getting-started) guide. If you wish to get started quickly, you can utilize this command:

- [Trying out React Native][hello-world]
- [Creating a New Application][new-app]
- [Adding React Native to an Existing Application][existing]
```sh
npx @callstack/react-native-visionos@latest init YourApp
```

[hello-world]: https://snack.expo.dev/@samples/hello-world
[new-app]: https://reactnative.dev/docs/getting-started
[existing]: https://reactnative.dev/docs/integration-with-existing-apps

## 📖 Documentation

The full documentation for React Native can be found on our [website][docs].

The React Native documentation discusses components, APIs, and topics that are specific to React Native. For further documentation on the React API that is shared between React Native and React DOM, refer to the [React documentation][r-docs].

The source for the React Native documentation and website is hosted on a separate repo, [**@facebook/react-native-website**][repo-website].

[docs]: https://reactnative.dev/docs/getting-started
[r-docs]: https://react.dev/learn
[repo-website]: https://github.com/facebook/react-native-website

## 🚀 Upgrading

Upgrading to new versions of React Native may give you access to more APIs, views, developer tools, and other goodies. See the [Upgrading Guide][u] for instructions.

React Native releases are discussed [in this discussion repo](https://github.com/reactwg/react-native-releases/discussions).

[u]: https://reactnative.dev/docs/upgrading
[repo-releases]: https://github.com/react-native-community/react-native-releases

## 👏 How to Contribute

The main purpose of this repository is to continue evolving React Native core. We want to make contributing to this project as easy and transparent as possible, and we are grateful to the community for contributing bug fixes and improvements. Read below to learn how you can take part in improving React Native.

### [Code of Conduct][code]

Facebook has adopted a Code of Conduct that we expect project participants to adhere to.
Please read the [full text][code] so that you can understand what actions will and will not be tolerated.

[code]: https://code.fb.com/codeofconduct/

### [Contributing Guide][contribute]

Read our [**Contributing Guide**][contribute] to learn about our development process, how to propose bugfixes and improvements, and how to build and test your changes to React Native.

[contribute]: https://reactnative.dev/docs/contributing

### [Open Source Roadmap][roadmap]

You can learn more about our vision for React Native in the [**Roadmap**][roadmap].
The full documentation for React Native visionOS can be found on our [website](https://callstack.github.io/react-native-visionos-docs).

[roadmap]: https://github.com/facebook/react-native/wiki/Roadmap
The source for the React Native visionOS documentation and website is hosted on a separate repo, @callstack/react-native-visionos-docs.

### Good First Issues
## Contributing

We have a list of [good first issues][gfi] that contain bugs which have a relatively limited scope. This is a great place to get started, gain experience, and get familiar with our contribution process.
Prerequisites:
- Download the latest Xcode (at least 15.2)
- Install the latest version of CMake (at least v3.28.0)

[gfi]: https://github.com/facebook/react-native/labels/good%20first%20issue
Check out `rn-tester` [README.md](./packages/rn-tester/README.md) to build React Native from the source.

### Discussions
Remember to use `RNTester-visionOS` target

Larger discussions and proposals are discussed in [**@react-native-community/discussions-and-proposals**][repo-meta].
If `RNTester-visionOS` scheme is not showing up, click "New Scheme", which should be pre-populated with `RNTester-visionOS`. Build the app using Xcode.

[repo-meta]: https://github.com/react-native-community/discussions-and-proposals
## Release process

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

React Native is MIT licensed, as found in the [LICENSE][l] file.
Usage:

React Native documentation is Creative Commons licensed, as found in the [LICENSE-docs][ld] file.
```sh
node ./scripts/oot-release.js --new-version "<visionos-version>" --react-native-version "<react-native-version>" --one-time-password "<otp>"
```

[l]: https://github.com/facebook/react-native/blob/main/LICENSE
[ld]: https://github.com/facebook/react-native/blob/main/LICENSE-docs
To test releases and template we use [Verdaccio](https://verdaccio.org/).
3 changes: 3 additions & 0 deletions jest.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,9 @@ module.exports = {
platforms: ['ios', 'android'],
},
moduleNameMapper: {
// These mappers allow out-of-tree platforms tests to seamlessly resolve RN imports
'^react-native/(.*)': '<rootDir>/packages/react-native/$1',
'^react-native$': '<rootDir>/packages/react-native/index.js',
// This module is internal to Meta and used by their custom React renderer.
// In tests, we can just use a mock.
'^ReactNativeInternalFeatureFlags$':
Expand Down
2 changes: 2 additions & 0 deletions packages/out-of-tree-platforms/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
# Build output
/dist
19 changes: 19 additions & 0 deletions packages/out-of-tree-platforms/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
# @callstack/out-of-tree-platforms

[![Version][version-badge]][package]

Utilities for Out of Tree (OOT) platforms.

## `getPlatformResolver`

```js
getPlatformResolver(options: ResolverConfig): CustomResolver
```

### options

```js
type ResolverConfig = {
platformImplementations: {[platform: string]: string},
};
```
1 change: 1 addition & 0 deletions packages/out-of-tree-platforms/index.js.flow
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export * from './src';
27 changes: 27 additions & 0 deletions packages/out-of-tree-platforms/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
{
"name": "@callstack/out-of-tree-platforms",
"version": "0.75.0-main",
"description": "Utils for React Native out of tree platforms.",
"keywords": ["out-of-tree", "react-native"],
"homepage": "https://github.com/callstack/react-native-visionos/tree/HEAD/packages/out-of-tree-platforms#readme",
"bugs": "https://github.com/callstack/react-native-visionos/issues",
"repository": {
"type": "git",
"url": "https://github.com/callstack/react-native-visionos.git",
"directory": "packages/out-of-tree-platforms"
},
"license": "MIT",
"exports": {
".": "./src/index.js",
"./package.json": "./package.json"
},
"files": [
"dist"
],
"devDependencies": {
"metro-resolver": "^0.80.0"
},
"engines": {
"node": ">=18"
}
}
43 changes: 43 additions & 0 deletions packages/out-of-tree-platforms/src/getPlatformResolver.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
/**
* Copyright (c) Meta Platforms, Inc. and affiliates.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*
* @flow
* @format
*/

import type {CustomResolver} from 'metro-resolver';

type ResolverConfig = {
platformNameMap: {[platform: string]: string},
};

/**
* Creates a custom Metro resolver that maps platform extensions to package names.
* To be used in app's `metro.config.js` as `resolver.resolveRequest`.
*/
export const getPlatformResolver = (config: ResolverConfig): CustomResolver => {
return (context, moduleName, platform) => {
// `customResolverOptions` is populated through `?resolver.platformExtension` query params
// in the jsBundleURLForBundleRoot method of the react-native/React/Base/RCTBundleURLProvider.mm
const platformExtension = context.customResolverOptions?.platformExtension;
let modifiedModuleName = moduleName;
if (
typeof platformExtension === 'string' &&
config.platformNameMap?.[platformExtension]
) {
const packageName = config.platformNameMap[platformExtension];
if (moduleName === 'react-native') {
modifiedModuleName = packageName;
} else if (moduleName.startsWith('react-native/')) {
modifiedModuleName = `${packageName}/${modifiedModuleName.slice(
'react-native/'.length,
)}`;
}
}

return context.resolveRequest(context, modifiedModuleName, platform);
};
};
5 changes: 5 additions & 0 deletions packages/out-of-tree-platforms/src/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
if (!process.env.BUILD_EXCLUDE_BABEL_REGISTER) {
require('../../../scripts/build/babel-register').registerForMonorepo();
}

export * from './getPlatformResolver';
12 changes: 1 addition & 11 deletions packages/react-native/Libraries/AppDelegate/RCTAppDelegate.mm
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
#import <react/renderer/graphics/ColorComponents.h>
#import "RCTAppDelegate+Protected.h"
#import "RCTAppSetupUtils.h"
#import <objc/runtime.h>

#if RN_DISABLE_OSS_PLUGIN_HEADER
#import <RCTTurboModulePlugin/RCTTurboModulePlugin.h>
Expand Down Expand Up @@ -57,22 +58,11 @@ - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(

self.rootViewFactory = [self createRCTRootViewFactory];

UIView *rootView = [self.rootViewFactory viewWithModuleName:self.moduleName
initialProperties:self.initialProps
launchOptions:launchOptions];

if (self.newArchEnabled || self.fabricEnabled) {
[RCTComponentViewFactory currentComponentViewFactory].thirdPartyFabricComponentsProvider = self;
}
[self _logWarnIfCreateRootViewWithBridgeIsOverridden];

self.window = [[UIWindow alloc] initWithFrame:[UIScreen mainScreen].bounds];
UIViewController *rootViewController = [self createRootViewController];
[self setRootView:rootView toRootViewController:rootViewController];
self.window.rootViewController = rootViewController;
self.window.windowScene.delegate = self;
[self.window makeKeyAndVisible];

return YES;
}

Expand Down
17 changes: 17 additions & 0 deletions packages/react-native/Libraries/Components/Keyboard/Keyboard.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import LayoutAnimation from '../../LayoutAnimation/LayoutAnimation';
import dismissKeyboard from '../../Utilities/dismissKeyboard';
import Platform from '../../Utilities/Platform';
import NativeKeyboardObserver from './NativeKeyboardObserver';
import warnOnce from '../../Utilities/warnOnce';

export type KeyboardEventName = $Keys<KeyboardEventDefinitions>;

Expand Down Expand Up @@ -114,6 +115,10 @@ class Keyboard {
);

constructor() {
if (Platform.isVision) {
return;
}

this.addListener('keyboardDidShow', ev => {
this._currentlyShowing = ev;
});
Expand Down Expand Up @@ -151,6 +156,14 @@ class Keyboard {
listener: (...$ElementType<KeyboardEventDefinitions, K>) => mixed,
context?: mixed,
): EventSubscription {
if (Platform.isVision) {
warnOnce(
'Keyboard-unavailable',
'Keyboard API is not available on visionOS platform. The system displays the keyboard in a separate window, leaving the app’s window unaffected by the keyboard’s appearance and disappearance',
);
return {remove() {}};
}

return this._emitter.addListener(eventType, listener);
}

Expand All @@ -160,6 +173,10 @@ class Keyboard {
* @param {string} eventType The native event string listeners are watching which will be removed.
*/
removeAllListeners<K: $Keys<KeyboardEventDefinitions>>(eventType: ?K): void {
if (Platform.isVision) {
return;
}

this._emitter.removeAllListeners(eventType);
}

Expand Down
Loading

0 comments on commit b23b7ce

Please sign in to comment.