Skip to content

Commit 8e24fae

Browse files
committed
feat: add visionos support
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 # Conflicts: # README.md # packages/react-native/Libraries/AppDelegate/RCTAppDelegate.mm # packages/react-native/Libraries/PushNotificationIOS/RCTPushNotificationManager.h # packages/react-native/Libraries/PushNotificationIOS/RCTPushNotificationManager.mm # packages/react-native/Libraries/Text/Text/RCTTextView.mm # packages/react-native/React-Core.podspec # packages/react-native/React/CoreModules/RCTStatusBarManager.mm # packages/react-native/React/CoreModules/React-CoreModules.podspec # packages/react-native/React/Fabric/Mounting/ComponentViews/Text/RCTParagraphComponentView.mm # packages/react-native/React/Views/RCTWrapperViewController.m # packages/react-native/scripts/cocoapods/helpers.rb # packages/rn-tester/Gemfile # packages/rn-tester/RNTester/AppDelegate.mm # packages/rn-tester/RNTesterPods.xcodeproj/project.pbxproj
1 parent cd7eb69 commit 8e24fae

File tree

55 files changed

+1081
-197
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

55 files changed

+1081
-197
lines changed

README.md

Lines changed: 8 additions & 135 deletions
Original file line numberDiff line numberDiff line change
@@ -1,147 +1,20 @@
11
<h1 align="center">
22
<a href="https://reactnative.dev/">
3-
React Native
3+
React Native Vision OS
44
</a>
55
</h1>
66

77
<p align="center">
88
<strong>Learn once, write anywhere:</strong><br>
9-
Build mobile apps with React.
9+
Build spatial apps with React.
1010
</p>
1111

