diff --git a/Libraries/ReactNative/UIManager.js b/Libraries/ReactNative/UIManager.js index 9f34734a731..5f6c61619d9 100644 --- a/Libraries/ReactNative/UIManager.js +++ b/Libraries/ReactNative/UIManager.js @@ -77,11 +77,24 @@ if (Platform.OS === 'ios') { } }); } else if (UIManager.ViewManagerNames) { - UIManager.ViewManagerNames.forEach(viewManagerName => { - defineLazyObjectProperty(UIManager, viewManagerName, { - get: () => UIManager.getConstantsForViewManager(viewManagerName), + // 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. + // So we wrap it in a special __residual call, which basically tells Prepack to ignore it. + let residual = global.__residual ? global.__residual : (_, f, ...args) => f.apply(undefined, args); + residual("void", (UIManager, defineLazyObjectProperty) => { + UIManager.ViewManagerNames.forEach(viewManagerName => { + defineLazyObjectProperty(UIManager, viewManagerName, { + get: () => UIManager.getConstantsForViewManager(viewManagerName), + }); }); - }); + }, UIManager, defineLazyObjectProperty); + + // As Prepack now no longer knows which properties exactly the UIManager has, + // we also tell Prepack that it has only partial knowledge of the UIManager, + // so that any accesses to unknown properties along the global code will fail + // when Prepack encounters them. + if (global.__makePartial) global.__makePartial(UIManager); } module.exports = UIManager;