Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
30 commits
Select commit Hold shift + click to select a range
85e8eb8
rename react-native package to @callstack/react-native-visionos
thymikee Nov 29, 2023
f8ed176
wip: metro setup for other platform
thymikee Nov 17, 2023
203567a
fix(flow): add .ios.visionos as support platform
thymikee Nov 22, 2023
72f420d
fix some flow errors
thymikee Nov 22, 2023
fae6fb2
fix flow
thymikee Nov 23, 2023
0fb67b7
revert Platform.select change
thymikee Nov 23, 2023
5b09982
revert KeyboardAvoidingView change
thymikee Nov 23, 2023
e1a4980
fix type
thymikee Nov 23, 2023
5591166
change kBundlePath to ios.visionos
thymikee Nov 24, 2023
152427b
fix: remove redundant isVisionOS
thymikee Nov 24, 2023
3c48e97
use custom resolver options to read platform for OOT
thymikee Nov 24, 2023
9789261
fix types
thymikee Nov 24, 2023
c156143
remove formatting
thymikee Nov 24, 2023
230589d
add/remove platform checks
thymikee Nov 24, 2023
fbc4ca9
document variant behavior
thymikee Nov 24, 2023
f7d3471
use visionOS Keyboard mock
thymikee Nov 24, 2023
670240d
use visionOS KeyboardAvoidingView mock
thymikee Nov 24, 2023
097b1c8
use visionOS InputAccessoryView mock
thymikee Nov 24, 2023
83c6b2c
test: add test for metroPlatformResolver
thymikee Nov 27, 2023
5ac0275
move implementation to user space
thymikee Nov 28, 2023
428a0fe
create out-of-tree-platforms package and bring back resolver options
thymikee Nov 29, 2023
4e3cf9d
revert flow changes
thymikee Nov 29, 2023
e7517b6
revert sourceExts changes
thymikee Nov 29, 2023
8795f64
update links
thymikee Nov 29, 2023
ae757e3
add comments
thymikee Nov 29, 2023
bf72cdc
fix visionos typo
thymikee Nov 29, 2023
46cbe85
adjust lockfile
thymikee Nov 29, 2023
a57a76b
revert loadMetroConfig change
thymikee Nov 29, 2023
f91c29a
remove podfile lock
thymikee Nov 30, 2023
69722ec
revert scripts changes
thymikee Nov 30, 2023
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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},
};
```
46 changes: 46 additions & 0 deletions packages/out-of-tree-platforms/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
/**
* 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`.
*/
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);
};
};

module.exports = {getPlatformResolver};
24 changes: 24 additions & 0 deletions packages/out-of-tree-platforms/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
{
"name": "@callstack/out-of-tree-platforms",
"version": "0.74.0",
"description": "Utils for React Native out of tree platforms.",
"license": "MIT",
"repository": {
"type": "git",
"url": "https://github.com/callstack/react-native-visionos.git",
"directory": "packages/out-of-tree-platforms"
},
"homepage": "https://github.com/callstack/react-native-visionos/tree/HEAD/packages/out-of-tree-platforms#readme",
"keywords": [
"out-of-tree",
"react-native"
],
"bugs": "https://github.com/facebook/react-native/issues",
"engines": {
"node": ">=18"
},
"exports": "./index.js",
"devDependencies": {
"metro-resolver": "^0.80.0"
}
}
3 changes: 3 additions & 0 deletions packages/react-native/React/Base/RCTBundleURLProvider.mm
Original file line number Diff line number Diff line change
Expand Up @@ -308,6 +308,9 @@ + (NSURL *)jsBundleURLForBundleRoot:(NSString *)bundleRoot
BOOL lazy = enableDev;
NSArray<NSURLQueryItem *> *queryItems = @[
[[NSURLQueryItem alloc] initWithName:@"platform" value:RCTPlatformName],
#if TARGET_OS_VISION
[[NSURLQueryItem alloc] initWithName:@"resolver.platformExtension" value:RCTPlatformExtension],
#endif
[[NSURLQueryItem alloc] initWithName:@"dev" value:enableDev ? @"true" : @"false"],
[[NSURLQueryItem alloc] initWithName:@"lazy" value:lazy ? @"true" : @"false"],
[[NSURLQueryItem alloc] initWithName:@"minify" value:enableMinification ? @"true" : @"false"],
Expand Down
3 changes: 3 additions & 0 deletions packages/react-native/React/Base/RCTConstants.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,9 @@
#import <React/RCTDefines.h>

RCT_EXTERN NSString *const RCTPlatformName;
#if TARGET_OS_VISION
RCT_EXTERN NSString *const RCTPlatformExtension;
#endif

RCT_EXTERN NSString *const RCTUserInterfaceStyleDidChangeNotification;
RCT_EXTERN NSString *const RCTUserInterfaceStyleDidChangeNotificationTraitCollectionKey;
Expand Down
3 changes: 3 additions & 0 deletions packages/react-native/React/Base/RCTConstants.m
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,9 @@
#import "RCTConstants.h"

NSString *const RCTPlatformName = @"ios";
#if TARGET_OS_VISION
NSString *const RCTPlatformExtension = @"visionos";
#endif

NSString *const RCTUserInterfaceStyleDidChangeNotification = @"RCTUserInterfaceStyleDidChangeNotification";
NSString *const RCTUserInterfaceStyleDidChangeNotificationTraitCollectionKey = @"traitCollection";
Expand Down
4 changes: 4 additions & 0 deletions packages/rn-tester/metro.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@

'use strict';

const {getPlatformResolver} = require('@callstack/out-of-tree-platforms');
const {getDefaultConfig} = require('@react-native/metro-config');
const {mergeConfig} = require('metro-config');
const path = require('path');
Expand Down Expand Up @@ -36,6 +37,9 @@ const config = {
extraNodeModules: {
'react-native': path.resolve(__dirname, '../react-native'),
},
resolveRequest: getPlatformResolver({
platformNameMap: [{visionos: '@callstack/react-native-visionos'}],
}),
},
};

Expand Down