WXDefine.h 6.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193
  1. /*
  2. * Licensed to the Apache Software Foundation (ASF) under one
  3. * or more contributor license agreements. See the NOTICE file
  4. * distributed with this work for additional information
  5. * regarding copyright ownership. The ASF licenses this file
  6. * to you under the Apache License, Version 2.0 (the
  7. * "License"); you may not use this file except in compliance
  8. * with the License. You may obtain a copy of the License at
  9. *
  10. * http://www.apache.org/licenses/LICENSE-2.0
  11. *
  12. * Unless required by applicable law or agreed to in writing,
  13. * software distributed under the License is distributed on an
  14. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  15. * KIND, either express or implied. See the License for the
  16. * specific language governing permissions and limitations
  17. * under the License.
  18. */
  19. #ifndef __WX_DEFINE_H__
  20. #define __WX_DEFINE_H__
  21. #define WX_SDK_VERSION @"0.20.0"
  22. #if defined(__cplusplus)
  23. #define WX_EXTERN extern "C" __attribute__((visibility("default")))
  24. #else
  25. #define WX_EXTERN extern __attribute__((visibility("default")))
  26. #endif
  27. /*
  28. * Concatenate preprocessor tokens a and b without expanding macro definitions
  29. * (however, if invoked from a macro, macro arguments are expanded).
  30. */
  31. #define WX_CONCAT(a, b) a ## b
  32. /*
  33. * Concatenate preprocessor tokens a and b after macro-expanding them.
  34. */
  35. #define WX_CONCAT_WRAPPER(a, b) WX_CONCAT(a, b)
  36. #define WX_CONCAT_TRIPLE(a, b, c) a ## b ## c
  37. #define WX_NSSTRING_HELPER(x) #x
  38. #define WX_NSSTRING(x) @WX_NSSTRING_HELPER(x)
  39. #define WX_SDK_ROOT_REF @"_root"
  40. #define WX_TEXT_FONT_SIZE (32.0 * self.weexInstance.pixelScaleFactor)
  41. #define WX_UPDATE_CONFIG(prefix, name, configs) \
  42. NSString *selStr = [NSString stringWithFormat:@"%@_%@", prefix, name];\
  43. SEL selector = NSSelectorFromString(selStr);\
  44. Class clazz = WX_COMPONENT_CLASS(_properties[@"type"]);\
  45. if ([clazz respondsToSelector:selector]) {\
  46. configs = ((NSArray *(*)(id, SEL))objc_msgSend)(clazz, selector);\
  47. }\
  48. #define WX_TYPE_KEYPATH(config, name, type, parts, vKey) \
  49. type = [config[0] stringByAppendingString:@":"];\
  50. NSString *keyPath = config.count > 1 ? config[1] : nil;\
  51. if(keyPath){\
  52. parts = [keyPath componentsSeparatedByString:@"."];\
  53. vKey = parts.lastObject;\
  54. parts = [parts subarrayWithRange:(NSRange){0, parts.count - 1}];\
  55. } else {\
  56. vKey = name;\
  57. }
  58. #define RGB(r, g, b) [UIColor colorWithRed:r/255.0 green:g/255.0 blue:b/255.0 alpha:1.0]
  59. #define RGB_A(r, g, b, a) [UIColor colorWithRed:r/255.0 green:g/255.0 blue:b/255.0 alpha:a]
  60. #define ScreenWidth ([[UIScreen mainScreen] bounds].size.width)
  61. #define WX_ERROR_DOMAIN @"WXErrorDomain"
  62. #define WX_APPLICATION_WILL_RESIGN_ACTIVE @"WXApplicationWillResignActiveEvent"
  63. #define WX_APPLICATION_DID_BECOME_ACTIVE @"WXApplicationDidBecomeActiveEvent"
  64. #define WX_INSTANCE_NOTIFICATION_UPDATE_STATE @"WXInstUpdateState"
  65. #define WX_COMPONENT_NOTIFICATION_VIEW_LOADED @"WXComponentViewLoaded"
  66. #define WX_INSTANCE_WILL_DESTROY_NOTIFICATION @"WXSDKInstanceWillDestroyNotification"
  67. #define WX_SDKINSTANCE_WILL_RENDER @"WXSDKInstanceWillRender"
  68. #define WX_COMPONENT_THREAD_NAME @"com.taobao.weex.component"
  69. #define WX_BRIDGE_THREAD_NAME @"com.taobao.weex.bridge"
  70. #define WX_FONT_DOWNLOAD_DIR [[WXUtility cacheDirectory] stringByAppendingPathComponent:[NSString stringWithFormat:@"wxdownload"]]
  71. #define WX_EXPORT_METHOD_INTERNAL(method, token) \
  72. + (NSString *)WX_CONCAT_WRAPPER(token, __LINE__) { \
  73. return NSStringFromSelector(method); \
  74. }
  75. #define WX_MODULE_EVENT_FIRE_NOTIFICATION @"WX_MODULE_EVENT_FIRE_NOTIFICATION"
  76. #define WX_ICONFONT_DOWNLOAD_NOTIFICATION @"WX_ICONFONT_DOWNLOAD_FINISH_NOTIFICATION"
  77. #define WX_INSTANCE_JSCONTEXT_CREATE_NOTIFICATION @"WX_INSTANCE_JSCONTEXT_CREATE_NOTIFICATION"
  78. /**
  79. * @abstract export public method
  80. */
  81. #define WX_EXPORT_METHOD(method) WX_EXPORT_METHOD_INTERNAL(method,wx_export_method_)
  82. /**
  83. * @abstract export public method, support sync return value
  84. * @warning the method can only be called on js thread
  85. */
  86. #define WX_EXPORT_METHOD_SYNC(method) WX_EXPORT_METHOD_INTERNAL(method,wx_export_method_sync_)
  87. /** extern "C" makes a function-name in C++ have 'C' linkage (compiler does not mangle the name)
  88. * so that client C code can link to (i.e use) your function using a 'C' compatible header file that contains just the declaration of your function.
  89. * http://stackoverflow.com/questions/1041866/in-c-source-what-is-the-effect-of-extern-c
  90. */
  91. #ifdef __cplusplus
  92. # define WX_EXTERN_C_BEGIN extern "C" {
  93. # define WX_EXTERN_C_END }
  94. #else
  95. # define WX_EXTERN_C_BEGIN
  96. # define WX_EXTERN_C_END
  97. #endif
  98. /**
  99. * @abstract Compared with system version of current device
  100. *
  101. * @return YES if greater than or equal to the system verison, otherwise, NO.
  102. *
  103. */
  104. #define WX_SYS_VERSION_GREATER_THAN_OR_EQUAL_TO(v) ([[[UIDevice currentDevice] systemVersion] compare:v options:NSNumericSearch] != NSOrderedAscending)
  105. /**
  106. * @abstract Compared with system version of current device
  107. *
  108. * @return YES if greater than the system verison, otherwise, NO.
  109. *
  110. */
  111. #define WX_SYS_VERSION_GREATER_THAN(v) ([[[UIDevice currentDevice] systemVersion] compare:v options:NSNumericSearch] == NSOrderedDescending)
  112. /**
  113. * @abstract Compared with system version of current device
  114. *
  115. * @return YES if equal to the system verison, otherwise, NO.
  116. *
  117. */
  118. #define WX_SYS_VERSION_EQUAL_TO(v) ([[[UIDevice currentDevice] systemVersion] compare:v options:NSNumericSearch] == NSOrderedSame)
  119. /**
  120. * @abstract Compared with system version of current device
  121. *
  122. * @return YES if less than the system verison, otherwise, NO.
  123. *
  124. */
  125. #define WX_SYS_VERSION_LESS_THAN(v) ([[[UIDevice currentDevice] systemVersion] compare:v options:NSNumericSearch] == NSOrderedAscending)
  126. /**
  127. * @abstract Compared with system version of current device
  128. *
  129. * @return YES if less than or equal to the system verison, otherwise, NO.
  130. *
  131. */
  132. #define WX_SYS_LESS_THAN_OR_EQUAL_TO(v) ([[[UIDevice currentDevice] systemVersion] compare:v options:NSNumericSearch] != NSOrderedDescending)
  133. /**
  134. * @abstract Estimate component's type. If the type isn't equal to WXComponentTypeCommon, then return.
  135. */
  136. #define WX_CHECK_COMPONENT_TYPE(type)\
  137. do {\
  138. if (type != WXComponentTypeCommon) {\
  139. return;\
  140. }\
  141. } while (0);
  142. #if __has_attribute(objc_requires_super)
  143. #define WX_REQUIRES_SUPER __attribute__((objc_requires_super))
  144. #else
  145. #define WX_REQUIRES_SUPER
  146. #endif
  147. #endif
  148. WX_EXTERN_C_BEGIN
  149. NSString* GetWeexSDKVersion(void);
  150. NSString* GetWeexSDKBuildTime(void);
  151. unsigned long GetWeexSDKBuildTimestamp(void);
  152. WX_EXTERN_C_END