12-
<p align="center">
13-
<a href="https://github.com/facebook/react-native/blob/HEAD/LICENSE">
14-
<img src="https://img.shields.io/badge/license-MIT-blue.svg" alt="React Native is released under the MIT license." />
15-
</a>
16-
<a href="https://circleci.com/gh/facebook/react-native">
17-
<img src="https://circleci.com/gh/facebook/react-native.svg?style=shield" alt="Current CircleCI build status." />
18-
</a>
19-
<a href="https://www.npmjs.org/package/react-native">
20-
<img src="https://img.shields.io/npm/v/react-native?color=brightgreen&label=npm%20package" alt="Current npm package version." />
21-
</a>
22-
<a href="https://reactnative.dev/docs/contributing">
23-
<img src="https://img.shields.io/badge/PRs-welcome-brightgreen.svg" alt="PRs welcome!" />
24-
</a>
25-
<a href="https://twitter.com/intent/follow?screen_name=reactnative">
26-
<img src="https://img.shields.io/twitter/follow/reactnative.svg?label=Follow%20@reactnative" alt="Follow @reactnative" />
27-
</a>
28-
</p>
29-
30-
<h3 align="center">
31-
<a href="https://reactnative.dev/docs/getting-started">Getting Started</a>
32-
<span> · </span>
33-
<a href="https://reactnative.dev/docs/tutorial">Learn the Basics</a>
34-
<span> · </span>
35-
<a href="https://reactnative.dev/showcase">Showcase</a>
36-
<span> · </span>
37-
<a href="https://reactnative.dev/docs/contributing">Contribute</a>
38-
<span> · </span>
39-
<a href="https://reactnative.dev/help">Community</a>
40-
<span> · </span>
41-
<a href="https://github.com/facebook/react-native/blob/HEAD/.github/SUPPORT.md">Support</a>
42-
</h3>
43-
44-
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.
45-
46-
- **Declarative.** React makes it painless to create interactive UIs. Declarative views make your code more predictable and easier to debug.
47-
- **Component-Based.** Build encapsulated components that manage their state, then compose them to make complex UIs.
48-
- **Developer Velocity.** See local changes in seconds. Changes to JavaScript code can be live reloaded without rebuilding the native app.
49-
- **Portability.** Reuse code across iOS, Android, and [other platforms][p].
50-
51-
React Native is developed and supported by many companies and individual core contributors. Find out more in our [ecosystem overview][e].
52-
53-
[r]: https://react.dev/
54-
[p]: https://reactnative.dev/docs/out-of-tree-platforms
55-
[e]: https://github.com/facebook/react-native/blob/HEAD/ECOSYSTEM.md
56-
57-
## Contents
58-
59-
- [Requirements](#-requirements)
60-
- [Building your first React Native app](#-building-your-first-react-native-app)
61-
- [Documentation](#-documentation)
62-
- [Upgrading](#-upgrading)
63-
- [How to Contribute](#-how-to-contribute)
64-
- [Code of Conduct](#code-of-conduct)
65-
- [License](#-license)
66-
67-
68-
## 📋 Requirements
69-
70-
React Native apps may target iOS 13.4 and Android 5.0 (API 21) 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.
71-
72-
## 🎉 Building your first React Native app
73-
74-
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:
75-
76-
- [Trying out React Native][hello-world]
77-
- [Creating a New Application][new-app]
78-
- [Adding React Native to an Existing Application][existing]
79-
80-
[hello-world]: https://snack.expo.dev/@samples/hello-world
81-
[new-app]: https://reactnative.dev/docs/getting-started
82-
[existing]: https://reactnative.dev/docs/integration-with-existing-apps
83-
84-
## 📖 Documentation
85-
86-
The full documentation for React Native can be found on our [website][docs].
87-
88-
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].
89-
90-
The source for the React Native documentation and website is hosted on a separate repo, [**@facebook/react-native-website**][repo-website].
91-
92-
[docs]: https://reactnative.dev/docs/getting-started
93-
[r-docs]: https://react.dev/learn
94-
[repo-website]: https://github.com/facebook/react-native-website
95-
96-
## 🚀 Upgrading
97-
98-
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.
99-
100-
React Native releases are discussed [in this discussion repo](https://github.com/reactwg/react-native-releases/discussions).
101-
102-
[u]: https://reactnative.dev/docs/upgrading
103-
[repo-releases]: https://github.com/react-native-community/react-native-releases
104-
105-
## 👏 How to Contribute
106-
107-
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.
108-
109-
### [Code of Conduct][code]
110-
111-
Facebook has adopted a Code of Conduct that we expect project participants to adhere to.
112-
Please read the [full text][code] so that you can understand what actions will and will not be tolerated.
113-
114-
[code]: https://code.fb.com/codeofconduct/
115-
116-
### [Contributing Guide][contribute]
117-
118-
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.
119-
120-
[contribute]: https://reactnative.dev/docs/contributing
121-
122-
### [Open Source Roadmap][roadmap]
123-
124-
You can learn more about our vision for React Native in the [**Roadmap**][roadmap].
125-
126-
[roadmap]: https://github.com/facebook/react-native/wiki/Roadmap
127-
128-
### Good First Issues
129-
130-
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.
131-
132-
[gfi]: https://github.com/facebook/react-native/labels/good%20first%20issue
133-
134-
### Discussions
135-
136-
Larger discussions and proposals are discussed in [**@react-native-community/discussions-and-proposals**][repo-meta].
137-
138-
[repo-meta]: https://github.com/react-native-community/discussions-and-proposals
139-
140-
## 📄 License
12+
React Native Vision OS 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.
14113

142-
React Native is MIT licensed, as found in the [LICENSE][l] file.
14+
This project is still at an early stage of development and is not ready for production use.
14315

144-
React Native documentation is Creative Commons licensed, as found in the [LICENSE-docs][ld] file.
16+
## Contributing
14517

146-
[l]: https://github.com/facebook/react-native/blob/main/LICENSE
147-
[ld]: https://github.com/facebook/react-native/blob/main/LICENSE-docs
18+
1. Download latest Xcode beta [here](https://developer.apple.com/xcode/).
19+
2. Install visionOS Simulator runtime.
20+
3. Follow the same steps as for running iOS defined in [packages/rn-tester/README.md](./packages/rn-tester/README.md)

packages/react-native/Libraries/AppDelegate/RCTAppDelegate.mm

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
#import <React/RCTSurfacePresenterBridgeAdapter.h>
1212
#import <react/renderer/runtimescheduler/RuntimeScheduler.h>
1313
#import "RCTAppSetupUtils.h"
14+
#import <React/RCTUtils.h>
1415
#import "RCTLegacyInteropComponents.h"
1516

1617
#if RCT_NEW_ARCH_ENABLED
@@ -49,6 +50,21 @@ @interface RCTAppDelegate () <
4950

5051
#endif
5152

53+
#if TARGET_OS_VISION
54+
@interface GlassViewController : UIViewController
55+
56+
@end
57+
58+
@implementation GlassViewController
59+
60+
- (UIContainerBackgroundStyle)preferredContainerBackgroundStyle {
61+
return UIContainerBackgroundStyleGlass;
62+
}
63+
64+
@end
65+
#endif
66+
67+
5268
static NSDictionary *updateInitialProps(NSDictionary *initialProps, BOOL isFabricEnabled)
5369
{
5470
#ifdef RCT_NEW_ARCH_ENABLED
@@ -136,7 +152,14 @@ - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(
136152

137153
rootView = [self createRootViewWithBridge:self.bridge moduleName:self.moduleName initProps:initProps];
138154
}
155+
156+
[self customizeRootView:(RCTRootView *)rootView];
157+
#if TARGET_OS_VISION
158+
self.window = [[UIWindow alloc] initWithFrame:RCTForegroundWindow().bounds];
159+
#else
139160
self.window = [[UIWindow alloc] initWithFrame:[UIScreen mainScreen].bounds];
161+
#endif
162+
140163
UIViewController *rootViewController = [self createRootViewController];
141164
[self setRootView:rootView toRootViewController:rootViewController];
142165
self.window.rootViewController = rootViewController;
@@ -180,7 +203,11 @@ - (UIView *)createRootViewWithBridge:(RCTBridge *)bridge
180203

181204
- (UIViewController *)createRootViewController
182205
{
206+
#if TARGET_OS_VISION
207+
return [GlassViewController new];
208+
#else
183209
return [UIViewController new];
210+
#endif
184211
}
185212

186213
- (void)setRootView:(UIView *)rootView toRootViewController:(UIViewController *)rootViewController

packages/react-native/Libraries/Components/Pressable/Pressable.js

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ import type {
2020
AccessibilityState,
2121
AccessibilityValue,
2222
} from '../View/ViewAccessibility';
23+
import type {HoverEffect} from '../View/ViewPropTypes';
2324

2425
import {PressabilityDebugView} from '../../Pressability/PressabilityDebug';
2526
import usePressability from '../../Pressability/usePressability';
@@ -32,12 +33,18 @@ import useAndroidRippleForView, {
3233
import * as React from 'react';
3334
import {useImperativeHandle, useMemo, useRef, useState} from 'react';
3435

36+
const defaultHoverEffect: HoverEffect = 'highlight';
37+
3538
type ViewStyleProp = $ElementType<React.ElementConfig<typeof View>, 'style'>;
3639

3740
export type StateCallbackType = $ReadOnly<{|
3841
pressed: boolean,
3942
|}>;
4043

44+
type VisionOSProps = $ReadOnly<{|
45+
visionos_hoverEffect?: ?HoverEffect,
46+
|}>;
47+
4148
type Props = $ReadOnly<{|
4249
/**
4350
* Accessibility.
@@ -193,6 +200,10 @@ type Props = $ReadOnly<{|
193200
* https://github.com/facebook/react-native/issues/34424
194201
*/
195202
'aria-label'?: ?string,
203+
/**
204+
* Props needed for visionOS.
205+
*/
206+
...VisionOSProps,
196207
|}>;
197208

198209
/**
@@ -232,6 +243,7 @@ function Pressable(props: Props, forwardedRef): React.Node {
232243
style,
233244
testOnly_pressed,
234245
unstable_pressDelay,
246+
visionos_hoverEffect = defaultHoverEffect,
235247
...restProps
236248
} = props;
237249

@@ -341,7 +353,8 @@ function Pressable(props: Props, forwardedRef): React.Node {
341353
{...eventHandlers}
342354
ref={mergedRef}
343355
style={typeof style === 'function' ? style({pressed}) : style}
344-
collapsable={false}>
356+
collapsable={false}
357+
visionos_hoverEffect={visionos_hoverEffect}>
345358
{typeof children === 'function' ? children({pressed}) : children}
346359
{__DEV__ ? <PressabilityDebugView color="red" hitSlop={hitSlop} /> : null}
347360
</View>

packages/react-native/Libraries/Components/Touchable/TouchableHighlight.js

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
*/
1010

1111
import type {ColorValue} from '../../StyleSheet/StyleSheet';
12+
import type {HoverEffect} from '../View/ViewPropTypes';
1213
import typeof TouchableWithoutFeedback from './TouchableWithoutFeedback';
1314

1415
import View from '../../Components/View/View';
@@ -32,10 +33,15 @@ type IOSProps = $ReadOnly<{|
3233
hasTVPreferredFocus?: ?boolean,
3334
|}>;
3435

36+
type VisionOSProps = $ReadOnly<{|
37+
hoverEffect?: ?HoverEffect,
38+
|}>;
39+
3540
type Props = $ReadOnly<{|
3641
...React.ElementConfig<TouchableWithoutFeedback>,
3742
...AndroidProps,
3843
...IOSProps,
44+
...VisionOSProps,
3945

4046
activeOpacity?: ?number,
4147
underlayColor?: ?ColorValue,
@@ -341,6 +347,7 @@ class TouchableHighlight extends React.Component<Props, State> {
341347
nextFocusLeft={this.props.nextFocusLeft}
342348
nextFocusRight={this.props.nextFocusRight}
343349
nextFocusUp={this.props.nextFocusUp}
350+
visionos_hoverEffect={this.props.hoverEffect}
344351
focusable={
345352
this.props.focusable !== false && this.props.onPress !== undefined
346353
}

packages/react-native/Libraries/Components/Touchable/TouchableOpacity.d.ts

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ import type * as React from 'react';
1111
import {Constructor} from '../../../types/private/Utilities';
1212
import {TimerMixin} from '../../../types/private/TimerMixin';
1313
import {NativeMethods} from '../../../types/public/ReactNativeTypes';
14-
import {TVParallaxProperties} from '../View/ViewPropTypes';
14+
import {HoverEffect, TVParallaxProperties} from '../View/ViewPropTypes';
1515
import {TouchableMixin} from './Touchable';
1616
import {TouchableWithoutFeedbackProps} from './TouchableWithoutFeedback';
1717

@@ -86,6 +86,11 @@ export interface TouchableOpacityProps
8686
* @platform android
8787
*/
8888
tvParallaxProperties?: TVParallaxProperties | undefined;
89+
90+
/**
91+
* Hover style to apply to the view. Only supported on visionOS.
92+
*/
93+
visionos_hoverEffect?: HoverEffect | undefined;
8994
}
9095

9196
/**

packages/react-native/Libraries/Components/Touchable/TouchableOpacity.js

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
*/
1010

1111
import type {ViewStyleProp} from '../../StyleSheet/StyleSheet';
12+
import type {HoverEffect} from '../View/ViewPropTypes';
1213
import typeof TouchableWithoutFeedback from './TouchableWithoutFeedback';
1314

1415
import Animated from '../../Animated/Animated';
@@ -21,6 +22,8 @@ import flattenStyle from '../../StyleSheet/flattenStyle';
2122
import Platform from '../../Utilities/Platform';
2223
import * as React from 'react';
2324

25+
const defaultHoverEffect: HoverEffect = 'highlight';
26+
2427
type TVProps = $ReadOnly<{|
2528
hasTVPreferredFocus?: ?boolean,
2629
nextFocusDown?: ?number,
@@ -30,9 +33,14 @@ type TVProps = $ReadOnly<{|
3033
nextFocusUp?: ?number,
3134
|}>;
3235

36+
type VisionOSProps = $ReadOnly<{|
37+
visionos_hoverEffect?: ?HoverEffect,
38+
|}>;
39+
3340
type Props = $ReadOnly<{|
3441
...React.ElementConfig<TouchableWithoutFeedback>,
3542
...TVProps,
43+
...VisionOSProps,
3644

3745
activeOpacity?: ?number,
3846
style?: ?ViewStyleProp,
@@ -130,6 +138,10 @@ type State = $ReadOnly<{|
130138
*
131139
*/
132140
class TouchableOpacity extends React.Component<Props, State> {
141+
static defaultProps: {|visionos_hoverEffect: HoverEffect|} = {
142+
visionos_hoverEffect: defaultHoverEffect,
143+
};
144+
133145
state: State = {
134146
anim: new Animated.Value(this._getChildStyleOpacityWithDefault()),
135147
pressability: new Pressability(this._createPressabilityConfig()),
@@ -286,6 +298,7 @@ class TouchableOpacity extends React.Component<Props, State> {
286298
nextFocusUp={this.props.nextFocusUp}
287299
hasTVPreferredFocus={this.props.hasTVPreferredFocus}
288300
hitSlop={this.props.hitSlop}
301+
visionos_hoverEffect={this.props.visionos_hoverEffect}
289302
focusable={
290303
this.props.focusable !== false && this.props.onPress !== undefined
291304
}

packages/react-native/Libraries/Components/View/ViewPropTypes.d.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@ import {LayoutChangeEvent, PointerEvents} from '../../Types/CoreEventTypes';
1616
import {Touchable} from '../Touchable/Touchable';
1717
import {AccessibilityProps} from './ViewAccessibility';
1818

19+
export type HoverEffect = 'lift' | 'highlight';
20+
1921
export type TVParallaxProperties = {
2022
/**
2123
* If true, parallax effects are enabled. Defaults to true.
@@ -122,6 +124,10 @@ export interface ViewPropsIOS extends TVViewPropsIOS {
122124
* Test and measure when using this property.
123125
*/
124126
shouldRasterizeIOS?: boolean | undefined;
127+
/**
128+
* Hover style to apply to the view. Only supported on visionOS.
129+
*/
130+
visionos_hoverEffect?: HoverEffect | undefined;
125131
}
126132

127133
export interface ViewPropsAndroid {

0 commit comments

Comments
 (0)