forked from facebook/react-native
-
Notifications
You must be signed in to change notification settings - Fork 32
Create custom resolver and utils package for out-of-tree platforms #32
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
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 f8ed176
wip: metro setup for other platform
thymikee 203567a
fix(flow): add .ios.visionos as support platform
thymikee 72f420d
fix some flow errors
thymikee fae6fb2
fix flow
thymikee 0fb67b7
revert Platform.select change
thymikee 5b09982
revert KeyboardAvoidingView change
thymikee e1a4980
fix type
thymikee 5591166
change kBundlePath to ios.visionos
thymikee 152427b
fix: remove redundant isVisionOS
thymikee 3c48e97
use custom resolver options to read platform for OOT
thymikee 9789261
fix types
thymikee c156143
remove formatting
thymikee 230589d
add/remove platform checks
thymikee fbc4ca9
document variant behavior
thymikee f7d3471
use visionOS Keyboard mock
thymikee 670240d
use visionOS KeyboardAvoidingView mock
thymikee 097b1c8
use visionOS InputAccessoryView mock
thymikee 83c6b2c
test: add test for metroPlatformResolver
thymikee 5ac0275
move implementation to user space
thymikee 428a0fe
create out-of-tree-platforms package and bring back resolver options
thymikee 4e3cf9d
revert flow changes
thymikee e7517b6
revert sourceExts changes
thymikee 8795f64
update links
thymikee ae757e3
add comments
thymikee bf72cdc
fix visionos typo
thymikee 46cbe85
adjust lockfile
thymikee a57a76b
revert loadMetroConfig change
thymikee f91c29a
remove podfile lock
thymikee 69722ec
revert scripts changes
thymikee File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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}, | ||
| }; | ||
| ``` |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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}; | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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" | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.