WXComponent+Layout.h 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162
  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. #import "WXComponent.h"
  20. #import "WXSDKInstance.h"
  21. #import "WXUtility.h"
  22. #define FlexUndefined NAN
  23. #ifdef __cplusplus
  24. #include "layout.h"
  25. typedef WeexCore::WXCoreFlexDirection WXCoreFlexDirection;
  26. typedef WeexCore::WXCoreFlexWrap WXCoreFlexWrap;
  27. typedef WeexCore::WXCoreJustifyContent WXCoreJustifyContent;
  28. typedef WeexCore::WXCoreAlignItems WXCoreAlignItems;
  29. typedef WeexCore::WXCoreAlignSelf WXCoreAlignSelf;
  30. typedef WeexCore::WXCorePositionType WXCorePositionType;
  31. typedef WeexCore::WXCoreDirection WXCoreDirection;
  32. extern "C" {
  33. #endif
  34. bool flexIsUndefined(float value);
  35. #ifdef __cplusplus
  36. }
  37. #endif
  38. #ifndef __cplusplus
  39. // Ensure that .m files can use css style enum definitions.
  40. #include "flex_enum.h"
  41. typedef enum WXCoreFlexDirection WXCoreFlexDirection;
  42. typedef enum WXCoreFlexWrap WXCoreFlexWrap;
  43. typedef enum WXCoreJustifyContent WXCoreJustifyContent;
  44. typedef enum WXCoreAlignItems WXCoreAlignItems;
  45. typedef enum WXCoreAlignSelf WXCoreAlignSelf;
  46. typedef enum WXCorePositionType WXCorePositionType;
  47. typedef enum WXCoreDirection WXCoreDirection;
  48. #endif
  49. @interface WXComponent ()
  50. {
  51. @package
  52. #ifdef __cplusplus
  53. WeexCore::WXCoreLayoutNode *_flexCssNode;
  54. #endif // __cplusplus
  55. CGRect _calculatedFrame;
  56. CGPoint _absolutePosition;
  57. WXPositionType _positionType;
  58. BOOL _isLastLayoutDirectionRTL;
  59. BOOL _isLayoutDirectionRTL;
  60. }
  61. /**
  62. * @abstract Return the css node used to layout.
  63. *
  64. * @warning Subclasses must not override this.
  65. */
  66. #ifdef __cplusplus
  67. @property (nonatomic, readonly, assign) WeexCore::WXCoreLayoutNode *flexCssNode;
  68. #endif
  69. /**
  70. * @abstract Get css style value for key. The key should be of CSS standard form.
  71. * This method is for convenience use in C/ObjC environment. And if you want to
  72. * retrieve all style values or in C++, you could use flexCssNode directly.
  73. *
  74. * Thread usage:
  75. * This method should be invoked in component thread by WXPerformBlockOnComponentThread.
  76. * Note that all initWithRef methods of WXComponent and its subclasses are performed in
  77. * component thread by default. Therefore you can call this method directly in initWithRef.
  78. *
  79. * Supported keys:
  80. * width, height, min-width, min-height, max-width, max-height,
  81. * margin-(left/right/top/bottom)
  82. * padding-(left/right/top/bottom)
  83. * border-(left/right/top/bottom)-width
  84. * left, right, top, bottom
  85. * flex-grow
  86. */
  87. - (float)getCssStyleValueForKey:(NSString *)key;
  88. /**
  89. * @abstract Get css style flex-direction. Thread usage the same as getCssStyleValueForKey.
  90. */
  91. - (WXCoreFlexDirection)getCssStyleFlexDirection;
  92. /**
  93. * @abstract Get css style flex-wrap. Thread usage the same as getCssStyleValueForKey.
  94. */
  95. - (WXCoreFlexWrap)getCssStyleFlexWrap;
  96. /**
  97. * @abstract Get css style justify-content. Thread usage the same as getCssStyleValueForKey.
  98. */
  99. - (WXCoreJustifyContent)getCssStyleJustifyContent;
  100. /**
  101. * @abstract Get css style align-items. Thread usage the same as getCssStyleValueForKey.
  102. */
  103. - (WXCoreAlignItems)getCssStyleAlignItems;
  104. /**
  105. * @abstract Get css style align-self. Thread usage the same as getCssStyleValueForKey.
  106. */
  107. - (WXCoreAlignSelf)getCssStyleAlignSelf;
  108. /**
  109. * @abstract Get css style position. Thread usage the same as getCssStyleValueForKey.
  110. */
  111. - (WXCorePositionType)getCssStylePositionType;
  112. /**
  113. * @abstract Get css layout direction. Thread usage the same as getCssStyleValueForKey.
  114. */
  115. - (WXCoreDirection)getCssDirection;
  116. /**
  117. * @abstract Convert layout dimension value like 'left', 'width' to style value in js considering viewport and scale.
  118. */
  119. - (NSString*)convertLayoutValueToStyleValue:(NSString*)valueName;
  120. /**
  121. * @abstract Get style width of a container(scroller like) with safe value. No NAN, No zero.
  122. */
  123. - (CGFloat)safeContainerStyleWidth;
  124. /**
  125. * @abstract Delete css node of a subcomponent.
  126. */
  127. - (void)removeSubcomponentCssNode:(WXComponent *)subcomponent;
  128. #pragma mark - RTL
  129. @property (nonatomic, assign, readonly) BOOL isDirectionRTL;
  130. // Now we scrollView RTL solution is tranform
  131. // so scrollView need tranform subviews when RTL by default
  132. // if your component view is not scrollView but also implement RTL layout by tranform,you need return YES
  133. - (BOOL)shouldTransformSubviewsWhenRTL;
  134. - (void)layoutDirectionDidChanged:(BOOL)isRTL;
  135. @end