mirror of
https://github.com/facebook/react-native.git
synced 2025-11-01 09:14:26 +00:00
Revert D15551356: [react-native][PR] [TM] Add spec for UIManager
Differential Revision: D15551356 Original commit changeset: 076c4ce635aa fbshipit-source-id: dff59dc9c98bc579851091855611ee5d973931d0
This commit is contained in:
committed by
Facebook Github Bot
parent
a944ebd7da
commit
b0254e8d3c
@@ -139,7 +139,7 @@ const AccessibilityInfo = {
|
||||
setAccessibilityFocus: function(reactTag: number): void {
|
||||
UIManager.sendAccessibilityEvent(
|
||||
reactTag,
|
||||
UIManager.getConstants().AccessibilityEventTypes.typeViewFocused,
|
||||
UIManager.AccessibilityEventTypes.typeViewFocused,
|
||||
);
|
||||
},
|
||||
|
||||
|
||||
@@ -1,122 +0,0 @@
|
||||
/**
|
||||
* 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.
|
||||
*
|
||||
* @flow
|
||||
* @format
|
||||
*/
|
||||
|
||||
'use strict';
|
||||
|
||||
import type {TurboModule} from '../TurboModule/RCTExport';
|
||||
import * as TurboModuleRegistry from '../TurboModule/TurboModuleRegistry';
|
||||
|
||||
export interface Spec extends TurboModule {
|
||||
+getConstants: () => Object;
|
||||
+getConstantsForViewManager: (viewManagerName: string) => Object;
|
||||
+getDefaultEventTypes: () => Array<string>;
|
||||
+playTouchSound: () => void;
|
||||
+lazilyLoadView: (name: string) => Object; // revisit return
|
||||
+createView: (
|
||||
reactTag: ?number,
|
||||
viewName: string,
|
||||
rootTag: number,
|
||||
props: Object,
|
||||
) => void;
|
||||
+updateView: (reactTag: number, viewName: string, props: Object) => void;
|
||||
+focus: (reactTag: ?number) => void;
|
||||
+blur: (reactTag: ?number) => void;
|
||||
+findSubviewIn: (
|
||||
reactTag: ?number,
|
||||
point: [number, number],
|
||||
callback: (
|
||||
nativeViewTag: number,
|
||||
left: number,
|
||||
top: number,
|
||||
width: number,
|
||||
height: number,
|
||||
) => void,
|
||||
) => void;
|
||||
+dispatchViewManagerCommand: (
|
||||
reactTag: ?number,
|
||||
commandID: number,
|
||||
commandArgs: ?Array<string | number | boolean>, // is this best?
|
||||
) => void;
|
||||
+measure: (
|
||||
reactTag: ?number,
|
||||
callback: (
|
||||
left: number,
|
||||
top: number,
|
||||
width: number,
|
||||
height: number,
|
||||
pageX: number,
|
||||
pageY: number,
|
||||
) => void,
|
||||
) => void;
|
||||
+measureInWindow: (
|
||||
reactTag: ?number,
|
||||
callback: (x: number, y: number, width: number, height: number) => void,
|
||||
) => void;
|
||||
+viewIsDescendantOf: (
|
||||
reactTag: ?number,
|
||||
ancestorReactTag: ?number,
|
||||
callback: (result: Array<boolean>) => void,
|
||||
) => void;
|
||||
+measureLayout: (
|
||||
reactTag: ?number,
|
||||
ancestorReactTag: ?number,
|
||||
errorCallback: (error: Object) => void,
|
||||
callback: (
|
||||
left: number,
|
||||
top: number,
|
||||
width: number,
|
||||
height: number,
|
||||
) => void,
|
||||
) => void;
|
||||
+measureLayoutRelativeToParent: (
|
||||
reactTag: ?number,
|
||||
errorCallback: (error: Object) => void,
|
||||
callback: (
|
||||
left: number,
|
||||
top: number,
|
||||
width: number,
|
||||
height: number,
|
||||
) => void,
|
||||
) => void;
|
||||
+setJSResponder: (reactTag: ?number, blockNativeResponder: boolean) => void;
|
||||
+clearJSResponder: () => void;
|
||||
+configureNextLayoutAnimation: (
|
||||
config: Object,
|
||||
callback: () => void, // check what is returned here
|
||||
errorCallback: (error: Object) => void,
|
||||
) => void;
|
||||
+removeSubviewsFromContainerWithID: (containerID: number) => void;
|
||||
+replaceExistingNonRootView: (
|
||||
reactTag: ?number,
|
||||
newReactTag: ?number,
|
||||
) => void;
|
||||
+setChildren: (containerTag: ?number, reactTags: Array<number>) => void;
|
||||
+manageChildren: (
|
||||
containerTag: ?number,
|
||||
moveFromIndices: Array<number>,
|
||||
moveToIndices: Array<number>,
|
||||
addChildReactTags: Array<number>,
|
||||
addAtIndices: Array<number>,
|
||||
removeAtIndices: Array<number>,
|
||||
) => void;
|
||||
|
||||
// Android only
|
||||
+setLayoutAnimationEnabledExperimental: (enabled: boolean) => void;
|
||||
+sendAccessibilityEvent: (reactTag: ?number, eventType: number) => void;
|
||||
+showPopupMenu: (
|
||||
reactTag: ?number,
|
||||
items: Array<string>,
|
||||
error: (error: Object) => void,
|
||||
success: (event: string, selected?: number) => void,
|
||||
) => void;
|
||||
+dismissPopupMenu: () => void;
|
||||
}
|
||||
|
||||
export default TurboModuleRegistry.getEnforcing<Spec>('UIManager');
|
||||
@@ -4,7 +4,7 @@
|
||||
* This source code is licensed under the MIT license found in the
|
||||
* LICENSE file in the root directory of this source tree.
|
||||
*
|
||||
* @flow
|
||||
* @flow strict-local
|
||||
* @format
|
||||
*/
|
||||
'use strict';
|
||||
@@ -14,94 +14,58 @@ const Platform = require('../Utilities/Platform');
|
||||
const UIManagerProperties = require('./UIManagerProperties');
|
||||
|
||||
const defineLazyObjectProperty = require('../Utilities/defineLazyObjectProperty');
|
||||
const invariant = require('invariant');
|
||||
|
||||
import NativeUIManager from './NativeUIManager';
|
||||
import type {Spec} from './NativeUIManager';
|
||||
|
||||
const {UIManager} = NativeModules;
|
||||
const viewManagerConfigs = {};
|
||||
|
||||
interface UIManagerJSInterface extends Spec {
|
||||
+getViewManagerConfig: (viewManagerName: string) => Object;
|
||||
// The following are not marked read-only due to logic in UIManagerStatTracker.
|
||||
createView: (
|
||||
reactTag: ?number,
|
||||
viewName: string,
|
||||
rootTag: number,
|
||||
props: Object,
|
||||
) => void;
|
||||
updateView: (reactTag: number, viewName: string, props: Object) => void;
|
||||
manageChildren: (
|
||||
containerTag: ?number,
|
||||
moveFromIndices: Array<number>,
|
||||
moveToIndices: Array<number>,
|
||||
addChildReactTags: Array<number>,
|
||||
addAtIndices: Array<number>,
|
||||
removeAtIndices: Array<number>,
|
||||
) => void;
|
||||
}
|
||||
invariant(
|
||||
UIManager,
|
||||
'UIManager is undefined. The native module config is probably incorrect.',
|
||||
);
|
||||
|
||||
const triedLoadingConfig = new Set();
|
||||
|
||||
let NativeUIManagerConstants = {};
|
||||
let isNativeUIManagerConstantsSet = false;
|
||||
function getConstants(): Object {
|
||||
if (!isNativeUIManagerConstantsSet) {
|
||||
NativeUIManagerConstants = NativeUIManager.getConstants();
|
||||
isNativeUIManagerConstantsSet = true;
|
||||
}
|
||||
return NativeUIManagerConstants;
|
||||
}
|
||||
|
||||
const UIManagerJS: UIManagerJSInterface = {
|
||||
...NativeUIManager,
|
||||
getConstants(): Object {
|
||||
return getConstants();
|
||||
},
|
||||
getViewManagerConfig: function(viewManagerName: string) {
|
||||
if (
|
||||
viewManagerConfigs[viewManagerName] === undefined &&
|
||||
NativeUIManager.getConstantsForViewManager
|
||||
) {
|
||||
try {
|
||||
viewManagerConfigs[
|
||||
viewManagerName
|
||||
] = NativeUIManager.getConstantsForViewManager(viewManagerName);
|
||||
} catch (e) {
|
||||
viewManagerConfigs[viewManagerName] = null;
|
||||
}
|
||||
UIManager.getViewManagerConfig = function(viewManagerName: string) {
|
||||
if (
|
||||
viewManagerConfigs[viewManagerName] === undefined &&
|
||||
UIManager.getConstantsForViewManager
|
||||
) {
|
||||
try {
|
||||
viewManagerConfigs[
|
||||
viewManagerName
|
||||
] = UIManager.getConstantsForViewManager(viewManagerName);
|
||||
} catch (e) {
|
||||
viewManagerConfigs[viewManagerName] = null;
|
||||
}
|
||||
}
|
||||
|
||||
const config = viewManagerConfigs[viewManagerName];
|
||||
if (config) {
|
||||
const config = viewManagerConfigs[viewManagerName];
|
||||
if (config) {
|
||||
return config;
|
||||
}
|
||||
|
||||
// If we're in the Chrome Debugger, let's not even try calling the sync
|
||||
// method.
|
||||
if (__DEV__) {
|
||||
if (!global.nativeCallSyncHook) {
|
||||
return config;
|
||||
}
|
||||
}
|
||||
|
||||
// If we're in the Chrome Debugger, let's not even try calling the sync
|
||||
// method.
|
||||
if (__DEV__) {
|
||||
if (!global.nativeCallSyncHook) {
|
||||
return config;
|
||||
}
|
||||
if (UIManager.lazilyLoadView && !triedLoadingConfig.has(viewManagerName)) {
|
||||
const result = UIManager.lazilyLoadView(viewManagerName);
|
||||
triedLoadingConfig.add(viewManagerName);
|
||||
if (result.viewConfig) {
|
||||
UIManager[viewManagerName] = result.viewConfig;
|
||||
lazifyViewManagerConfig(viewManagerName);
|
||||
}
|
||||
}
|
||||
|
||||
if (
|
||||
NativeUIManager.lazilyLoadView &&
|
||||
!triedLoadingConfig.has(viewManagerName)
|
||||
) {
|
||||
const result = NativeUIManager.lazilyLoadView(viewManagerName);
|
||||
triedLoadingConfig.add(viewManagerName);
|
||||
if (result.viewConfig) {
|
||||
getConstants()[viewManagerName] = result.viewConfig;
|
||||
lazifyViewManagerConfig(viewManagerName);
|
||||
}
|
||||
}
|
||||
|
||||
return viewManagerConfigs[viewManagerName];
|
||||
},
|
||||
return viewManagerConfigs[viewManagerName];
|
||||
};
|
||||
|
||||
function lazifyViewManagerConfig(viewName) {
|
||||
const viewConfig = getConstants()[viewName];
|
||||
const viewConfig = UIManager[viewName];
|
||||
if (viewConfig.Manager) {
|
||||
viewManagerConfigs[viewName] = viewConfig;
|
||||
defineLazyObjectProperty(viewConfig, 'Constants', {
|
||||
@@ -142,10 +106,10 @@ function lazifyViewManagerConfig(viewName) {
|
||||
* namespace instead of UIManager, unlike Android.
|
||||
*/
|
||||
if (Platform.OS === 'ios') {
|
||||
Object.keys(getConstants()).forEach(viewName => {
|
||||
Object.keys(UIManager).forEach(viewName => {
|
||||
lazifyViewManagerConfig(viewName);
|
||||
});
|
||||
} else if (getConstants().ViewManagerNames) {
|
||||
} else if (UIManager.ViewManagerNames) {
|
||||
// We want to add all the view managers to the UIManager.
|
||||
// However, the way things are set up, the list of view managers is not known at compile time.
|
||||
// As Prepack runs at compile it, it cannot process this loop.
|
||||
@@ -156,13 +120,13 @@ if (Platform.OS === 'ios') {
|
||||
residual(
|
||||
'void',
|
||||
(UIManager, defineLazyObjectProperty) => {
|
||||
UIManager.getConstants().ViewManagerNames.forEach(viewManagerName => {
|
||||
UIManager.ViewManagerNames.forEach(viewManagerName => {
|
||||
defineLazyObjectProperty(UIManager, viewManagerName, {
|
||||
get: () => UIManager.getConstantsForViewManager(viewManagerName),
|
||||
});
|
||||
});
|
||||
},
|
||||
NativeUIManager,
|
||||
UIManager,
|
||||
defineLazyObjectProperty,
|
||||
);
|
||||
|
||||
@@ -171,28 +135,27 @@ if (Platform.OS === 'ios') {
|
||||
// so that any accesses to unknown properties along the global code will fail
|
||||
// when Prepack encounters them.
|
||||
if (global.__makePartial) {
|
||||
global.__makePartial(NativeUIManager);
|
||||
global.__makePartial(UIManager);
|
||||
}
|
||||
}
|
||||
|
||||
if (__DEV__) {
|
||||
Object.keys(getConstants()).forEach(viewManagerName => {
|
||||
Object.keys(UIManager).forEach(viewManagerName => {
|
||||
if (!UIManagerProperties.includes(viewManagerName)) {
|
||||
if (!viewManagerConfigs[viewManagerName]) {
|
||||
viewManagerConfigs[viewManagerName] = getConstants()[viewManagerName];
|
||||
viewManagerConfigs[viewManagerName] = UIManager[viewManagerName];
|
||||
}
|
||||
defineLazyObjectProperty(NativeUIManager, viewManagerName, {
|
||||
defineLazyObjectProperty(UIManager, viewManagerName, {
|
||||
get: () => {
|
||||
console.warn(
|
||||
`Accessing view manager configs directly off UIManager via UIManager['${viewManagerName}'] ` +
|
||||
`is no longer supported. Use UIManager.getViewManagerConfig('${viewManagerName}') instead.`,
|
||||
);
|
||||
|
||||
return UIManagerJS.getViewManagerConfig(viewManagerName);
|
||||
return UIManager.getViewManagerConfig(viewManagerName);
|
||||
},
|
||||
});
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
module.exports = UIManagerJS;
|
||||
module.exports = UIManager;
|
||||
|
||||
@@ -52,8 +52,8 @@ const UIManagerStatTracker = {
|
||||
remove,
|
||||
) {
|
||||
incStat('manageChildren', 1);
|
||||
incStat('move', moveFrom.length);
|
||||
incStat('remove', remove.length);
|
||||
incStat('move', Object.keys(moveFrom || []).length);
|
||||
incStat('remove', Object.keys(remove || []).length);
|
||||
manageChildrenOrig(tag, moveFrom, moveTo, addTags, addIndices, remove);
|
||||
};
|
||||
},
|
||||
|
||||
@@ -96,18 +96,17 @@ function attachDefaultEventTypes(viewConfig: any) {
|
||||
// This is supported on UIManager platforms (ex: Android),
|
||||
// as lazy view managers are not implemented for all platforms.
|
||||
// See [UIManager] for details on constants and implementations.
|
||||
const constants = UIManager.getConstants();
|
||||
if (constants.ViewManagerNames || constants.LazyViewManagersEnabled) {
|
||||
if (UIManager.ViewManagerNames || UIManager.LazyViewManagersEnabled) {
|
||||
// Lazy view managers enabled.
|
||||
viewConfig = merge(viewConfig, UIManager.getDefaultEventTypes());
|
||||
} else {
|
||||
viewConfig.bubblingEventTypes = merge(
|
||||
viewConfig.bubblingEventTypes,
|
||||
constants.genericBubblingEventTypes,
|
||||
UIManager.genericBubblingEventTypes,
|
||||
);
|
||||
viewConfig.directEventTypes = merge(
|
||||
viewConfig.directEventTypes,
|
||||
constants.genericDirectEventTypes,
|
||||
UIManager.genericDirectEventTypes,
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user