RCTDefines.h 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149
  1. /*
  2. * Copyright (c) Facebook, Inc. and its 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. #if __OBJC__
  8. #import <Foundation/Foundation.h>
  9. #endif
  10. /**
  11. * Make global functions usable in C++
  12. */
  13. #if defined(__cplusplus)
  14. #define RCT_EXTERN extern "C" __attribute__((visibility("default")))
  15. #define RCT_EXTERN_C_BEGIN extern "C" {
  16. #define RCT_EXTERN_C_END }
  17. #else
  18. #define RCT_EXTERN extern __attribute__((visibility("default")))
  19. #define RCT_EXTERN_C_BEGIN
  20. #define RCT_EXTERN_C_END
  21. #endif
  22. /**
  23. * The RCT_DEBUG macro can be used to exclude error checking and logging code
  24. * from release builds to improve performance and reduce binary size.
  25. */
  26. #ifndef RCT_DEBUG
  27. #if DEBUG
  28. #define RCT_DEBUG 1
  29. #else
  30. #define RCT_DEBUG 0
  31. #endif
  32. #endif
  33. /**
  34. * The RCT_DEV macro can be used to enable or disable development tools
  35. * such as the debug executors, dev menu, red box, etc.
  36. */
  37. #ifndef RCT_DEV
  38. #if DEBUG
  39. #define RCT_DEV 1
  40. #else
  41. #define RCT_DEV 0
  42. #endif
  43. #endif
  44. /**
  45. * RCT_DEV_MENU can be used to toggle the dev menu separately from RCT_DEV.
  46. * By default though, it will inherit from RCT_DEV.
  47. */
  48. #ifndef RCT_DEV_MENU
  49. #define RCT_DEV_MENU RCT_DEV
  50. #endif
  51. #ifndef RCT_ENABLE_INSPECTOR
  52. #if RCT_DEV && __has_include(<React/RCTInspectorDevServerHelper.h>)
  53. #define RCT_ENABLE_INSPECTOR 1
  54. #else
  55. #define RCT_ENABLE_INSPECTOR 0
  56. #endif
  57. #endif
  58. #ifndef ENABLE_PACKAGER_CONNECTION
  59. #if RCT_DEV && (__has_include("RCTPackagerConnection.h") || __has_include(<React/RCTPackagerConnection.h>))
  60. #define ENABLE_PACKAGER_CONNECTION 1
  61. #else
  62. #define ENABLE_PACKAGER_CONNECTION 0
  63. #endif
  64. #endif
  65. #if RCT_DEV
  66. #define RCT_IF_DEV(...) __VA_ARGS__
  67. #else
  68. #define RCT_IF_DEV(...)
  69. #endif
  70. #ifndef RCT_PROFILE
  71. #define RCT_PROFILE RCT_DEV
  72. #endif
  73. /**
  74. * Add the default Metro packager port number
  75. */
  76. #ifndef RCT_METRO_PORT
  77. #define RCT_METRO_PORT 8081
  78. #else
  79. // test if RCT_METRO_PORT is empty
  80. #define RCT_METRO_PORT_DO_EXPAND(VAL) VAL##1
  81. #define RCT_METRO_PORT_EXPAND(VAL) RCT_METRO_PORT_DO_EXPAND(VAL)
  82. #if !defined(RCT_METRO_PORT) || (RCT_METRO_PORT_EXPAND(RCT_METRO_PORT) == 1)
  83. // Only here if RCT_METRO_PORT is not defined
  84. // OR RCT_METRO_PORT is the empty string
  85. #undef RCT_METRO_PORT
  86. #define RCT_METRO_PORT 8081
  87. #endif
  88. #endif
  89. /**
  90. * Add the default packager name
  91. */
  92. #ifndef RCT_PACKAGER_NAME
  93. #define RCT_PACKAGER_NAME @"Metro"
  94. #endif
  95. /**
  96. * By default, only raise an NSAssertion in debug mode
  97. * (custom assert functions will still be called).
  98. */
  99. #ifndef RCT_NSASSERT
  100. #define RCT_NSASSERT RCT_DEBUG
  101. #endif
  102. /**
  103. * Concat two literals. Supports macro expansions,
  104. * e.g. RCT_CONCAT(foo, __FILE__).
  105. */
  106. #define RCT_CONCAT2(A, B) A##B
  107. #define RCT_CONCAT(A, B) RCT_CONCAT2(A, B)
  108. /**
  109. * This attribute is used for static analysis.
  110. */
  111. #if !defined RCT_DYNAMIC
  112. #if __has_attribute(objc_dynamic)
  113. #define RCT_DYNAMIC __attribute__((objc_dynamic))
  114. #else
  115. #define RCT_DYNAMIC
  116. #endif
  117. #endif
  118. /**
  119. * Throw an assertion for unimplemented methods.
  120. */
  121. #define RCT_NOT_IMPLEMENTED(method) \
  122. _Pragma("clang diagnostic push") _Pragma("clang diagnostic ignored \"-Wmissing-method-return-type\"") \
  123. _Pragma("clang diagnostic ignored \"-Wunused-parameter\"") \
  124. RCT_EXTERN NSException *_RCTNotImplementedException(SEL, Class); \
  125. method NS_UNAVAILABLE \
  126. { \
  127. @throw _RCTNotImplementedException(_cmd, [self class]); \
  128. } \
  129. _Pragma("clang diagnostic pop")
  130. /**
  131. * Check if WebKit iOS 10.0 APIs are available.
  132. */
  133. #define WEBKIT_IOS_10_APIS_AVAILABLE __has_include(<WebKit/WKAudiovisualMediaTypes.h>)