mirror of
https://github.com/facebook/react-native.git
synced 2025-11-01 09:14:26 +00:00
a596e98611
Summary: This sync includes the following changes: - **[c1220ebdd](https://github.com/facebook/react/commit/c1220ebdd )**: treat empty string as null ([#22807](https://github.com/facebook/react/pull/22807)) //<salazarm>// - **[09d9b1775](https://github.com/facebook/react/commit/09d9b1775 )**: Update deprecated features in ESLint configuration files. ([#22767](https://github.com/facebook/react/pull/22767)) //<Esteban>// - **[bddbfb86d](https://github.com/facebook/react/commit/bddbfb86d )**: Revert "Fix Node package.json ./ exports deprecation warning ([#22783](https://github.com/facebook/react/pull/22783))" ([#22792](https://github.com/facebook/react/pull/22792)) //<Sebastian Silbermann>// - **[b831aec48](https://github.com/facebook/react/commit/b831aec48 )**: chore(fast-refresh): double check wasMounted ([#22740](https://github.com/facebook/react/pull/22740)) //<anc95>// - **[8edeb787b](https://github.com/facebook/react/commit/8edeb787b )**: Fix Node package.json ./ exports deprecation warning ([#22783](https://github.com/facebook/react/pull/22783)) //<Rin Arakaki>// - **[fdc1d617a](https://github.com/facebook/react/commit/fdc1d617a )**: Flag for client render fallback behavior on hydration mismatch ([#22787](https://github.com/facebook/react/pull/22787)) //<salazarm>// - **[aa19d569b](https://github.com/facebook/react/commit/aa19d569b )**: Add test selectors to experimental build ([#22760](https://github.com/facebook/react/pull/22760)) //<Brian Vaughn>// - **[520ffc77a](https://github.com/facebook/react/commit/520ffc77a )**: Use globalThis if possible for native fetch in browser build ([#22777](https://github.com/facebook/react/pull/22777)) //<Jiachi Liu>// - **[afbc2d08f](https://github.com/facebook/react/commit/afbc2d08f )**: Remove unused react-internal/invariant-args ESLint rule. ([#22778](https://github.com/facebook/react/pull/22778)) //<Esteban>// - **[ca94e2680](https://github.com/facebook/react/commit/ca94e2680 )**: Remove 'packages/shared/invariant.js' ([#22779](https://github.com/facebook/react/pull/22779)) //<Esteban>// - **[83564712b](https://github.com/facebook/react/commit/83564712b )**: Move SuspenseList to experimental channel ([#22765](https://github.com/facebook/react/pull/22765)) //<Andrew Clark>// - **[d4144e6e5](https://github.com/facebook/react/commit/d4144e6e5 )**: fix : grammatical typo for test description ([#22764](https://github.com/facebook/react/pull/22764)) //<Brijesh Prasad>// - **[0b329511b](https://github.com/facebook/react/commit/0b329511b )**: chore: fix comment typo ([#22657](https://github.com/facebook/react/pull/22657)) //<Han Han>// - **[e6f60d2ad](https://github.com/facebook/react/commit/e6f60d2ad )**: fix typos ([#22715](https://github.com/facebook/react/pull/22715)) //<180909>// Changelog: [General][Changed] - React Native sync for revisions c0c71a8...c1220eb jest_e2e[run_all_tests] Reviewed By: yungsters Differential Revision: D32646433 fbshipit-source-id: c534ee7a17141634700c90fc2c7b34bfbe17887a
129 lines
3.6 KiB
JavaScript
129 lines
3.6 KiB
JavaScript
/**
|
|
* Copyright (c) Facebook, Inc. and its affiliates.
|
|
*
|
|
* This source code is licensed under the MIT license found in the
|
|
* LICENSE file in the root directory of this source tree.
|
|
*
|
|
* @noformat
|
|
* @flow strict-local
|
|
* @generated SignedSource<<a81ed33269e71024fedad145e843fab0>>
|
|
*
|
|
* This file was sync'd from the facebook/react repository.
|
|
*/
|
|
|
|
'use strict';
|
|
|
|
import {type ViewConfig} from './ReactNativeTypes';
|
|
import invariant from 'invariant';
|
|
|
|
// Event configs
|
|
const customBubblingEventTypes: {
|
|
[eventName: string]: $ReadOnly<{|
|
|
phasedRegistrationNames: $ReadOnly<{|
|
|
captured: string,
|
|
bubbled: string,
|
|
|}>,
|
|
|}>,
|
|
...,
|
|
} = {};
|
|
const customDirectEventTypes: {
|
|
[eventName: string]: $ReadOnly<{|
|
|
registrationName: string,
|
|
|}>,
|
|
...,
|
|
} = {};
|
|
|
|
exports.customBubblingEventTypes = customBubblingEventTypes;
|
|
exports.customDirectEventTypes = customDirectEventTypes;
|
|
|
|
const viewConfigCallbacks = new Map();
|
|
const viewConfigs = new Map();
|
|
|
|
function processEventTypes(viewConfig: ViewConfig): void {
|
|
const {bubblingEventTypes, directEventTypes} = viewConfig;
|
|
|
|
if (__DEV__) {
|
|
if (bubblingEventTypes != null && directEventTypes != null) {
|
|
for (const topLevelType in directEventTypes) {
|
|
invariant(
|
|
bubblingEventTypes[topLevelType] == null,
|
|
'Event cannot be both direct and bubbling: %s',
|
|
topLevelType,
|
|
);
|
|
}
|
|
}
|
|
}
|
|
|
|
if (bubblingEventTypes != null) {
|
|
for (const topLevelType in bubblingEventTypes) {
|
|
if (customBubblingEventTypes[topLevelType] == null) {
|
|
customBubblingEventTypes[topLevelType] =
|
|
bubblingEventTypes[topLevelType];
|
|
}
|
|
}
|
|
}
|
|
|
|
if (directEventTypes != null) {
|
|
for (const topLevelType in directEventTypes) {
|
|
if (customDirectEventTypes[topLevelType] == null) {
|
|
customDirectEventTypes[topLevelType] = directEventTypes[topLevelType];
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
/**
|
|
* Registers a native view/component by name.
|
|
* A callback is provided to load the view config from UIManager.
|
|
* The callback is deferred until the view is actually rendered.
|
|
*/
|
|
exports.register = function(name: string, callback: () => ViewConfig): string {
|
|
invariant(
|
|
!viewConfigCallbacks.has(name),
|
|
'Tried to register two views with the same name %s',
|
|
name,
|
|
);
|
|
invariant(
|
|
typeof callback === 'function',
|
|
'View config getter callback for component `%s` must be a function (received `%s`)',
|
|
name,
|
|
callback === null ? 'null' : typeof callback,
|
|
);
|
|
viewConfigCallbacks.set(name, callback);
|
|
return name;
|
|
};
|
|
|
|
/**
|
|
* Retrieves a config for the specified view.
|
|
* If this is the first time the view has been used,
|
|
* This configuration will be lazy-loaded from UIManager.
|
|
*/
|
|
exports.get = function(name: string): ViewConfig {
|
|
let viewConfig;
|
|
if (!viewConfigs.has(name)) {
|
|
const callback = viewConfigCallbacks.get(name);
|
|
if (typeof callback !== 'function') {
|
|
invariant(
|
|
false,
|
|
'View config getter callback for component `%s` must be a function (received `%s`).%s',
|
|
name,
|
|
callback === null ? 'null' : typeof callback,
|
|
typeof name[0] === 'string' && /[a-z]/.test(name[0])
|
|
? ' Make sure to start component names with a capital letter.'
|
|
: '',
|
|
);
|
|
}
|
|
viewConfig = callback();
|
|
processEventTypes(viewConfig);
|
|
viewConfigs.set(name, viewConfig);
|
|
|
|
// Clear the callback after the config is set so that
|
|
// we don't mask any errors during registration.
|
|
viewConfigCallbacks.set(name, null);
|
|
} else {
|
|
viewConfig = viewConfigs.get(name);
|
|
}
|
|
invariant(viewConfig, 'View config not found for name %s', name);
|
|
return viewConfig;
|
|
};
|