-
Notifications
You must be signed in to change notification settings - Fork 47.2k
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
Extracted definition and access to public instances to a separate module in Fabric #26291
Closed
rubennorte
wants to merge
2
commits into
facebook:main
from
rubennorte:extract-react-fabric-public-instance-handling-to-module
Closed
Changes from all commits
Commits
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 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 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 |
---|---|---|
|
@@ -28,6 +28,7 @@ import { | |
import {createPortal as createPortalImpl} from 'react-reconciler/src/ReactPortal'; | ||
import {setBatchingImplementation} from './legacy-events/ReactGenericBatching'; | ||
import ReactVersion from 'shared/ReactVersion'; | ||
import {getNativeTagFromPublicInstance} from './ReactFabricPublicInstanceUtils'; | ||
|
||
// Modules provided by RN: | ||
import { | ||
|
@@ -44,6 +45,7 @@ import { | |
import {LegacyRoot, ConcurrentRoot} from 'react-reconciler/src/ReactRootTags'; | ||
import ReactSharedInternals from 'shared/ReactSharedInternals'; | ||
import getComponentNameFromType from 'shared/getComponentNameFromType'; | ||
import type {PublicInstance} from './ReactFabricHostConfig'; | ||
|
||
const ReactCurrentOwner = ReactSharedInternals.ReactCurrentOwner; | ||
|
||
|
@@ -67,19 +69,23 @@ function findHostInstance_DEPRECATED<TElementType: ElementType>( | |
owner.stateNode._warnedAboutRefsInRender = true; | ||
} | ||
} | ||
|
||
if (componentOrHandle == null) { | ||
return null; | ||
} | ||
// $FlowFixMe Flow has hardcoded values for React DOM that don't work with RN | ||
if (componentOrHandle._nativeTag) { | ||
// $FlowFixMe Flow has hardcoded values for React DOM that don't work with RN | ||
return componentOrHandle; | ||
|
||
// For compatibility with Paper | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. nit: avoid codename "Paper", use "legacy renderer" |
||
if (componentOrHandle._nativeTag != null) { | ||
// $FlowExpectedError[incompatible-cast] For compatibility with Paper (when using Fabric) | ||
return (componentOrHandle: PublicInstance); | ||
} | ||
// $FlowFixMe Flow has hardcoded values for React DOM that don't work with RN | ||
if (componentOrHandle.canonical && componentOrHandle.canonical._nativeTag) { | ||
// $FlowFixMe Flow has hardcoded values for React DOM that don't work with RN | ||
return componentOrHandle.canonical; | ||
|
||
// Fabric-specific | ||
if (componentOrHandle.publicInstance != null) { | ||
// $FlowExpectedError[incompatible-cast] For compatibility with Fabric (when using Paper) | ||
return (componentOrHandle.publicInstance: PublicInstance); | ||
} | ||
|
||
let hostInstance; | ||
if (__DEV__) { | ||
hostInstance = findHostInstanceWithWarning( | ||
|
@@ -111,19 +117,28 @@ function findNodeHandle(componentOrHandle: any): ?number { | |
owner.stateNode._warnedAboutRefsInRender = true; | ||
} | ||
} | ||
|
||
if (componentOrHandle == null) { | ||
return null; | ||
} | ||
|
||
if (typeof componentOrHandle === 'number') { | ||
// Already a node handle | ||
return componentOrHandle; | ||
} | ||
|
||
// For compatibility with Paper | ||
if (componentOrHandle._nativeTag) { | ||
return componentOrHandle._nativeTag; | ||
} | ||
if (componentOrHandle.canonical && componentOrHandle.canonical._nativeTag) { | ||
return componentOrHandle.canonical._nativeTag; | ||
|
||
if (componentOrHandle.internals != null) { | ||
const nativeTag = componentOrHandle.internals.nativeTag; | ||
if (nativeTag != null) { | ||
return nativeTag; | ||
} | ||
} | ||
|
||
let hostInstance; | ||
if (__DEV__) { | ||
hostInstance = findHostInstanceWithWarning( | ||
|
@@ -138,7 +153,14 @@ function findNodeHandle(componentOrHandle: any): ?number { | |
return hostInstance; | ||
} | ||
|
||
return hostInstance._nativeTag; | ||
// $FlowExpectedError[prop-missing] For compatibility with Paper (when using Fabric) | ||
if (hostInstance._nativeTag != null) { | ||
// $FlowExpectedError[incompatible-return] | ||
return hostInstance._nativeTag; | ||
} | ||
|
||
// $FlowExpectedError[incompatible-call] For compatibility with Fabric (when using Paper) | ||
return getNativeTagFromPublicInstance(hostInstance); | ||
} | ||
|
||
function dispatchCommand(handle: any, command: string, args: Array<any>) { | ||
|
@@ -265,6 +287,7 @@ export { | |
}; | ||
|
||
injectIntoDevTools({ | ||
// $FlowExpectedError[incompatible-call] The type of `Instance` in `getClosestInstanceFromNode` does not match in Fabric and Paper, so it fails to typecheck here. | ||
findFiberByHostInstance: getClosestInstanceFromNode, | ||
bundleType: __DEV__ ? 1 : 0, | ||
version: ReactVersion, | ||
|
This file contains 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 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 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 |
---|---|---|
|
@@ -7,42 +7,24 @@ | |
* @flow | ||
*/ | ||
|
||
// Module provided by RN: | ||
import {UIManager} from 'react-native/Libraries/ReactPrivate/ReactNativePrivateInterface'; | ||
|
||
const ReactFabricGlobalResponderHandler = { | ||
onChange: function (from: any, to: any, blockNativeResponder: boolean) { | ||
const fromOrTo = from || to; | ||
const fromOrToStateNode = fromOrTo && fromOrTo.stateNode; | ||
const isFabric = !!( | ||
fromOrToStateNode && fromOrToStateNode.canonical._internalInstanceHandle | ||
); | ||
|
||
if (isFabric) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. is this safe removal because this handler file is solely handling fabric? no mixed case? |
||
if (from) { | ||
// equivalent to clearJSResponder | ||
nativeFabricUIManager.setIsJSResponder( | ||
from.stateNode.node, | ||
false, | ||
blockNativeResponder || false, | ||
); | ||
} | ||
if (from) { | ||
// equivalent to clearJSResponder | ||
nativeFabricUIManager.setIsJSResponder( | ||
from.stateNode.node, | ||
false, | ||
blockNativeResponder || false, | ||
); | ||
} | ||
|
||
if (to) { | ||
// equivalent to setJSResponder | ||
nativeFabricUIManager.setIsJSResponder( | ||
to.stateNode.node, | ||
true, | ||
blockNativeResponder || false, | ||
); | ||
} | ||
} else { | ||
if (to !== null) { | ||
const tag = to.stateNode.canonical._nativeTag; | ||
UIManager.setJSResponder(tag, blockNativeResponder); | ||
} else { | ||
UIManager.clearJSResponder(); | ||
} | ||
if (to) { | ||
// equivalent to setJSResponder | ||
nativeFabricUIManager.setIsJSResponder( | ||
to.stateNode.node, | ||
true, | ||
blockNativeResponder || false, | ||
); | ||
} | ||
}, | ||
}; | ||
|
Oops, something went wrong.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is unused :)