[iOS] Add methods to retrieve css style values from weexcore c++ object.
diff --git a/ios/sdk/WeexSDK/Sources/Layout/WXComponent+Layout.h b/ios/sdk/WeexSDK/Sources/Layout/WXComponent+Layout.h
index a338847..7a7dc37 100644
--- a/ios/sdk/WeexSDK/Sources/Layout/WXComponent+Layout.h
+++ b/ios/sdk/WeexSDK/Sources/Layout/WXComponent+Layout.h
@@ -26,6 +26,13 @@
#ifdef __cplusplus
#include "layout.h"
+typedef WeexCore::WXCoreFlexDirection WXCoreFlexDirection;
+typedef WeexCore::WXCoreFlexWrap WXCoreFlexWrap;
+typedef WeexCore::WXCoreJustifyContent WXCoreJustifyContent;
+typedef WeexCore::WXCoreAlignItems WXCoreAlignItems;
+typedef WeexCore::WXCoreAlignSelf WXCoreAlignSelf;
+typedef WeexCore::WXCorePositionType WXCorePositionType;
+
extern "C" {
#endif
bool flexIsUndefined(float value);
@@ -33,6 +40,19 @@
}
#endif
+#ifndef __cplusplus
+// Ensure that .m files can use css style enum definitions.
+#include "flex_enum.h"
+
+typedef enum WXCoreFlexDirection WXCoreFlexDirection;
+typedef enum WXCoreFlexWrap WXCoreFlexWrap;
+typedef enum WXCoreJustifyContent WXCoreJustifyContent;
+typedef enum WXCoreAlignItems WXCoreAlignItems;
+typedef enum WXCoreAlignSelf WXCoreAlignSelf;
+typedef enum WXCorePositionType WXCorePositionType;
+
+#endif
+
@interface WXComponent ()
{
@package
@@ -51,10 +71,60 @@
* @warning Subclasses must not override this.
*/
#ifdef __cplusplus
-@property(nonatomic, readonly, assign) WeexCore::WXCoreLayoutNode *flexCssNode;
+@property (nonatomic, readonly, assign) WeexCore::WXCoreLayoutNode *flexCssNode;
#endif
/**
+ * @abstract Get css style value for key. The key should be of CSS standard form.
+ * This method is for convenience use in C/ObjC environment. And if you want to
+ * retrieve all style values or in C++, you could use flexCssNode directly.
+ *
+ * Thread usage:
+ * This method should be invoked in component thread by WXPerformBlockOnComponentThread.
+ * Note that all initWithRef methods of WXComponent and its subclasses are performed in
+ * component thread by default. Therefore you can call this method directly in initWithRef.
+ *
+ * Supported keys:
+ * width, height, min-width, min-height, max-width, max-height,
+ * margin-(left/right/top/bottom)
+ * padding-(left/right/top/bottom)
+ * border-(left/right/top/bottom)-width
+ * left, right, top, bottom
+ * flex-grow
+ */
+- (float)getCssStyleValueForKey:(NSString *)key;
+
+/**
+ * @abstract Get css style flex-direction. Thread usage the same as getCssStyleValueForKey.
+ */
+- (WXCoreFlexDirection)getCssStyleFlexDirection;
+
+/**
+ * @abstract Get css style flex-wrap. Thread usage the same as getCssStyleValueForKey.
+ */
+- (WXCoreFlexWrap)getCssStyleFlexWrap;
+
+/**
+ * @abstract Get css style justify-content. Thread usage the same as getCssStyleValueForKey.
+ */
+- (WXCoreJustifyContent)getCssStyleJustifyContent;
+
+/**
+ * @abstract Get css style align-items. Thread usage the same as getCssStyleValueForKey.
+ */
+- (WXCoreAlignItems)getCssStyleAlignItems;
+
+/**
+ * @abstract Get css style align-self. Thread usage the same as getCssStyleValueForKey.
+ */
+- (WXCoreAlignSelf)getCssStyleAlignSelf;
+
+/**
+ * @abstract Get css style position. Thread usage the same as getCssStyleValueForKey.
+ */
+- (WXCorePositionType)getCssStylePositionType;
+
+/**
* @abstract Convert layout dimension value like 'left', 'width' to style value in js considering viewport and scale.
*/
- (NSString*)convertLayoutValueToStyleValue:(NSString*)valueName;
diff --git a/ios/sdk/WeexSDK/Sources/Layout/WXComponent+Layout.mm b/ios/sdk/WeexSDK/Sources/Layout/WXComponent+Layout.mm
index 18cb24d..8afd225 100644
--- a/ios/sdk/WeexSDK/Sources/Layout/WXComponent+Layout.mm
+++ b/ios/sdk/WeexSDK/Sources/Layout/WXComponent+Layout.mm
@@ -366,6 +366,86 @@
return defaultValue;
}
+- (float)getCssStyleValueForKey:(NSString *)key
+{
+ /*
+ * width, height, min-width, min-height, max-width, max-height,
+ * margin-(left/right/top/bottom)
+ * padding-(left/right/top/bottom)
+ * border-(left/right/top/bottom)-width
+ * left, right, top, bottom
+ * flex-grow
+ */
+ WXAssert(_flexCssNode != nullptr, @"Css node is null.");
+ if (_flexCssNode == nullptr) {
+ return NAN;
+ }
+
+ std::string ckey = [key UTF8String];
+ if (ckey == "width") return _flexCssNode->getStyleWidth();
+ if (ckey == "height") return _flexCssNode->getStyleHeight();
+ if (ckey == "min-width") return _flexCssNode->getMinWidth();
+ if (ckey == "min-height") return _flexCssNode->getMinHeight();
+ if (ckey == "max-width") return _flexCssNode->getMaxWidth();
+ if (ckey == "max-height") return _flexCssNode->getMaxHeight();
+ if (ckey == "margin-left") return _flexCssNode->getMarginLeft();
+ if (ckey == "margin-right") return _flexCssNode->getMarginRight();
+ if (ckey == "margin-top") return _flexCssNode->getMarginTop();
+ if (ckey == "margin-bottom") return _flexCssNode->getMarginBottom();
+ if (ckey == "padding-left") return _flexCssNode->getPaddingLeft();
+ if (ckey == "padding-right") return _flexCssNode->getPaddingRight();
+ if (ckey == "padding-top") return _flexCssNode->getPaddingTop();
+ if (ckey == "padding-bottom") return _flexCssNode->getPaddingBottom();
+ if (ckey == "border-left-width") return _flexCssNode->getBorderWidthLeft();
+ if (ckey == "border-right-width") return _flexCssNode->getBorderWidthRight();
+ if (ckey == "border-top-width") return _flexCssNode->getBorderWidthTop();
+ if (ckey == "border-bottom-width") return _flexCssNode->getBorderWidthBottom();
+ if (ckey == "left") return _flexCssNode->getStylePositionLeft();
+ if (ckey == "right") return _flexCssNode->getStylePositionRight();
+ if (ckey == "top") return _flexCssNode->getStylePositionTop();
+ if (ckey == "bottom") return _flexCssNode->getStylePositionBottom();
+ if (ckey == "flex-grow") return _flexCssNode->getFlex();
+
+ WXAssert(NO, @"Invalid css style key %@", key);
+ return NAN;
+}
+
+- (WXCoreFlexDirection)getCssStyleFlexDirection
+{
+ WXAssert(_flexCssNode != nullptr, @"Css node is null.");
+ return _flexCssNode ? _flexCssNode->getFlexDirection() : kFlexDirectionColumn;
+}
+
+- (WXCoreFlexWrap)getCssStyleFlexWrap
+{
+ WXAssert(_flexCssNode != nullptr, @"Css node is null.");
+ return _flexCssNode ? _flexCssNode->getFlexWrap() : kNoWrap;
+}
+
+- (WXCoreJustifyContent)getCssStyleJustifyContent
+{
+ WXAssert(_flexCssNode != nullptr, @"Css node is null.");
+ return _flexCssNode ? _flexCssNode->getJustifyContent() : kJustifyFlexStart;
+}
+
+- (WXCoreAlignItems)getCssStyleAlignItems
+{
+ WXAssert(_flexCssNode != nullptr, @"Css node is null.");
+ return _flexCssNode ? _flexCssNode->getAlignItems() : kAlignItemsStretch;
+}
+
+- (WXCoreAlignSelf)getCssStyleAlignSelf
+{
+ WXAssert(_flexCssNode != nullptr, @"Css node is null.");
+ return _flexCssNode ? _flexCssNode->getAlignSelf() : kAlignSelfAuto;
+}
+
+- (WXCorePositionType)getCssStylePositionType
+{
+ WXAssert(_flexCssNode != nullptr, @"Css node is null.");
+ return _flexCssNode ? _flexCssNode->getStylePositionType() : kRelative;
+}
+
- (NSString*)convertLayoutValueToStyleValue:(NSString*)valueName
{
if (_flexCssNode == nullptr) {
diff --git a/weex_core/Source/core/layout/flex_enum.h b/weex_core/Source/core/layout/flex_enum.h
index 9eb3676..7e439b2 100644
--- a/weex_core/Source/core/layout/flex_enum.h
+++ b/weex_core/Source/core/layout/flex_enum.h
@@ -16,12 +16,14 @@
* specific language governing permissions and limitations
* under the License.
*/
-#ifdef __cplusplus
#ifndef WEEXCORE_FLEXLAYOUT_WXCOREFLEXENUM_H
#define WEEXCORE_FLEXLAYOUT_WXCOREFLEXENUM_H
+/* These enum definitions may also be used by C files. */
+#ifdef __cplusplus
namespace WeexCore {
+#endif
/**
* MainAxis direction
@@ -120,6 +122,8 @@
kLeft,
};
+#ifdef __cplusplus
}
+#endif
+
#endif //WEEXCORE_FLEXLAYOUT_WXCOREFLEXENUM_H
-#endif
\ No newline at end of file
diff --git a/weex_core/Source/core/layout/layout.h b/weex_core/Source/core/layout/layout.h
index 0d62edd..4b8f0c5 100644
--- a/weex_core/Source/core/layout/layout.h
+++ b/weex_core/Source/core/layout/layout.h
@@ -836,7 +836,7 @@
}
}
- inline WXCorePositionType getStypePositionType() const {
+ inline WXCorePositionType getStylePositionType() const {
return mCssStyle->mPositionType;
}