-
Notifications
You must be signed in to change notification settings - Fork 46.9k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Removed unused imperative events implementation from React Native ren…
…derer (#26282) ## Summary I'm going to start implementing parts of this proposal react-native-community/discussions-and-proposals#607 As part of that implementation I'm going to refactor a few parts of the interface between React and React Native. One of the main problems we have right now is that we have private parts used by React and React Native in the public instance exported by refs. I want to properly separate that. I saw that a few methods to attach event handlers imperatively on refs were also exposing some things in the public instance (the `_eventListeners`). I checked and these methods are unused, so we can just clean them up instead of having to refactor them too. Adding support for imperative event listeners is in the roadmap after this proposal, and its implementation might differ after this refactor. This is essentially a manual revert of #23386. I'll submit more PRs after this for the rest of the refactor. ## How did you test this change? Existing jest tests. Will test a React sync internally at Meta.
- Loading branch information
1 parent
4111002
commit d49e0e0
Showing
10 changed files
with
61 additions
and
368 deletions.
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
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
37 changes: 37 additions & 0 deletions
37
packages/react-native-renderer/src/ReactNativeGetListener.js
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 |
---|---|---|
@@ -0,0 +1,37 @@ | ||
/** | ||
* 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 | ||
*/ | ||
|
||
import type {Fiber} from 'react-reconciler/src/ReactInternalTypes'; | ||
|
||
import {getFiberCurrentPropsFromNode} from './legacy-events/EventPluginUtils'; | ||
|
||
export default function getListener( | ||
inst: Fiber, | ||
registrationName: string, | ||
): Function | null { | ||
const stateNode = inst.stateNode; | ||
if (stateNode === null) { | ||
// Work in progress (ex: onload events in incremental mode). | ||
return null; | ||
} | ||
const props = getFiberCurrentPropsFromNode(stateNode); | ||
if (props === null) { | ||
// Work in progress. | ||
return null; | ||
} | ||
const listener = props[registrationName]; | ||
|
||
if (listener && typeof listener !== 'function') { | ||
throw new Error( | ||
`Expected \`${registrationName}\` listener to be a function, instead got a value of \`${typeof listener}\` type.`, | ||
); | ||
} | ||
|
||
return listener; | ||
} |
Oops, something went wrong.