2015-11-27 13:39:00 +00:00
|
|
|
/**
|
|
|
|
* Copyright (c) 2015-present, Facebook, Inc.
|
|
|
|
*
|
2018-02-17 02:24:55 +00:00
|
|
|
* This source code is licensed under the MIT license found in the
|
|
|
|
* LICENSE file in the root directory of this source tree.
|
2015-11-27 13:39:00 +00:00
|
|
|
*
|
|
|
|
* @providesModule UIManager
|
|
|
|
* @flow
|
2017-09-25 05:57:35 +00:00
|
|
|
* @format
|
2015-11-27 13:39:00 +00:00
|
|
|
*/
|
|
|
|
'use strict';
|
|
|
|
|
2016-05-09 15:20:08 +00:00
|
|
|
const NativeModules = require('NativeModules');
|
2016-09-23 18:12:54 +00:00
|
|
|
const Platform = require('Platform');
|
2016-05-09 15:20:08 +00:00
|
|
|
|
2016-09-23 18:12:54 +00:00
|
|
|
const defineLazyObjectProperty = require('defineLazyObjectProperty');
|
2016-08-05 18:19:11 +00:00
|
|
|
const invariant = require('fbjs/lib/invariant');
|
2015-11-27 13:39:00 +00:00
|
|
|
|
2017-09-25 05:57:35 +00:00
|
|
|
const {UIManager} = NativeModules;
|
2016-09-23 18:12:54 +00:00
|
|
|
|
2017-09-25 05:57:35 +00:00
|
|
|
invariant(
|
|
|
|
UIManager,
|
|
|
|
'UIManager is undefined. The native module config is probably incorrect.',
|
|
|
|
);
|
2016-02-23 10:26:11 +00:00
|
|
|
|
2017-03-25 07:37:51 +00:00
|
|
|
// In past versions of ReactNative users called UIManager.takeSnapshot()
|
|
|
|
// However takeSnapshot was moved to ReactNative in order to support flat
|
|
|
|
// bundles and to avoid a cyclic dependency between UIManager and ReactNative.
|
|
|
|
// UIManager.takeSnapshot still exists though. In order to avoid confusion or
|
|
|
|
// accidental usage, mask the method with a deprecation warning.
|
|
|
|
UIManager.__takeSnapshot = UIManager.takeSnapshot;
|
|
|
|
UIManager.takeSnapshot = function() {
|
|
|
|
invariant(
|
|
|
|
false,
|
|
|
|
'UIManager.takeSnapshot should not be called directly. ' +
|
2017-09-25 05:57:35 +00:00
|
|
|
'Use ReactNative.takeSnapshot instead.',
|
2017-03-25 07:37:51 +00:00
|
|
|
);
|
2016-02-23 10:26:11 +00:00
|
|
|
};
|
|
|
|
|
2016-05-09 15:20:08 +00:00
|
|
|
/**
|
|
|
|
* Copies the ViewManager constants and commands into UIManager. This is
|
|
|
|
* only needed for iOS, which puts the constants in the ViewManager
|
|
|
|
* namespace instead of UIManager, unlike Android.
|
|
|
|
*/
|
|
|
|
if (Platform.OS === 'ios') {
|
|
|
|
Object.keys(UIManager).forEach(viewName => {
|
|
|
|
const viewConfig = UIManager[viewName];
|
|
|
|
if (viewConfig.Manager) {
|
2016-09-23 18:12:54 +00:00
|
|
|
defineLazyObjectProperty(viewConfig, 'Constants', {
|
2016-05-09 15:20:08 +00:00
|
|
|
get: () => {
|
2016-09-23 18:12:54 +00:00
|
|
|
const viewManager = NativeModules[viewConfig.Manager];
|
2016-09-23 18:12:54 +00:00
|
|
|
const constants = {};
|
2017-09-25 05:57:35 +00:00
|
|
|
viewManager &&
|
|
|
|
Object.keys(viewManager).forEach(key => {
|
|
|
|
const value = viewManager[key];
|
|
|
|
if (typeof value !== 'function') {
|
|
|
|
constants[key] = value;
|
|
|
|
}
|
|
|
|
});
|
2016-05-09 15:20:08 +00:00
|
|
|
return constants;
|
|
|
|
},
|
|
|
|
});
|
2016-09-23 18:12:54 +00:00
|
|
|
defineLazyObjectProperty(viewConfig, 'Commands', {
|
2016-05-09 15:20:08 +00:00
|
|
|
get: () => {
|
2016-09-23 18:12:54 +00:00
|
|
|
const viewManager = NativeModules[viewConfig.Manager];
|
2016-09-23 18:12:54 +00:00
|
|
|
const commands = {};
|
2016-05-09 15:20:08 +00:00
|
|
|
let index = 0;
|
2017-09-25 05:57:35 +00:00
|
|
|
viewManager &&
|
|
|
|
Object.keys(viewManager).forEach(key => {
|
|
|
|
const value = viewManager[key];
|
|
|
|
if (typeof value === 'function') {
|
|
|
|
commands[key] = index++;
|
|
|
|
}
|
|
|
|
});
|
2016-05-09 15:20:08 +00:00
|
|
|
return commands;
|
|
|
|
},
|
|
|
|
});
|
|
|
|
}
|
|
|
|
});
|
2018-03-12 15:40:14 +00:00
|
|
|
} else if (UIManager.ViewManagerNames) {
|
2017-01-20 23:53:42 +00:00
|
|
|
UIManager.ViewManagerNames.forEach(viewManagerName => {
|
|
|
|
defineLazyObjectProperty(UIManager, viewManagerName, {
|
2017-09-28 16:40:39 +00:00
|
|
|
get: () => UIManager.getConstantsForViewManager(viewManagerName),
|
2017-01-20 23:53:42 +00:00
|
|
|
});
|
|
|
|
});
|
2016-05-09 15:20:08 +00:00
|
|
|
}
|
|
|
|
|
2015-11-27 13:39:00 +00:00
|
|
|
module.exports = UIManager;
|