1. /**
    
  2.  * Copyright (c) Meta Platforms, Inc. and affiliates.
    
  3.  *
    
  4.  * This source code is licensed under the MIT license found in the
    
  5.  * LICENSE file in the root directory of this source tree.
    
  6.  *
    
  7.  * @flow
    
  8.  */
    
  9. 
    
  10. /**
    
  11.  * In the future, we should cleanup callbacks by cancelling them instead of
    
  12.  * using this.
    
  13.  */
    
  14. export function mountSafeCallback_NOT_REALLY_SAFE(
    
  15.   context: any,
    
  16.   callback: ?Function,
    
  17. ): any {
    
  18.   return function () {
    
  19.     if (!callback) {
    
  20.       return undefined;
    
  21.     }
    
  22.     // This protects against createClass() components.
    
  23.     // We don't know if there is code depending on it.
    
  24.     // We intentionally don't use isMounted() because even accessing
    
  25.     // isMounted property on a React ES6 class will trigger a warning.
    
  26.     if (typeof context.__isMounted === 'boolean') {
    
  27.       if (!context.__isMounted) {
    
  28.         return undefined;
    
  29.       }
    
  30.     }
    
  31. 
    
  32.     // FIXME: there used to be other branches that protected
    
  33.     // against unmounted host components. But RN host components don't
    
  34.     // define isMounted() anymore, so those checks didn't do anything.
    
  35. 
    
  36.     // They caused false positive warning noise so we removed them:
    
  37.     // https://github.com/facebook/react-native/issues/18868#issuecomment-413579095
    
  38. 
    
  39.     // However, this means that the callback is NOT guaranteed to be safe
    
  40.     // for host components. The solution we should implement is to make
    
  41.     // UIManager.measure() and similar calls truly cancelable. Then we
    
  42.     // can change our own code calling them to cancel when something unmounts.
    
  43. 
    
  44.     return callback.apply(context, arguments);
    
  45.   };
    
  46. }
    
  47. 
    
  48. export function warnForStyleProps(props: any, validAttributes: any) {
    
  49.   if (__DEV__) {
    
  50.     for (const key in validAttributes.style) {
    
  51.       if (!(validAttributes[key] || props[key] === undefined)) {
    
  52.         console.error(
    
  53.           'You are setting the style `{ %s' +
    
  54.             ': ... }` as a prop. You ' +
    
  55.             'should nest it in a style object. ' +
    
  56.             'E.g. `{ style: { %s' +
    
  57.             ': ... } }`',
    
  58.           key,
    
  59.           key,
    
  60.         );
    
  61.       }
    
  62.     }
    
  63.   }
    
  64. }