From f1055bcac8b580c40f9646687e7a950fb6864c74 Mon Sep 17 00:00:00 2001 From: Pritesh Nandgaonkar Date: Tue, 19 Dec 2017 11:18:00 -0800 Subject: [PATCH] Make YGNode as c++ struct with properties exposed through accessors Reviewed By: emilsjolander Differential Revision: D6592257 fbshipit-source-id: 641e8b9462ad00731a094511f9f5608b23a6bb21 --- Libraries/Text/RCTShadowText.m | 2 +- .../Text/RCTText.xcodeproj/project.pbxproj | 13 +- React/React.xcodeproj/project.pbxproj | 82 +- React/Views/RCTShadowView.m | 6 +- .../jni/first-party/yogajni/jni/YGJNI.cpp | 34 +- ReactCommon/yoga/yoga/YGNode.cpp | 399 ++++ ReactCommon/yoga/yoga/YGNode.h | 121 ++ ReactCommon/yoga/yoga/YGNodePrint.cpp | 137 +- ReactCommon/yoga/yoga/Yoga-internal.h | 191 +- ReactCommon/yoga/yoga/Yoga.cpp | 1928 ++++++++++------- ReactCommon/yoga/yoga/Yoga.h | 28 +- 11 files changed, 1902 insertions(+), 1039 deletions(-) create mode 100644 ReactCommon/yoga/yoga/YGNode.cpp create mode 100644 ReactCommon/yoga/yoga/YGNode.h diff --git a/Libraries/Text/RCTShadowText.m b/Libraries/Text/RCTShadowText.m index 92108a55f7765e..426f043fb34ab9 100644 --- a/Libraries/Text/RCTShadowText.m +++ b/Libraries/Text/RCTShadowText.m @@ -74,7 +74,7 @@ - (instancetype)init _writingDirection = NSWritingDirectionNatural; _cachedLayoutDirection = UIUserInterfaceLayoutDirectionLeftToRight; - YGNodeSetMeasureFunc(self.yogaNode, RCTMeasure); + YGNodeSetMeasureFunc(self.yogaNode, RCTMeasure); [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(contentSizeMultiplierDidChange:) diff --git a/Libraries/Text/RCTText.xcodeproj/project.pbxproj b/Libraries/Text/RCTText.xcodeproj/project.pbxproj index 0065b050984e6b..a9ab7d13ac91ab 100644 --- a/Libraries/Text/RCTText.xcodeproj/project.pbxproj +++ b/Libraries/Text/RCTText.xcodeproj/project.pbxproj @@ -15,17 +15,15 @@ 2D3B5F331D9B102D00451313 /* RCTTextSelection.m in Sources */ = {isa = PBXBuildFile; fileRef = 19FC5C841D41A4120090108F /* RCTTextSelection.m */; }; 2D3B5F341D9B103100451313 /* RCTRawTextManager.m in Sources */ = {isa = PBXBuildFile; fileRef = 58B511C71A9E6C5C00147676 /* RCTRawTextManager.m */; }; 2D3B5F351D9B103300451313 /* RCTShadowRawText.m in Sources */ = {isa = PBXBuildFile; fileRef = 58B511C91A9E6C5C00147676 /* RCTShadowRawText.m */; }; - 2D3B5F361D9B106F00451313 /* RCTShadowText.m in Sources */ = {isa = PBXBuildFile; fileRef = 58B511CB1A9E6C5C00147676 /* RCTShadowText.m */; }; 2D3B5F371D9B106F00451313 /* RCTText.m in Sources */ = {isa = PBXBuildFile; fileRef = 58B512141A9E6EFF00147676 /* RCTText.m */; }; 2D3B5F381D9B106F00451313 /* RCTTextManager.m in Sources */ = {isa = PBXBuildFile; fileRef = 58B511CD1A9E6C5C00147676 /* RCTTextManager.m */; }; 2D3B5F391D9B106F00451313 /* RCTTextField.m in Sources */ = {isa = PBXBuildFile; fileRef = 1362F0FD1B4D51F400E06D8C /* RCTTextField.m */; }; 2D3B5F3A1D9B106F00451313 /* RCTTextFieldManager.m in Sources */ = {isa = PBXBuildFile; fileRef = 1362F0FF1B4D51F400E06D8C /* RCTTextFieldManager.m */; }; 2D3B5F3B1D9B106F00451313 /* RCTTextView.m in Sources */ = {isa = PBXBuildFile; fileRef = 131B6ABD1AF0CD0600FFC3E0 /* RCTTextView.m */; }; 2D3B5F3C1D9B106F00451313 /* RCTTextViewManager.m in Sources */ = {isa = PBXBuildFile; fileRef = 131B6ABF1AF0CD0600FFC3E0 /* RCTTextViewManager.m */; }; - 2DEAB2901F84BA4300FC6B42 /* RCTFontAttributes.m in Sources */ = {isa = PBXBuildFile; fileRef = A85C82991F742AA20036C019 /* RCTFontAttributes.m */; }; + 5335D53F1FE8196200883D58 /* RCTShadowText.m in Sources */ = {isa = PBXBuildFile; fileRef = 5335D53E1FE8196100883D58 /* RCTShadowText.m */; }; 58B511CE1A9E6C5C00147676 /* RCTRawTextManager.m in Sources */ = {isa = PBXBuildFile; fileRef = 58B511C71A9E6C5C00147676 /* RCTRawTextManager.m */; }; 58B511CF1A9E6C5C00147676 /* RCTShadowRawText.m in Sources */ = {isa = PBXBuildFile; fileRef = 58B511C91A9E6C5C00147676 /* RCTShadowRawText.m */; }; - 58B511D01A9E6C5C00147676 /* RCTShadowText.m in Sources */ = {isa = PBXBuildFile; fileRef = 58B511CB1A9E6C5C00147676 /* RCTShadowText.m */; }; 58B511D11A9E6C5C00147676 /* RCTTextManager.m in Sources */ = {isa = PBXBuildFile; fileRef = 58B511CD1A9E6C5C00147676 /* RCTTextManager.m */; }; 58B512161A9E6EFF00147676 /* RCTText.m in Sources */ = {isa = PBXBuildFile; fileRef = 58B512141A9E6EFF00147676 /* RCTText.m */; }; 598F41261F145D4900B8495B /* RCTBackedTextInputDelegateAdapter.m in Sources */ = {isa = PBXBuildFile; fileRef = 598F41251F145D4900B8495B /* RCTBackedTextInputDelegateAdapter.m */; }; @@ -89,13 +87,13 @@ 19FC5C841D41A4120090108F /* RCTTextSelection.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = RCTTextSelection.m; sourceTree = ""; }; 19FC5C861D41A4220090108F /* RCTTextSelection.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = RCTTextSelection.h; sourceTree = ""; }; 2D2A287B1D9B048500D4039D /* libRCTText-tvOS.a */ = {isa = PBXFileReference; explicitFileType = archive.ar; includeInIndex = 0; path = "libRCTText-tvOS.a"; sourceTree = BUILT_PRODUCTS_DIR; }; + 5335D53E1FE8196100883D58 /* RCTShadowText.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = RCTShadowText.m; sourceTree = ""; }; 58B5119B1A9E6C1200147676 /* libRCTText.a */ = {isa = PBXFileReference; explicitFileType = archive.ar; includeInIndex = 0; path = libRCTText.a; sourceTree = BUILT_PRODUCTS_DIR; }; 58B511C61A9E6C5C00147676 /* RCTRawTextManager.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = RCTRawTextManager.h; sourceTree = ""; }; 58B511C71A9E6C5C00147676 /* RCTRawTextManager.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = RCTRawTextManager.m; sourceTree = ""; }; 58B511C81A9E6C5C00147676 /* RCTShadowRawText.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = RCTShadowRawText.h; sourceTree = ""; }; 58B511C91A9E6C5C00147676 /* RCTShadowRawText.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = RCTShadowRawText.m; sourceTree = ""; }; 58B511CA1A9E6C5C00147676 /* RCTShadowText.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = RCTShadowText.h; sourceTree = ""; }; - 58B511CB1A9E6C5C00147676 /* RCTShadowText.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = RCTShadowText.m; sourceTree = ""; }; 58B511CC1A9E6C5C00147676 /* RCTTextManager.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = RCTTextManager.h; sourceTree = ""; }; 58B511CD1A9E6C5C00147676 /* RCTTextManager.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = RCTTextManager.m; sourceTree = ""; }; 58B512141A9E6EFF00147676 /* RCTText.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = RCTText.m; sourceTree = ""; }; @@ -125,6 +123,7 @@ 58B511921A9E6C1200147676 = { isa = PBXGroup; children = ( + 5335D53E1FE8196100883D58 /* RCTShadowText.m */, 58B5119C1A9E6C1200147676 /* Products */, 598F41231F145D4900B8495B /* RCTBackedTextInputDelegate.h */, 598F41241F145D4900B8495B /* RCTBackedTextInputDelegateAdapter.h */, @@ -140,7 +139,6 @@ 58B511C81A9E6C5C00147676 /* RCTShadowRawText.h */, 58B511C91A9E6C5C00147676 /* RCTShadowRawText.m */, 58B511CA1A9E6C5C00147676 /* RCTShadowText.h */, - 58B511CB1A9E6C5C00147676 /* RCTShadowText.m */, 59F60E8D1E661BDD0081153B /* RCTShadowTextField.h */, 59F60E8E1E661BDD0081153B /* RCTShadowTextField.m */, 59F60E8F1E661BDD0081153B /* RCTShadowTextView.h */, @@ -259,7 +257,6 @@ 2D3B5F371D9B106F00451313 /* RCTText.m in Sources */, 2D3B5F381D9B106F00451313 /* RCTTextManager.m in Sources */, 2D3B5F391D9B106F00451313 /* RCTTextField.m in Sources */, - 2D3B5F361D9B106F00451313 /* RCTShadowText.m in Sources */, 2D3B5F3B1D9B106F00451313 /* RCTTextView.m in Sources */, 59AF89AB1EDCBCC700F004B1 /* RCTUITextField.m in Sources */, 598F41271F145D4900B8495B /* RCTBackedTextInputDelegateAdapter.m in Sources */, @@ -283,6 +280,7 @@ files = ( 58B511D11A9E6C5C00147676 /* RCTTextManager.m in Sources */, 131B6AC01AF0CD0600FFC3E0 /* RCTTextView.m in Sources */, + 5335D53F1FE8196200883D58 /* RCTShadowText.m in Sources */, 58B511CE1A9E6C5C00147676 /* RCTRawTextManager.m in Sources */, 19FC5C851D41A4120090108F /* RCTTextSelection.m in Sources */, 1362F1001B4D51F400E06D8C /* RCTTextField.m in Sources */, @@ -298,7 +296,6 @@ 131B6AC11AF0CD0600FFC3E0 /* RCTTextViewManager.m in Sources */, 59F60E931E661BDD0081153B /* RCTShadowTextView.m in Sources */, 58B511CF1A9E6C5C00147676 /* RCTShadowRawText.m in Sources */, - 58B511D01A9E6C5C00147676 /* RCTShadowText.m in Sources */, ); runOnlyForDeploymentPostprocessing = 0; }; @@ -432,6 +429,7 @@ 58B511B01A9E6C1300147676 /* Debug */ = { isa = XCBuildConfiguration; buildSettings = { + CLANG_CXX_LANGUAGE_STANDARD = "gnu++0x"; CLANG_STATIC_ANALYZER_MODE = deep; OTHER_LDFLAGS = "-ObjC"; PRODUCT_NAME = "$(TARGET_NAME)"; @@ -442,6 +440,7 @@ 58B511B11A9E6C1300147676 /* Release */ = { isa = XCBuildConfiguration; buildSettings = { + CLANG_CXX_LANGUAGE_STANDARD = "gnu++0x"; CLANG_STATIC_ANALYZER_MODE = deep; OTHER_LDFLAGS = "-ObjC"; PRODUCT_NAME = "$(TARGET_NAME)"; diff --git a/React/React.xcodeproj/project.pbxproj b/React/React.xcodeproj/project.pbxproj index 784a92e6a6bfd8..74817a90a5550d 100644 --- a/React/React.xcodeproj/project.pbxproj +++ b/React/React.xcodeproj/project.pbxproj @@ -129,7 +129,6 @@ 13D9FEEB1CDCCECF00158BD7 /* RCTEventEmitter.m in Sources */ = {isa = PBXBuildFile; fileRef = 13D9FEEA1CDCCECF00158BD7 /* RCTEventEmitter.m */; }; 13D9FEEE1CDCD93000158BD7 /* RCTKeyboardObserver.m in Sources */ = {isa = PBXBuildFile; fileRef = 13D9FEED1CDCD93000158BD7 /* RCTKeyboardObserver.m */; }; 13E0674A1A70F434002CDEE1 /* RCTUIManager.m in Sources */ = {isa = PBXBuildFile; fileRef = 13E067491A70F434002CDEE1 /* RCTUIManager.m */; }; - 13E067551A70F44B002CDEE1 /* RCTShadowView.m in Sources */ = {isa = PBXBuildFile; fileRef = 13E0674C1A70F44B002CDEE1 /* RCTShadowView.m */; }; 13E067561A70F44B002CDEE1 /* RCTViewManager.m in Sources */ = {isa = PBXBuildFile; fileRef = 13E0674E1A70F44B002CDEE1 /* RCTViewManager.m */; }; 13E067571A70F44B002CDEE1 /* RCTView.m in Sources */ = {isa = PBXBuildFile; fileRef = 13E067501A70F44B002CDEE1 /* RCTView.m */; }; 13E067591A70F44B002CDEE1 /* UIView+React.m in Sources */ = {isa = PBXBuildFile; fileRef = 13E067541A70F44B002CDEE1 /* UIView+React.m */; }; @@ -320,7 +319,6 @@ 2D3B5EE01D9B09AD00451313 /* RCTRootShadowView.m in Sources */ = {isa = PBXBuildFile; fileRef = 13BCE8081C99CB9D00DD7AAD /* RCTRootShadowView.m */; }; 2D3B5EE31D9B09B700451313 /* RCTSegmentedControl.m in Sources */ = {isa = PBXBuildFile; fileRef = 131B6AF11AF1093D00FFC3E0 /* RCTSegmentedControl.m */; }; 2D3B5EE41D9B09BB00451313 /* RCTSegmentedControlManager.m in Sources */ = {isa = PBXBuildFile; fileRef = 131B6AF31AF1093D00FFC3E0 /* RCTSegmentedControlManager.m */; }; - 2D3B5EE51D9B09BE00451313 /* RCTShadowView.m in Sources */ = {isa = PBXBuildFile; fileRef = 13E0674C1A70F44B002CDEE1 /* RCTShadowView.m */; }; 2D3B5EEA1D9B09CD00451313 /* RCTTabBar.m in Sources */ = {isa = PBXBuildFile; fileRef = 137327E01AA5CF210034F82E /* RCTTabBar.m */; }; 2D3B5EEB1D9B09D000451313 /* RCTTabBarItem.m in Sources */ = {isa = PBXBuildFile; fileRef = 137327E21AA5CF210034F82E /* RCTTabBarItem.m */; }; 2D3B5EEC1D9B09D400451313 /* RCTTabBarItemManager.m in Sources */ = {isa = PBXBuildFile; fileRef = 137327E41AA5CF210034F82E /* RCTTabBarItemManager.m */; }; @@ -959,6 +957,9 @@ 3DFE0D1B1DF8575800459392 /* YGMacros.h in Copy Headers */ = {isa = PBXBuildFile; fileRef = 130A77041DF767AF001F9587 /* YGMacros.h */; }; 3DFE0D1C1DF8575800459392 /* Yoga.h in Copy Headers */ = {isa = PBXBuildFile; fileRef = 130A77081DF767AF001F9587 /* Yoga.h */; }; 3EDCA8A51D3591E700450C31 /* RCTErrorInfo.m in Sources */ = {isa = PBXBuildFile; fileRef = 3EDCA8A41D3591E700450C31 /* RCTErrorInfo.m */; }; + 5335D5411FE81A4700883D58 /* RCTShadowView.m in Sources */ = {isa = PBXBuildFile; fileRef = 5335D5401FE81A4700883D58 /* RCTShadowView.m */; }; + 534D3F811FE7E277002E5E0D /* YGNode.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 53EC85DF1FDEC75A0051B2B5 /* YGNode.cpp */; }; + 534D3F821FE7E296002E5E0D /* YGNode.h in Headers */ = {isa = PBXBuildFile; fileRef = 53EC85DE1FDEC75A0051B2B5 /* YGNode.h */; }; 5376C5E41FC6DDBC0083513D /* YGNodePrint.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 5376C5E11FC6DDB20083513D /* YGNodePrint.cpp */; }; 5376C5E51FC6DDBD0083513D /* YGNodePrint.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 5376C5E11FC6DDB20083513D /* YGNodePrint.cpp */; }; 5376C5E61FC6DDC10083513D /* YGNodePrint.h in Headers */ = {isa = PBXBuildFile; fileRef = 5376C5E01FC6DDB20083513D /* YGNodePrint.h */; }; @@ -971,6 +972,10 @@ 53D123A01FBF1EFF001B8A10 /* Yoga.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 53CBF1871FB4FE80002CBB31 /* Yoga.cpp */; }; 53D123A11FBF1EFF001B8A10 /* Yoga.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 53CBF1871FB4FE80002CBB31 /* Yoga.cpp */; }; 53D123B21FBF220F001B8A10 /* Yoga.h in Headers */ = {isa = PBXBuildFile; fileRef = 130A77081DF767AF001F9587 /* Yoga.h */; }; + 53EC85E21FDEC75F0051B2B5 /* YGNode.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 53EC85DF1FDEC75A0051B2B5 /* YGNode.cpp */; }; + 53EC85E31FDEC75F0051B2B5 /* YGNode.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 53EC85DF1FDEC75A0051B2B5 /* YGNode.cpp */; }; + 53EC85E41FDEC7630051B2B5 /* YGNode.h in Headers */ = {isa = PBXBuildFile; fileRef = 53EC85DE1FDEC75A0051B2B5 /* YGNode.h */; }; + 53EC85E51FDEC7630051B2B5 /* YGNode.h in Headers */ = {isa = PBXBuildFile; fileRef = 53EC85DE1FDEC75A0051B2B5 /* YGNode.h */; }; 58114A161AAE854800E7D092 /* RCTPicker.m in Sources */ = {isa = PBXBuildFile; fileRef = 58114A131AAE854800E7D092 /* RCTPicker.m */; }; 58114A171AAE854800E7D092 /* RCTPickerManager.m in Sources */ = {isa = PBXBuildFile; fileRef = 58114A151AAE854800E7D092 /* RCTPickerManager.m */; }; 58114A501AAE93D500E7D092 /* RCTAsyncLocalStorage.m in Sources */ = {isa = PBXBuildFile; fileRef = 58114A4E1AAE93D500E7D092 /* RCTAsyncLocalStorage.m */; }; @@ -1085,18 +1090,18 @@ 59EB6DC01EBD70130072A5E7 /* RCTUIManagerObserverCoordinator.h in Copy Headers */ = {isa = PBXBuildFile; fileRef = 59EB6DB91EBD6FC90072A5E7 /* RCTUIManagerObserverCoordinator.h */; }; 59EDBCA71FDF4E0C003573DE /* RCTScrollableProtocol.h in Headers */ = {isa = PBXBuildFile; fileRef = 59EDBC9C1FDF4E0C003573DE /* RCTScrollableProtocol.h */; }; 59EDBCA81FDF4E0C003573DE /* RCTScrollableProtocol.h in Headers */ = {isa = PBXBuildFile; fileRef = 59EDBC9C1FDF4E0C003573DE /* RCTScrollableProtocol.h */; }; - 59EDBCA91FDF4E0C003573DE /* RCTScrollContentShadowView.h in Headers */ = {isa = PBXBuildFile; fileRef = 59EDBC9D1FDF4E0C003573DE /* RCTScrollContentShadowView.h */; }; - 59EDBCAA1FDF4E0C003573DE /* RCTScrollContentShadowView.h in Headers */ = {isa = PBXBuildFile; fileRef = 59EDBC9D1FDF4E0C003573DE /* RCTScrollContentShadowView.h */; }; - 59EDBCAB1FDF4E0C003573DE /* RCTScrollContentShadowView.m in Sources */ = {isa = PBXBuildFile; fileRef = 59EDBC9E1FDF4E0C003573DE /* RCTScrollContentShadowView.m */; }; - 59EDBCAC1FDF4E0C003573DE /* RCTScrollContentShadowView.m in Sources */ = {isa = PBXBuildFile; fileRef = 59EDBC9E1FDF4E0C003573DE /* RCTScrollContentShadowView.m */; }; + 59EDBCA91FDF4E0C003573DE /* (null) in Headers */ = {isa = PBXBuildFile; }; + 59EDBCAA1FDF4E0C003573DE /* (null) in Headers */ = {isa = PBXBuildFile; }; + 59EDBCAB1FDF4E0C003573DE /* (null) in Sources */ = {isa = PBXBuildFile; }; + 59EDBCAC1FDF4E0C003573DE /* (null) in Sources */ = {isa = PBXBuildFile; }; 59EDBCAD1FDF4E0C003573DE /* RCTScrollContentView.h in Headers */ = {isa = PBXBuildFile; fileRef = 59EDBC9F1FDF4E0C003573DE /* RCTScrollContentView.h */; }; 59EDBCAE1FDF4E0C003573DE /* RCTScrollContentView.h in Headers */ = {isa = PBXBuildFile; fileRef = 59EDBC9F1FDF4E0C003573DE /* RCTScrollContentView.h */; }; 59EDBCAF1FDF4E0C003573DE /* RCTScrollContentView.m in Sources */ = {isa = PBXBuildFile; fileRef = 59EDBCA01FDF4E0C003573DE /* RCTScrollContentView.m */; }; 59EDBCB01FDF4E0C003573DE /* RCTScrollContentView.m in Sources */ = {isa = PBXBuildFile; fileRef = 59EDBCA01FDF4E0C003573DE /* RCTScrollContentView.m */; }; - 59EDBCB11FDF4E0C003573DE /* RCTScrollContentViewManager.h in Headers */ = {isa = PBXBuildFile; fileRef = 59EDBCA11FDF4E0C003573DE /* RCTScrollContentViewManager.h */; }; - 59EDBCB21FDF4E0C003573DE /* RCTScrollContentViewManager.h in Headers */ = {isa = PBXBuildFile; fileRef = 59EDBCA11FDF4E0C003573DE /* RCTScrollContentViewManager.h */; }; - 59EDBCB31FDF4E0C003573DE /* RCTScrollContentViewManager.m in Sources */ = {isa = PBXBuildFile; fileRef = 59EDBCA21FDF4E0C003573DE /* RCTScrollContentViewManager.m */; }; - 59EDBCB41FDF4E0C003573DE /* RCTScrollContentViewManager.m in Sources */ = {isa = PBXBuildFile; fileRef = 59EDBCA21FDF4E0C003573DE /* RCTScrollContentViewManager.m */; }; + 59EDBCB11FDF4E0C003573DE /* (null) in Headers */ = {isa = PBXBuildFile; }; + 59EDBCB21FDF4E0C003573DE /* (null) in Headers */ = {isa = PBXBuildFile; }; + 59EDBCB31FDF4E0C003573DE /* (null) in Sources */ = {isa = PBXBuildFile; }; + 59EDBCB41FDF4E0C003573DE /* (null) in Sources */ = {isa = PBXBuildFile; }; 59EDBCB51FDF4E0C003573DE /* RCTScrollView.h in Headers */ = {isa = PBXBuildFile; fileRef = 59EDBCA31FDF4E0C003573DE /* RCTScrollView.h */; }; 59EDBCB61FDF4E0C003573DE /* RCTScrollView.h in Headers */ = {isa = PBXBuildFile; fileRef = 59EDBCA31FDF4E0C003573DE /* RCTScrollView.h */; }; 59EDBCB71FDF4E0C003573DE /* RCTScrollView.m in Sources */ = {isa = PBXBuildFile; fileRef = 59EDBCA41FDF4E0C003573DE /* RCTScrollView.m */; }; @@ -1106,15 +1111,15 @@ 59EDBCBB1FDF4E0C003573DE /* RCTScrollViewManager.m in Sources */ = {isa = PBXBuildFile; fileRef = 59EDBCA61FDF4E0C003573DE /* RCTScrollViewManager.m */; }; 59EDBCBC1FDF4E0C003573DE /* RCTScrollViewManager.m in Sources */ = {isa = PBXBuildFile; fileRef = 59EDBCA61FDF4E0C003573DE /* RCTScrollViewManager.m */; }; 59EDBCBD1FDF4E43003573DE /* RCTScrollableProtocol.h in Copy Headers */ = {isa = PBXBuildFile; fileRef = 59EDBC9C1FDF4E0C003573DE /* RCTScrollableProtocol.h */; }; - 59EDBCBE1FDF4E43003573DE /* RCTScrollContentShadowView.h in Copy Headers */ = {isa = PBXBuildFile; fileRef = 59EDBC9D1FDF4E0C003573DE /* RCTScrollContentShadowView.h */; }; + 59EDBCBE1FDF4E43003573DE /* (null) in Copy Headers */ = {isa = PBXBuildFile; }; 59EDBCBF1FDF4E43003573DE /* RCTScrollContentView.h in Copy Headers */ = {isa = PBXBuildFile; fileRef = 59EDBC9F1FDF4E0C003573DE /* RCTScrollContentView.h */; }; - 59EDBCC01FDF4E43003573DE /* RCTScrollContentViewManager.h in Copy Headers */ = {isa = PBXBuildFile; fileRef = 59EDBCA11FDF4E0C003573DE /* RCTScrollContentViewManager.h */; }; + 59EDBCC01FDF4E43003573DE /* (null) in Copy Headers */ = {isa = PBXBuildFile; }; 59EDBCC11FDF4E43003573DE /* RCTScrollView.h in Copy Headers */ = {isa = PBXBuildFile; fileRef = 59EDBCA31FDF4E0C003573DE /* RCTScrollView.h */; }; 59EDBCC21FDF4E43003573DE /* RCTScrollViewManager.h in Copy Headers */ = {isa = PBXBuildFile; fileRef = 59EDBCA51FDF4E0C003573DE /* RCTScrollViewManager.h */; }; 59EDBCC31FDF4E55003573DE /* RCTScrollableProtocol.h in Copy Headers */ = {isa = PBXBuildFile; fileRef = 59EDBC9C1FDF4E0C003573DE /* RCTScrollableProtocol.h */; }; - 59EDBCC41FDF4E55003573DE /* RCTScrollContentShadowView.h in Copy Headers */ = {isa = PBXBuildFile; fileRef = 59EDBC9D1FDF4E0C003573DE /* RCTScrollContentShadowView.h */; }; + 59EDBCC41FDF4E55003573DE /* (null) in Copy Headers */ = {isa = PBXBuildFile; }; 59EDBCC51FDF4E55003573DE /* RCTScrollContentView.h in Copy Headers */ = {isa = PBXBuildFile; fileRef = 59EDBC9F1FDF4E0C003573DE /* RCTScrollContentView.h */; }; - 59EDBCC61FDF4E55003573DE /* RCTScrollContentViewManager.h in Copy Headers */ = {isa = PBXBuildFile; fileRef = 59EDBCA11FDF4E0C003573DE /* RCTScrollContentViewManager.h */; }; + 59EDBCC61FDF4E55003573DE /* (null) in Copy Headers */ = {isa = PBXBuildFile; }; 59EDBCC71FDF4E55003573DE /* RCTScrollView.h in Copy Headers */ = {isa = PBXBuildFile; fileRef = 59EDBCA31FDF4E0C003573DE /* RCTScrollView.h */; }; 59EDBCC81FDF4E55003573DE /* RCTScrollViewManager.h in Copy Headers */ = {isa = PBXBuildFile; fileRef = 59EDBCA51FDF4E0C003573DE /* RCTScrollViewManager.h */; }; 657734841EE834C900A0E9EA /* RCTInspectorDevServerHelper.h in Headers */ = {isa = PBXBuildFile; fileRef = 657734821EE834C900A0E9EA /* RCTInspectorDevServerHelper.h */; }; @@ -1338,9 +1343,9 @@ dstSubfolderSpec = 16; files = ( 59EDBCC31FDF4E55003573DE /* RCTScrollableProtocol.h in Copy Headers */, - 59EDBCC41FDF4E55003573DE /* RCTScrollContentShadowView.h in Copy Headers */, + 59EDBCC41FDF4E55003573DE /* (null) in Copy Headers */, 59EDBCC51FDF4E55003573DE /* RCTScrollContentView.h in Copy Headers */, - 59EDBCC61FDF4E55003573DE /* RCTScrollContentViewManager.h in Copy Headers */, + 59EDBCC61FDF4E55003573DE /* (null) in Copy Headers */, 59EDBCC71FDF4E55003573DE /* RCTScrollView.h in Copy Headers */, 59EDBCC81FDF4E55003573DE /* RCTScrollViewManager.h in Copy Headers */, 594F0A411FD233BD007FBE96 /* RCTSurface.h in Copy Headers */, @@ -1569,9 +1574,9 @@ dstSubfolderSpec = 16; files = ( 59EDBCBD1FDF4E43003573DE /* RCTScrollableProtocol.h in Copy Headers */, - 59EDBCBE1FDF4E43003573DE /* RCTScrollContentShadowView.h in Copy Headers */, + 59EDBCBE1FDF4E43003573DE /* (null) in Copy Headers */, 59EDBCBF1FDF4E43003573DE /* RCTScrollContentView.h in Copy Headers */, - 59EDBCC01FDF4E43003573DE /* RCTScrollContentViewManager.h in Copy Headers */, + 59EDBCC01FDF4E43003573DE /* (null) in Copy Headers */, 59EDBCC11FDF4E43003573DE /* RCTScrollView.h in Copy Headers */, 59EDBCC21FDF4E43003573DE /* RCTScrollViewManager.h in Copy Headers */, 594F0A381FD233A2007FBE96 /* RCTSurface.h in Copy Headers */, @@ -1989,7 +1994,6 @@ 13E067481A70F434002CDEE1 /* RCTUIManager.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = RCTUIManager.h; sourceTree = ""; }; 13E067491A70F434002CDEE1 /* RCTUIManager.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = RCTUIManager.m; sourceTree = ""; }; 13E0674B1A70F44B002CDEE1 /* RCTShadowView.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = RCTShadowView.h; sourceTree = ""; }; - 13E0674C1A70F44B002CDEE1 /* RCTShadowView.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = RCTShadowView.m; sourceTree = ""; }; 13E0674D1A70F44B002CDEE1 /* RCTViewManager.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = RCTViewManager.h; sourceTree = ""; }; 13E0674E1A70F44B002CDEE1 /* RCTViewManager.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = RCTViewManager.m; sourceTree = ""; }; 13E0674F1A70F44B002CDEE1 /* RCTView.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = RCTView.h; sourceTree = ""; }; @@ -2135,12 +2139,15 @@ 3EDCA8A21D3591E700450C31 /* RCTErrorCustomizer.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = RCTErrorCustomizer.h; sourceTree = ""; }; 3EDCA8A31D3591E700450C31 /* RCTErrorInfo.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = RCTErrorInfo.h; sourceTree = ""; }; 3EDCA8A41D3591E700450C31 /* RCTErrorInfo.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = RCTErrorInfo.m; sourceTree = ""; }; + 5335D5401FE81A4700883D58 /* RCTShadowView.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = RCTShadowView.m; sourceTree = ""; }; 5376C5E01FC6DDB20083513D /* YGNodePrint.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = YGNodePrint.h; sourceTree = ""; }; 5376C5E11FC6DDB20083513D /* YGNodePrint.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = YGNodePrint.cpp; sourceTree = ""; }; 53CBF1851FB4FE80002CBB31 /* Yoga-internal.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = "Yoga-internal.h"; sourceTree = ""; }; 53CBF1861FB4FE80002CBB31 /* YGEnums.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = YGEnums.cpp; sourceTree = ""; }; 53CBF1871FB4FE80002CBB31 /* Yoga.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = Yoga.cpp; sourceTree = ""; }; 53D123831FBF1D49001B8A10 /* libyoga.a */ = {isa = PBXFileReference; lastKnownFileType = archive.ar; name = libyoga.a; path = "../../../../../../../../../Library/Developer/Xcode/DerivedData/yoga-hdfifpwsinitsibujacpiefkjfdy/Build/Products/Debug/libyoga.a"; sourceTree = ""; }; + 53EC85DE1FDEC75A0051B2B5 /* YGNode.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = YGNode.h; sourceTree = ""; }; + 53EC85DF1FDEC75A0051B2B5 /* YGNode.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = YGNode.cpp; sourceTree = ""; }; 58114A121AAE854800E7D092 /* RCTPicker.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = RCTPicker.h; sourceTree = ""; }; 58114A131AAE854800E7D092 /* RCTPicker.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = RCTPicker.m; sourceTree = ""; }; 58114A141AAE854800E7D092 /* RCTPickerManager.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = RCTPickerManager.h; sourceTree = ""; }; @@ -2188,12 +2195,8 @@ 59EB6DB91EBD6FC90072A5E7 /* RCTUIManagerObserverCoordinator.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = RCTUIManagerObserverCoordinator.h; sourceTree = ""; }; 59EB6DBA1EBD6FC90072A5E7 /* RCTUIManagerObserverCoordinator.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = RCTUIManagerObserverCoordinator.mm; sourceTree = ""; }; 59EDBC9C1FDF4E0C003573DE /* RCTScrollableProtocol.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = RCTScrollableProtocol.h; sourceTree = ""; }; - 59EDBC9D1FDF4E0C003573DE /* RCTScrollContentShadowView.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = RCTScrollContentShadowView.h; sourceTree = ""; }; - 59EDBC9E1FDF4E0C003573DE /* RCTScrollContentShadowView.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = RCTScrollContentShadowView.m; sourceTree = ""; }; 59EDBC9F1FDF4E0C003573DE /* RCTScrollContentView.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = RCTScrollContentView.h; sourceTree = ""; }; 59EDBCA01FDF4E0C003573DE /* RCTScrollContentView.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = RCTScrollContentView.m; sourceTree = ""; }; - 59EDBCA11FDF4E0C003573DE /* RCTScrollContentViewManager.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = RCTScrollContentViewManager.h; sourceTree = ""; }; - 59EDBCA21FDF4E0C003573DE /* RCTScrollContentViewManager.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = RCTScrollContentViewManager.m; sourceTree = ""; }; 59EDBCA31FDF4E0C003573DE /* RCTScrollView.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = RCTScrollView.h; sourceTree = ""; }; 59EDBCA41FDF4E0C003573DE /* RCTScrollView.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = RCTScrollView.m; sourceTree = ""; }; 59EDBCA51FDF4E0C003573DE /* RCTScrollViewManager.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = RCTScrollViewManager.h; sourceTree = ""; }; @@ -2315,6 +2318,8 @@ 130A77021DF767AF001F9587 /* yoga */ = { isa = PBXGroup; children = ( + 53EC85DF1FDEC75A0051B2B5 /* YGNode.cpp */, + 53EC85DE1FDEC75A0051B2B5 /* YGNode.h */, 5376C5E11FC6DDB20083513D /* YGNodePrint.cpp */, 5376C5E01FC6DDB20083513D /* YGNodePrint.h */, 53CBF1861FB4FE80002CBB31 /* YGEnums.cpp */, @@ -2503,6 +2508,7 @@ 13B07FF31A6947C200A75B9A /* Views */ = { isa = PBXGroup; children = ( + 5335D5401FE81A4700883D58 /* RCTShadowView.m */, B95154301D1B34B200FE7B80 /* RCTActivityIndicatorView.h */, B95154311D1B34B200FE7B80 /* RCTActivityIndicatorView.m */, 13B080181A69489C00A75B9A /* RCTActivityIndicatorViewManager.h */, @@ -2563,7 +2569,6 @@ 131B6AF21AF1093D00FFC3E0 /* RCTSegmentedControlManager.h */, 131B6AF31AF1093D00FFC3E0 /* RCTSegmentedControlManager.m */, 13E0674B1A70F44B002CDEE1 /* RCTShadowView.h */, - 13E0674C1A70F44B002CDEE1 /* RCTShadowView.m */, 597633351F4E021D005BE8A4 /* RCTShadowView+Internal.h */, 597633341F4E021D005BE8A4 /* RCTShadowView+Internal.m */, 590D7BFB1EBD458B00D8A370 /* RCTShadowView+Layout.h */, @@ -2800,12 +2805,8 @@ isa = PBXGroup; children = ( 59EDBC9C1FDF4E0C003573DE /* RCTScrollableProtocol.h */, - 59EDBC9D1FDF4E0C003573DE /* RCTScrollContentShadowView.h */, - 59EDBC9E1FDF4E0C003573DE /* RCTScrollContentShadowView.m */, 59EDBC9F1FDF4E0C003573DE /* RCTScrollContentView.h */, 59EDBCA01FDF4E0C003573DE /* RCTScrollContentView.m */, - 59EDBCA11FDF4E0C003573DE /* RCTScrollContentViewManager.h */, - 59EDBCA21FDF4E0C003573DE /* RCTScrollContentViewManager.m */, 59EDBCA31FDF4E0C003573DE /* RCTScrollView.h */, 59EDBCA41FDF4E0C003573DE /* RCTScrollView.m */, 59EDBCA51FDF4E0C003573DE /* RCTScrollViewManager.h */, @@ -3100,7 +3101,7 @@ 3D302F351DF828F800D6DDAE /* RCTErrorCustomizer.h in Headers */, 3D302F361DF828F800D6DDAE /* RCTErrorInfo.h in Headers */, 3D302F371DF828F800D6DDAE /* RCTEventDispatcher.h in Headers */, - 59EDBCAA1FDF4E0C003573DE /* RCTScrollContentShadowView.h in Headers */, + 59EDBCAA1FDF4E0C003573DE /* (null) in Headers */, 594F0A371FD23228007FBE96 /* RCTSurfaceSizeMeasureMode.h in Headers */, 3D302F381DF828F800D6DDAE /* RCTFrameUpdate.h in Headers */, 3D302F391DF828F800D6DDAE /* RCTImageSource.h in Headers */, @@ -3129,7 +3130,7 @@ 3D302F481DF828F800D6DDAE /* RCTRootView.h in Headers */, 3D302F491DF828F800D6DDAE /* RCTRootViewDelegate.h in Headers */, 3D302F4A1DF828F800D6DDAE /* RCTRootViewInternal.h in Headers */, - 59EDBCB21FDF4E0C003573DE /* RCTScrollContentViewManager.h in Headers */, + 59EDBCB21FDF4E0C003573DE /* (null) in Headers */, 3D302F4B1DF828F800D6DDAE /* RCTTouchEvent.h in Headers */, 59D031F21F8353D3008361F0 /* RCTSafeAreaView.h in Headers */, 3D302F4C1DF828F800D6DDAE /* RCTTouchHandler.h in Headers */, @@ -3233,6 +3234,7 @@ isa = PBXHeadersBuildPhase; buildActionMask = 2147483647; files = ( + 53EC85E41FDEC7630051B2B5 /* YGNode.h in Headers */, 53D1239F1FBF1EFB001B8A10 /* Yoga-internal.h in Headers */, 3DFE0D161DF8574D00459392 /* YGEnums.h in Headers */, 3DFE0D171DF8574D00459392 /* YGMacros.h in Headers */, @@ -3310,6 +3312,7 @@ isa = PBXHeadersBuildPhase; buildActionMask = 2147483647; files = ( + 53EC85E51FDEC7630051B2B5 /* YGNode.h in Headers */, 53D1239E1FBF1EFB001B8A10 /* Yoga-internal.h in Headers */, 133957881DF76D3500EC27BE /* YGEnums.h in Headers */, 1339578B1DF76D3500EC27BE /* Yoga.h in Headers */, @@ -3384,6 +3387,7 @@ 3D80DA1F1DF820620028D040 /* RCTPushNotificationManager.h in Headers */, 3D80DA201DF820620028D040 /* RCTAssert.h in Headers */, 3D80DA211DF820620028D040 /* RCTBridge.h in Headers */, + 534D3F821FE7E296002E5E0D /* YGNode.h in Headers */, 13F880381E296D2800C3C7A1 /* JSCWrapper.h in Headers */, 3D80DA221DF820620028D040 /* RCTBridge+Private.h in Headers */, 599FAA461FB274980058CCF6 /* RCTSurfaceStage.h in Headers */, @@ -3405,7 +3409,7 @@ 3D7BFD2D1EA8E3FA008DFB7A /* RCTReconnectingWebSocket.h in Headers */, 3D80DA2C1DF820620028D040 /* RCTEventDispatcher.h in Headers */, 3D80DA2D1DF820620028D040 /* RCTFrameUpdate.h in Headers */, - 59EDBCA91FDF4E0C003573DE /* RCTScrollContentShadowView.h in Headers */, + 59EDBCA91FDF4E0C003573DE /* (null) in Headers */, 3D80DA2E1DF820620028D040 /* RCTImageSource.h in Headers */, 3D80DA2F1DF820620028D040 /* RCTInvalidating.h in Headers */, 598FD1971F817336006C54CB /* RCTModalManager.h in Headers */, @@ -3427,7 +3431,7 @@ 53D123B21FBF220F001B8A10 /* Yoga.h in Headers */, 3D80DA391DF820620028D040 /* RCTNullability.h in Headers */, 3D80DA3A1DF820620028D040 /* RCTParserUtils.h in Headers */, - 59EDBCB11FDF4E0C003573DE /* RCTScrollContentViewManager.h in Headers */, + 59EDBCB11FDF4E0C003573DE /* (null) in Headers */, 599FAA421FB274980058CCF6 /* RCTSurfaceRootView.h in Headers */, 59D031F91F8353D3008361F0 /* RCTSafeAreaViewManager.h in Headers */, 3D80DA3B1DF820620028D040 /* RCTPerformanceLogger.h in Headers */, @@ -4088,7 +4092,7 @@ 2D3B5EA31D9B08BE00451313 /* RCTParserUtils.m in Sources */, 59500D461F71C63F00B122B7 /* RCTUIManagerUtils.m in Sources */, 599FAA4D1FB274980058CCF6 /* RCTSurfaceView.mm in Sources */, - 59EDBCB41FDF4E0C003573DE /* RCTScrollContentViewManager.m in Sources */, + 59EDBCB41FDF4E0C003573DE /* (null) in Sources */, 2D3B5EA01D9B08B200451313 /* RCTLog.mm in Sources */, 5960C1BC1F0804A00066FD5B /* RCTLayoutAnimationGroup.m in Sources */, 2D3B5ECF1D9B096F00451313 /* RCTFont.mm in Sources */, @@ -4154,7 +4158,7 @@ 2D3B5E941D9B087900451313 /* RCTBundleURLProvider.m in Sources */, 2D3B5EB81D9B091B00451313 /* RCTSourceCode.m in Sources */, 2D3B5EB51D9B091100451313 /* RCTDevMenu.m in Sources */, - 59EDBCAC1FDF4E0C003573DE /* RCTScrollContentShadowView.m in Sources */, + 59EDBCAC1FDF4E0C003573DE /* (null) in Sources */, 2D3B5EBD1D9B092A00451313 /* RCTTiming.m in Sources */, 135A9C041E7B0F6400587AEB /* RCTJSCErrorHandling.mm in Sources */, 2D3B5EA81D9B08D300451313 /* RCTUtils.m in Sources */, @@ -4195,7 +4199,6 @@ 2D3B5EC11D9B093900451313 /* RCTFPSGraph.m in Sources */, 2D3B5E9A1D9B089D00451313 /* RCTEventDispatcher.m in Sources */, 2D3B5ED61D9B098400451313 /* RCTModalHostViewManager.m in Sources */, - 2D3B5EE51D9B09BE00451313 /* RCTShadowView.m in Sources */, 135A9C051E7B0F7500587AEB /* RCTJSCHelpers.mm in Sources */, 2D3B5EC71D9B095600451313 /* RCTActivityIndicatorView.m in Sources */, 2D3B5EB21D9B090300451313 /* RCTAsyncLocalStorage.m in Sources */, @@ -4247,6 +4250,7 @@ buildActionMask = 2147483647; files = ( 53D123A01FBF1EFF001B8A10 /* Yoga.cpp in Sources */, + 53EC85E21FDEC75F0051B2B5 /* YGNode.cpp in Sources */, 53D1239A1FBF1EF2001B8A10 /* YGEnums.cpp in Sources */, 5376C5E41FC6DDBC0083513D /* YGNodePrint.cpp in Sources */, ); @@ -4257,6 +4261,7 @@ buildActionMask = 2147483647; files = ( 53D123A11FBF1EFF001B8A10 /* Yoga.cpp in Sources */, + 53EC85E31FDEC75F0051B2B5 /* YGNode.cpp in Sources */, 53D1239B1FBF1EF4001B8A10 /* YGEnums.cpp in Sources */, 5376C5E51FC6DDBD0083513D /* YGNodePrint.cpp in Sources */, ); @@ -4364,7 +4369,7 @@ 13A0C28A1B74F71200B29F6F /* RCTDevMenu.m in Sources */, 13BCE8091C99CB9D00DD7AAD /* RCTRootShadowView.m in Sources */, 006FC4141D9B20820057AAAD /* RCTMultipartDataTask.m in Sources */, - 59EDBCB31FDF4E0C003573DE /* RCTScrollContentViewManager.m in Sources */, + 59EDBCB31FDF4E0C003573DE /* (null) in Sources */, 13CC8A821B17642100940AE7 /* RCTBorderDrawing.m in Sources */, C60128AD1F3D1258009DF9FF /* RCTCxxConvert.m in Sources */, 83CBBA511A601E3B00E9B192 /* RCTAssert.m in Sources */, @@ -4402,7 +4407,7 @@ 3D37B5821D522B190042D5B5 /* RCTFont.mm in Sources */, 137327EA1AA5CF210034F82E /* RCTTabBarManager.m in Sources */, 59EDBCB71FDF4E0C003573DE /* RCTScrollView.m in Sources */, - 59EDBCAB1FDF4E0C003573DE /* RCTScrollContentShadowView.m in Sources */, + 59EDBCAB1FDF4E0C003573DE /* (null) in Sources */, 59EDBCBB1FDF4E0C003573DE /* RCTScrollViewManager.m in Sources */, 369123E11DDC75850095B341 /* RCTJSCSamplingProfiler.m in Sources */, 599FAA441FB274980058CCF6 /* RCTSurfaceRootView.mm in Sources */, @@ -4447,12 +4452,12 @@ 13C156051AB1A2840079392D /* RCTWebView.m in Sources */, 83CBBA601A601EAA00E9B192 /* RCTBridge.m in Sources */, 590D7BFF1EBD458B00D8A370 /* RCTShadowView+Layout.m in Sources */, + 5335D5411FE81A4700883D58 /* RCTShadowView.m in Sources */, 66CD94B31F1045E700CB3C7C /* RCTMaskedView.m in Sources */, 13C156061AB1A2840079392D /* RCTWebViewManager.m in Sources */, 58114A161AAE854800E7D092 /* RCTPicker.m in Sources */, 137327E81AA5CF210034F82E /* RCTTabBarItem.m in Sources */, 83A1FE8C1B62640A00BE0E65 /* RCTModalHostView.m in Sources */, - 13E067551A70F44B002CDEE1 /* RCTShadowView.m in Sources */, 9936F3371F5F2F480010BF04 /* PrivateDataBase.cpp in Sources */, 1450FF871BCFF28A00208362 /* RCTProfileTrampoline-arm.S in Sources */, 131B6AF51AF1093D00FFC3E0 /* RCTSegmentedControlManager.m in Sources */, @@ -4461,6 +4466,7 @@ 657734911EE8354A00A0E9EA /* RCTInspectorPackagerConnection.m in Sources */, 68EFE4EE1CF6EB3900A1DE13 /* RCTBundleURLProvider.m in Sources */, B95154321D1B34B200FE7B80 /* RCTActivityIndicatorView.m in Sources */, + 534D3F811FE7E277002E5E0D /* YGNode.cpp in Sources */, 5960C1BB1F0804A00066FD5B /* RCTLayoutAnimationGroup.m in Sources */, 13B0801A1A69489C00A75B9A /* RCTNavigator.m in Sources */, 137327E71AA5CF210034F82E /* RCTTabBar.m in Sources */, diff --git a/React/Views/RCTShadowView.m b/React/Views/RCTShadowView.m index ee4617278fe53c..b86bf176f56f18 100644 --- a/React/Views/RCTShadowView.m +++ b/React/Views/RCTShadowView.m @@ -10,11 +10,11 @@ #import "RCTShadowView.h" #import "RCTConvert.h" +#import "RCTI18nUtil.h" #import "RCTLog.h" #import "RCTUtils.h" #import "UIView+Private.h" #import "UIView+React.h" -#import "RCTI18nUtil.h" typedef void (^RCTActionBlock)(RCTShadowView *shadowViewSelf, id value); typedef void (^RCTResetActionBlock)(RCTShadowView *shadowViewSelf); @@ -369,8 +369,8 @@ - (instancetype)init _reactSubviews = [NSMutableArray array]; _yogaNode = YGNodeNewWithConfig([[self class] yogaConfig]); - YGNodeSetContext(_yogaNode, (__bridge void *)self); - YGNodeSetPrintFunc(_yogaNode, RCTPrint); + YGNodeSetContext(_yogaNode, (__bridge void *)self); + YGNodeSetPrintFunc(_yogaNode, RCTPrint); } return self; } diff --git a/ReactAndroid/src/main/jni/first-party/yogajni/jni/YGJNI.cpp b/ReactAndroid/src/main/jni/first-party/yogajni/jni/YGJNI.cpp index df0398833198e1..a7676a97a3bcd0 100644 --- a/ReactAndroid/src/main/jni/first-party/yogajni/jni/YGJNI.cpp +++ b/ReactAndroid/src/main/jni/first-party/yogajni/jni/YGJNI.cpp @@ -8,8 +8,9 @@ */ #include -#include +#include #include +#include using namespace facebook::jni; using namespace std; @@ -19,7 +20,7 @@ struct JYogaNode : public JavaClass { }; static inline weak_ref *YGNodeJobject(YGNodeRef node) { - return reinterpret_cast *>(YGNodeGetContext(node)); + return reinterpret_cast*>(node->getContext()); } static void YGTransferLayoutDirection(YGNodeRef node, alias_ref javaNode) { @@ -28,7 +29,7 @@ static void YGTransferLayoutDirection(YGNodeRef node, alias_ref javaNod } static void YGTransferLayoutOutputsRecursive(YGNodeRef root) { - if (YGNodeGetHasNewLayout(root)) { + if (root->getHasNewLayout()) { if (auto obj = YGNodeJobject(root)->lockLocal()) { static auto widthField = obj->getClass()->getField("mWidth"); static auto heightField = obj->getClass()->getField("mHeight"); @@ -88,7 +89,7 @@ static void YGTransferLayoutOutputsRecursive(YGNodeRef root) { obj->setFieldValue(hasNewLayoutField, true); YGTransferLayoutDirection(root, obj); - YGNodeSetHasNewLayout(root, false); + root->setHasNewLayout(false); for (uint32_t i = 0; i < YGNodeGetChildCount(root); i++) { YGTransferLayoutOutputsRecursive(YGNodeGetChild(root, i)); @@ -188,15 +189,17 @@ static inline YGConfigRef _jlong2YGConfigRef(jlong addr) { jlong jni_YGNodeNew(alias_ref thiz) { const YGNodeRef node = YGNodeNew(); - YGNodeSetContext(node, new weak_ref(make_weak(thiz))); - YGNodeSetPrintFunc(node, YGPrint); + node->setContext(new weak_ref(make_weak(thiz))); + // YGNodeSetContext(node, new weak_ref(make_weak(thiz))); + node->setPrintFunc(YGPrint); + // YGNodeSetPrintFunc(node, YGPrint); return reinterpret_cast(node); } jlong jni_YGNodeNewWithConfig(alias_ref thiz, jlong configPointer) { const YGNodeRef node = YGNodeNewWithConfig(_jlong2YGConfigRef(configPointer)); - YGNodeSetContext(node, new weak_ref(make_weak(thiz))); - YGNodeSetPrintFunc(node, YGPrint); + node->setContext(new weak_ref(make_weak(thiz))); + node->setPrintFunc(YGPrint); return reinterpret_cast(node); } @@ -208,10 +211,10 @@ void jni_YGNodeFree(alias_ref thiz, jlong nativePointer) { void jni_YGNodeReset(alias_ref thiz, jlong nativePointer) { const YGNodeRef node = _jlong2YGNodeRef(nativePointer); - void *context = YGNodeGetContext(node); + void* context = node->getContext(); YGNodeReset(node); - YGNodeSetContext(node, context); - YGNodeSetPrintFunc(node, YGPrint); + node->setContext(context); + node->setPrintFunc(YGPrint); } void jni_YGNodePrint(alias_ref thiz, jlong nativePointer) { @@ -246,18 +249,19 @@ void jni_YGNodeMarkDirty(alias_ref, jlong nativePointer) { } jboolean jni_YGNodeIsDirty(alias_ref, jlong nativePointer) { - return (jboolean) YGNodeIsDirty(_jlong2YGNodeRef(nativePointer)); + return (jboolean)_jlong2YGNodeRef(nativePointer)->isDirty(); } void jni_YGNodeSetHasMeasureFunc(alias_ref, jlong nativePointer, jboolean hasMeasureFunc) { - YGNodeSetMeasureFunc(_jlong2YGNodeRef(nativePointer), hasMeasureFunc ? YGJNIMeasureFunc : NULL); + _jlong2YGNodeRef(nativePointer) + ->setMeasureFunc(hasMeasureFunc ? YGJNIMeasureFunc : nullptr); } void jni_YGNodeSetHasBaselineFunc(alias_ref, jlong nativePointer, jboolean hasBaselineFunc) { - YGNodeSetBaselineFunc(_jlong2YGNodeRef(nativePointer), - hasBaselineFunc ? YGJNIBaselineFunc : NULL); + _jlong2YGNodeRef(nativePointer) + ->setBaseLineFunc(hasBaselineFunc ? YGJNIBaselineFunc : nullptr); } void jni_YGNodeCopyStyle(alias_ref, jlong dstNativePointer, jlong srcNativePointer) { diff --git a/ReactCommon/yoga/yoga/YGNode.cpp b/ReactCommon/yoga/yoga/YGNode.cpp new file mode 100644 index 00000000000000..70f0f46ab6106a --- /dev/null +++ b/ReactCommon/yoga/yoga/YGNode.cpp @@ -0,0 +1,399 @@ +/** + * Copyright (c) 2014-present, Facebook, Inc. + * All rights reserved. + * + * This source code is licensed under the BSD-style license found in the + * LICENSE file in the root directory of this source tree. An additional grant + * of patent rights can be found in the PATENTS file in the same directory. + */ + +#include "YGNode.h" +#include + +void* YGNode::getContext() const { + return context_; +} + +YGPrintFunc YGNode::getPrintFunc() const { + return print_; +} + +bool YGNode::getHasNewLayout() const { + return hasNewLayout_; +} + +YGNodeType YGNode::getNodeType() const { + return nodeType_; +} + +YGMeasureFunc YGNode::getMeasure() const { + return measure_; +} + +YGBaselineFunc YGNode::getBaseline() const { + return baseline_; +} + +YGStyle YGNode::getStyle() const { + return style_; +} + +YGLayout YGNode::getLayout() const { + return layout_; +} + +YGLayout& YGNode::getLayoutRef() { + return layout_; +} + +uint32_t YGNode::getLineIndex() const { + return lineIndex_; +} + +YGNodeRef YGNode::getParent() const { + return parent_; +} + +YGVector YGNode::getChildren() const { + return children_; +} + +YGNodeRef YGNode::getChild(uint32_t index) const { + return children_.at(index); +} + +YGNodeRef YGNode::getNextChild() const { + return nextChild_; +} + +YGConfigRef YGNode::getConfig() const { + return config_; +} + +bool YGNode::isDirty() const { + return isDirty_; +} + +YGValue YGNode::getResolvedDimension(int index) { + return resolvedDimensions_[index]; +} + +std::array YGNode::getResolvedDimensions() const { + return resolvedDimensions_; +} +// Setters + +void YGNode::setContext(void* context) { + context_ = context; +} + +void YGNode::setPrintFunc(YGPrintFunc printFunc) { + print_ = printFunc; +} + +void YGNode::setHasNewLayout(bool hasNewLayout) { + hasNewLayout_ = hasNewLayout; +} + +void YGNode::setNodeType(YGNodeType nodeType) { + nodeType_ = nodeType; +} + +void YGNode::setStyleFlexDirection(YGFlexDirection direction) { + style_.flexDirection = direction; +} + +void YGNode::setStyleAlignContent(YGAlign alignContent) { + style_.alignContent = alignContent; +} + +void YGNode::setMeasureFunc(YGMeasureFunc measureFunc) { + if (measureFunc == nullptr) { + measure_ = nullptr; + // TODO: t18095186 Move nodeType to opt-in function and mark appropriate + // places in Litho + nodeType_ = YGNodeTypeDefault; + } else { + YGAssertWithNode( + this, + children_.size() == 0, + "Cannot set measure function: Nodes with measure functions cannot have children."); + measure_ = measureFunc; + // TODO: t18095186 Move nodeType to opt-in function and mark appropriate + // places in Litho + setNodeType(YGNodeTypeText); + } + + measure_ = measureFunc; +} + +void YGNode::setBaseLineFunc(YGBaselineFunc baseLineFunc) { + baseline_ = baseLineFunc; +} + +void YGNode::setStyle(YGStyle style) { + style_ = style; +} + +void YGNode::setLayout(YGLayout layout) { + layout_ = layout; +} + +void YGNode::setLineIndex(uint32_t lineIndex) { + lineIndex_ = lineIndex; +} + +void YGNode::setParent(YGNodeRef parent) { + parent_ = parent; +} + +void YGNode::setChildren(YGVector children) { + children_ = children; +} + +void YGNode::setNextChild(YGNodeRef nextChild) { + nextChild_ = nextChild; +} + +void YGNode::replaceChild(YGNodeRef child, uint32_t index) { + children_[index] = child; +} + +void YGNode::insertChild(YGNodeRef child, uint32_t index) { + children_.insert(children_.begin() + index, child); +} + +void YGNode::setConfig(YGConfigRef config) { + config_ = config; +} + +void YGNode::setDirty(bool isDirty) { + isDirty_ = isDirty; +} + +bool YGNode::removeChild(YGNodeRef child) { + std::vector::iterator p = + std::find(children_.begin(), children_.end(), child); + if (p != children_.end()) { + children_.erase(p); + return true; + } + return false; +} + +void YGNode::removeChild(uint32_t index) { + children_.erase(children_.begin() + index); +} + +void YGNode::setLayoutDirection(YGDirection direction) { + layout_.direction = direction; +} + +void YGNode::setLayoutMargin(float margin, int index) { + layout_.margin[index] = margin; +} + +void YGNode::setLayoutBorder(float border, int index) { + layout_.border[index] = border; +} + +void YGNode::setLayoutPadding(float padding, int index) { + layout_.padding[index] = padding; +} + +void YGNode::setLayoutLastParentDirection(YGDirection direction) { + layout_.lastParentDirection = direction; +} + +void YGNode::setLayoutComputedFlexBasis(float computedFlexBasis) { + layout_.computedFlexBasis = computedFlexBasis; +} + +void YGNode::setLayoutPosition(float position, int index) { + layout_.position[index] = position; +} + +void YGNode::setLayoutComputedFlexBasisGeneration( + uint32_t computedFlexBasisGeneration) { + layout_.computedFlexBasisGeneration = computedFlexBasisGeneration; +} + +void YGNode::setLayoutMeasuredDimension(float measuredDimension, int index) { + layout_.measuredDimensions[index] = measuredDimension; +} + +void YGNode::setLayoutHadOverflow(bool hadOverflow) { + layout_.hadOverflow = hadOverflow; +} + +void YGNode::setLayoutDimension(float dimension, int index) { + layout_.dimensions[index] = dimension; +} + +YGNode::YGNode() + : context_(nullptr), + print_(nullptr), + hasNewLayout_(true), + nodeType_(YGNodeTypeDefault), + measure_(nullptr), + baseline_(nullptr), + style_(gYGNodeStyleDefaults), + layout_(gYGNodeLayoutDefaults), + lineIndex_(0), + parent_(nullptr), + children_(YGVector()), + nextChild_(nullptr), + config_(nullptr), + isDirty_(false), + resolvedDimensions_({{YGValueUndefined, YGValueUndefined}}) {} + +YGNode::YGNode(const YGNode& node) + : context_(node.getContext()), + print_(node.getPrintFunc()), + hasNewLayout_(node.getHasNewLayout()), + nodeType_(node.getNodeType()), + measure_(node.getMeasure()), + baseline_(node.getBaseline()), + style_(node.getStyle()), + layout_(node.getLayout()), + lineIndex_(node.getLineIndex()), + parent_(node.getParent()), + children_(node.getChildren()), + nextChild_(node.getNextChild()), + config_(node.getConfig()), + isDirty_(node.isDirty()), + resolvedDimensions_(node.getResolvedDimensions()) {} + +YGNode::YGNode(const YGConfigRef newConfig) : YGNode() { + config_ = newConfig; +} + +YGNode::YGNode( + void* context, + YGPrintFunc print, + bool hasNewLayout, + YGNodeType nodeType, + YGMeasureFunc measure, + YGBaselineFunc baseline, + YGStyle style, + YGLayout layout, + uint32_t lineIndex, + YGNodeRef parent, + YGVector children, + YGNodeRef nextChild, + YGConfigRef config, + bool isDirty, + std::array resolvedDimensions) + : context_(context), + print_(print), + hasNewLayout_(hasNewLayout), + nodeType_(nodeType), + measure_(measure), + baseline_(baseline), + style_(style), + layout_(layout), + lineIndex_(lineIndex), + parent_(parent), + children_(children), + nextChild_(nextChild), + config_(config), + isDirty_(isDirty), + resolvedDimensions_(resolvedDimensions) {} + +YGNode& YGNode::operator=(const YGNode& node) { + if (&node == this) { + return *this; + } + + for (auto child : children_) { + delete child; + } + + context_ = node.getContext(); + print_ = node.getPrintFunc(); + hasNewLayout_ = node.getHasNewLayout(); + nodeType_ = node.getNodeType(); + measure_ = node.getMeasure(); + baseline_ = node.getBaseline(); + style_ = node.getStyle(); + layout_ = node.getLayout(); + lineIndex_ = node.getLineIndex(); + parent_ = node.getParent(); + children_ = node.getChildren(); + nextChild_ = node.getNextChild(); + config_ = node.getConfig(); + isDirty_ = node.isDirty(); + resolvedDimensions_ = node.getResolvedDimensions(); + + return *this; +} + +YGValue YGNode::marginLeadingValue(const YGFlexDirection axis) const { + if (YGFlexDirectionIsRow(axis) && + getStyle().margin[YGEdgeStart].unit != YGUnitUndefined) { + return getStyle().margin[YGEdgeStart]; + } else { + return getStyle().margin[leading[axis]]; + } +} + +YGValue YGNode::marginTrailingValue(const YGFlexDirection axis) const { + if (YGFlexDirectionIsRow(axis) && + getStyle().margin[YGEdgeEnd].unit != YGUnitUndefined) { + return getStyle().margin[YGEdgeEnd]; + } else { + return getStyle().margin[trailing[axis]]; + } +} + +YGValue YGNode::resolveFlexBasisPtr() const { + YGValue flexBasis = getStyle().flexBasis; + if (flexBasis.unit != YGUnitAuto && flexBasis.unit != YGUnitUndefined) { + return flexBasis; + } + if (!YGFloatIsUndefined(getStyle().flex) && getStyle().flex > 0.0f) { + return config_->useWebDefaults ? YGValueAuto : YGValueZero; + } + return YGValueAuto; +} + +void YGNode::resolveDimension() { + for (uint32_t dim = YGDimensionWidth; dim < YGDimensionCount; dim++) { + if (getStyle().maxDimensions[dim].unit != YGUnitUndefined && + YGValueEqual( + getStyle().maxDimensions[dim], getStyle().minDimensions[dim])) { + resolvedDimensions_[dim] = getStyle().maxDimensions[dim]; + } else { + resolvedDimensions_[dim] = getStyle().dimensions[dim]; + } + } +} + +void YGNode::clearChildren() { + children_.clear(); + children_.shrink_to_fit(); +} + +YGNode::~YGNode() { + // All the member variables are deallocated externally, so no need to + // deallocate here +} + +const YGNode& YGNode::defaultValue() { + static const YGNode n = {nullptr, + nullptr, + true, + YGNodeTypeDefault, + nullptr, + nullptr, + gYGNodeStyleDefaults, + gYGNodeLayoutDefaults, + 0, + nullptr, + YGVector(), + nullptr, + nullptr, + false, + {{YGValueUndefined, YGValueUndefined}}}; + return n; +} diff --git a/ReactCommon/yoga/yoga/YGNode.h b/ReactCommon/yoga/yoga/YGNode.h new file mode 100644 index 00000000000000..a5062bdb850211 --- /dev/null +++ b/ReactCommon/yoga/yoga/YGNode.h @@ -0,0 +1,121 @@ +/** + * Copyright (c) 2014-present, Facebook, Inc. + * All rights reserved. + * + * This source code is licensed under the BSD-style license found in the + * LICENSE file in the root directory of this source tree. An additional grant + * of patent rights can be found in the PATENTS file in the same directory. + */ + +#pragma once +#include + +#include "Yoga-internal.h" + +struct YGNode { + private: + void* context_; + YGPrintFunc print_; + bool hasNewLayout_; + YGNodeType nodeType_; + YGMeasureFunc measure_; + YGBaselineFunc baseline_; + YGStyle style_; + YGLayout layout_; + uint32_t lineIndex_; + YGNodeRef parent_; + YGVector children_; + YGNodeRef nextChild_; + YGConfigRef config_; + bool isDirty_; + std::array resolvedDimensions_; + + public: + YGNode(); + ~YGNode(); + explicit YGNode(const YGConfigRef newConfig); + YGNode(const YGNode& node); + YGNode& operator=(const YGNode& node); + YGNode( + void* context, + YGPrintFunc print, + bool hasNewLayout, + YGNodeType nodeType, + YGMeasureFunc measure, + YGBaselineFunc baseline, + YGStyle style, + YGLayout layout, + uint32_t lineIndex, + YGNodeRef parent, + YGVector children, + YGNodeRef nextChild, + YGConfigRef config, + bool isDirty, + std::array resolvedDimensions); + + // Getters + void* getContext() const; + YGPrintFunc getPrintFunc() const; + bool getHasNewLayout() const; + YGNodeType getNodeType() const; + YGMeasureFunc getMeasure() const; + YGBaselineFunc getBaseline() const; + YGStyle getStyle() const; + YGLayout getLayout() const; + YGLayout& getLayoutRef(); // TODO remove its use + uint32_t getLineIndex() const; + YGNodeRef getParent() const; + YGVector getChildren() const; + YGNodeRef getChild(uint32_t index) const; + YGNodeRef getNextChild() const; + YGConfigRef getConfig() const; + bool isDirty() const; + std::array getResolvedDimensions() const; + YGValue getResolvedDimension(int index); + + // Setters + + void setContext(void* context); + void setPrintFunc(YGPrintFunc printFunc); + void setHasNewLayout(bool hasNewLayout); + void setNodeType(YGNodeType nodeTye); + void setMeasureFunc(YGMeasureFunc measureFunc); + void setBaseLineFunc(YGBaselineFunc baseLineFunc); + void setStyle(YGStyle style); + void setStyleFlexDirection(YGFlexDirection direction); + void setStyleAlignContent(YGAlign alignContent); + void setLayout(YGLayout layout); + void setLineIndex(uint32_t lineIndex); + void setParent(YGNodeRef parent); + void setChildren(YGVector children); + void setNextChild(YGNodeRef nextChild); + void setConfig(YGConfigRef config); + void setDirty(bool isDirty); + void setLayoutLastParentDirection(YGDirection direction); + void setLayoutComputedFlexBasis(float computedFlexBasis); + void setLayoutComputedFlexBasisGeneration( + uint32_t computedFlexBasisGeneration); + void setLayoutMeasuredDimension(float measuredDimension, int index); + void setLayoutHadOverflow(bool hadOverflow); + void setLayoutDimension(float dimension, int index); + + // Other methods + YGValue marginLeadingValue(const YGFlexDirection axis) const; + YGValue marginTrailingValue(const YGFlexDirection axis) const; + YGValue resolveFlexBasisPtr() const; + void resolveDimension(); + void clearChildren(); + void replaceChild(YGNodeRef child, uint32_t index); + void insertChild(YGNodeRef child, uint32_t index); + /// Removes the first occurrence of child + bool removeChild(YGNodeRef child); + void removeChild(uint32_t index); + void setLayoutDirection(YGDirection direction); + void setLayoutMargin(float margin, int index); + void setLayoutBorder(float border, int index); + void setLayoutPadding(float padding, int index); + void setLayoutPosition(float position, int index); + + // Static methods + static const YGNode& defaultValue(); +}; diff --git a/ReactCommon/yoga/yoga/YGNodePrint.cpp b/ReactCommon/yoga/yoga/YGNodePrint.cpp index 7ab673f444dac1..e49903acc92328 100644 --- a/ReactCommon/yoga/yoga/YGNodePrint.cpp +++ b/ReactCommon/yoga/yoga/YGNodePrint.cpp @@ -10,6 +10,7 @@ #include "YGNodePrint.h" #include #include "YGEnums.h" +#include "YGNode.h" #include "Yoga-internal.h" namespace facebook { @@ -22,7 +23,7 @@ static void indent(string* base, uint32_t level) { } } -static bool areFourValuesEqual(const YGValue four[4]) { +static bool areFourValuesEqual(const std::array& four) { return YGValueEqual(four[0], four[1]) && YGValueEqual(four[0], four[2]) && YGValueEqual(four[0], four[3]); } @@ -50,54 +51,53 @@ appendFloatIfNotUndefined(string* base, const string key, const float num) { static void appendNumberIfNotUndefined( string* base, const string key, - const YGValue* const number) { - if (number->unit != YGUnitUndefined) { - if (number->unit == YGUnitAuto) { + const YGValue number) { + if (number.unit != YGUnitUndefined) { + if (number.unit == YGUnitAuto) { base->append(key + ": auto; "); } else { - string unit = number->unit == YGUnitPoint ? "px" : "%%"; + string unit = number.unit == YGUnitPoint ? "px" : "%%"; appendFormatedString( - base, "%s: %g%s; ", key.c_str(), number->value, unit.c_str()); + base, "%s: %g%s; ", key.c_str(), number.value, unit.c_str()); } } } -static void appendNumberIfNotAuto( - string* base, - const string key, - const YGValue* const number) { - if (number->unit != YGUnitAuto) { +static void +appendNumberIfNotAuto(string* base, const string& key, const YGValue number) { + if (number.unit != YGUnitAuto) { appendNumberIfNotUndefined(base, key, number); } } -static void appendNumberIfNotZero( - string* base, - const string str, - const YGValue* const number) { - if (!YGFloatsEqual(number->value, 0)) { +static void +appendNumberIfNotZero(string* base, const string& str, const YGValue number) { + if (!YGFloatsEqual(number.value, 0)) { appendNumberIfNotUndefined(base, str, number); } } -static void appendEdges(string* base, const string key, const YGValue* edges) { +static void appendEdges( + string* base, + const string& key, + const std::array& edges) { if (areFourValuesEqual(edges)) { - appendNumberIfNotZero(base, key, &edges[YGEdgeLeft]); + appendNumberIfNotZero(base, key, edges[YGEdgeLeft]); } else { for (int edge = YGEdgeLeft; edge != YGEdgeAll; ++edge) { string str = key + "-" + YGEdgeToString(static_cast(edge)); - appendNumberIfNotZero(base, str, &edges[edge]); + appendNumberIfNotZero(base, str, edges[edge]); } } } static void appendEdgeIfNotUndefined( string* base, - const string str, - const YGValue* edges, + const string& str, + const std::array& edges, const YGEdge edge) { appendNumberIfNotUndefined( - base, str, YGComputedEdgeValue(edges, edge, &YGValueUndefined)); + base, str, *YGComputedEdgeValue(edges, edge, &YGValueUndefined)); } void YGNodeToString( @@ -107,105 +107,112 @@ void YGNodeToString( uint32_t level) { indent(str, level); appendFormatedString(str, "
print != nullptr) { - node->print(node); + if (node->getPrintFunc() != nullptr) { + node->getPrintFunc()(node); } if (options & YGPrintOptionsLayout) { appendFormatedString(str, "layout=\""); appendFormatedString( - str, "width: %g; ", node->layout.dimensions[YGDimensionWidth]); + str, "width: %g; ", node->getLayout().dimensions[YGDimensionWidth]); + appendFormatedString( + str, "height: %g; ", node->getLayout().dimensions[YGDimensionHeight]); appendFormatedString( - str, "height: %g; ", node->layout.dimensions[YGDimensionHeight]); - appendFormatedString(str, "top: %g; ", node->layout.position[YGEdgeTop]); - appendFormatedString(str, "left: %g;", node->layout.position[YGEdgeLeft]); + str, "top: %g; ", node->getLayout().position[YGEdgeTop]); + appendFormatedString( + str, "left: %g;", node->getLayout().position[YGEdgeLeft]); appendFormatedString(str, "\" "); } if (options & YGPrintOptionsStyle) { appendFormatedString(str, "style=\""); - if (node->style.flexDirection != gYGNodeDefaults.style.flexDirection) { + if (node->getStyle().flexDirection != YGNode().getStyle().flexDirection) { appendFormatedString( str, "flex-direction: %s; ", - YGFlexDirectionToString(node->style.flexDirection)); + YGFlexDirectionToString(node->getStyle().flexDirection)); } - if (node->style.justifyContent != gYGNodeDefaults.style.justifyContent) { + if (node->getStyle().justifyContent != YGNode().getStyle().justifyContent) { appendFormatedString( str, "justify-content: %s; ", - YGJustifyToString(node->style.justifyContent)); + YGJustifyToString(node->getStyle().justifyContent)); } - if (node->style.alignItems != gYGNodeDefaults.style.alignItems) { + if (node->getStyle().alignItems != YGNode().getStyle().alignItems) { appendFormatedString( - str, "align-items: %s; ", YGAlignToString(node->style.alignItems)); + str, + "align-items: %s; ", + YGAlignToString(node->getStyle().alignItems)); } - if (node->style.alignContent != gYGNodeDefaults.style.alignContent) { + if (node->getStyle().alignContent != YGNode().getStyle().alignContent) { appendFormatedString( str, "align-content: %s; ", - YGAlignToString(node->style.alignContent)); + YGAlignToString(node->getStyle().alignContent)); } - if (node->style.alignSelf != gYGNodeDefaults.style.alignSelf) { + if (node->getStyle().alignSelf != YGNode().getStyle().alignSelf) { appendFormatedString( - str, "align-self: %s; ", YGAlignToString(node->style.alignSelf)); + str, "align-self: %s; ", YGAlignToString(node->getStyle().alignSelf)); } - appendFloatIfNotUndefined(str, "flex-grow", node->style.flexGrow); - appendFloatIfNotUndefined(str, "flex-shrink", node->style.flexShrink); - appendNumberIfNotAuto(str, "flex-basis", &node->style.flexBasis); - appendFloatIfNotUndefined(str, "flex", node->style.flex); + appendFloatIfNotUndefined(str, "flex-grow", node->getStyle().flexGrow); + appendFloatIfNotUndefined(str, "flex-shrink", node->getStyle().flexShrink); + appendNumberIfNotAuto(str, "flex-basis", node->getStyle().flexBasis); + appendFloatIfNotUndefined(str, "flex", node->getStyle().flex); - if (node->style.flexWrap != gYGNodeDefaults.style.flexWrap) { + if (node->getStyle().flexWrap != YGNode().getStyle().flexWrap) { appendFormatedString( - str, "flexWrap: %s; ", YGWrapToString(node->style.flexWrap)); + str, "flexWrap: %s; ", YGWrapToString(node->getStyle().flexWrap)); } - if (node->style.overflow != gYGNodeDefaults.style.overflow) { + if (node->getStyle().overflow != YGNode().getStyle().overflow) { appendFormatedString( - str, "overflow: %s; ", YGOverflowToString(node->style.overflow)); + str, "overflow: %s; ", YGOverflowToString(node->getStyle().overflow)); } - if (node->style.display != gYGNodeDefaults.style.display) { + if (node->getStyle().display != YGNode().getStyle().display) { appendFormatedString( - str, "display: %s; ", YGDisplayToString(node->style.display)); + str, "display: %s; ", YGDisplayToString(node->getStyle().display)); } - appendEdges(str, "margin", node->style.margin); - appendEdges(str, "padding", node->style.padding); - appendEdges(str, "border", node->style.border); + appendEdges(str, "margin", node->getStyle().margin); + appendEdges(str, "padding", node->getStyle().padding); + appendEdges(str, "border", node->getStyle().border); appendNumberIfNotAuto( - str, "width", &node->style.dimensions[YGDimensionWidth]); + str, "width", node->getStyle().dimensions[YGDimensionWidth]); appendNumberIfNotAuto( - str, "height", &node->style.dimensions[YGDimensionHeight]); + str, "height", node->getStyle().dimensions[YGDimensionHeight]); appendNumberIfNotAuto( - str, "max-width", &node->style.maxDimensions[YGDimensionWidth]); + str, "max-width", node->getStyle().maxDimensions[YGDimensionWidth]); appendNumberIfNotAuto( - str, "max-height", &node->style.maxDimensions[YGDimensionHeight]); + str, "max-height", node->getStyle().maxDimensions[YGDimensionHeight]); appendNumberIfNotAuto( - str, "min-width", &node->style.minDimensions[YGDimensionWidth]); + str, "min-width", node->getStyle().minDimensions[YGDimensionWidth]); appendNumberIfNotAuto( - str, "min-height", &node->style.minDimensions[YGDimensionHeight]); + str, "min-height", node->getStyle().minDimensions[YGDimensionHeight]); - if (node->style.positionType != gYGNodeDefaults.style.positionType) { + if (node->getStyle().positionType != YGNode().getStyle().positionType) { appendFormatedString( str, "position: %s; ", - YGPositionTypeToString(node->style.positionType)); + YGPositionTypeToString(node->getStyle().positionType)); } - appendEdgeIfNotUndefined(str, "left", node->style.position, YGEdgeLeft); - appendEdgeIfNotUndefined(str, "right", node->style.position, YGEdgeRight); - appendEdgeIfNotUndefined(str, "top", node->style.position, YGEdgeTop); - appendEdgeIfNotUndefined(str, "bottom", node->style.position, YGEdgeBottom); + appendEdgeIfNotUndefined( + str, "left", node->getStyle().position, YGEdgeLeft); + appendEdgeIfNotUndefined( + str, "right", node->getStyle().position, YGEdgeRight); + appendEdgeIfNotUndefined(str, "top", node->getStyle().position, YGEdgeTop); + appendEdgeIfNotUndefined( + str, "bottom", node->getStyle().position, YGEdgeBottom); appendFormatedString(str, "\" "); - if (node->measure != nullptr) { + if (node->getMeasure() != nullptr) { appendFormatedString(str, "has-custom-measure=\"true\""); } } appendFormatedString(str, ">"); - const uint32_t childCount = node->children.size(); + const uint32_t childCount = node->getChildren().size(); if (options & YGPrintOptionsChildren && childCount > 0) { for (uint32_t i = 0; i < childCount; i++) { appendFormatedString(str, "\n"); diff --git a/ReactCommon/yoga/yoga/Yoga-internal.h b/ReactCommon/yoga/yoga/Yoga-internal.h index 568cd9748cb1a0..1ea80704ada95a 100644 --- a/ReactCommon/yoga/yoga/Yoga-internal.h +++ b/ReactCommon/yoga/yoga/Yoga-internal.h @@ -8,6 +8,9 @@ */ #pragma once +#include +#include +#include #include #include "Yoga.h" @@ -23,6 +26,25 @@ WIN_EXPORT float YGRoundValueToPixelGrid(const float value, YG_EXTERN_C_END +extern const std::array trailing; +extern const std::array leading; +extern bool YGFlexDirectionIsRow(const YGFlexDirection flexDirection); +extern bool YGValueEqual(const YGValue a, const YGValue b); +extern const YGValue YGValueUndefined; +extern const YGValue YGValueAuto; +extern const YGValue YGValueZero; + +template +bool YGValueArrayEqual( + const std::array val1, + const std::array val2) { + bool areEqual = true; + for (uint32_t i = 0; i < size && areEqual; ++i) { + areEqual = YGValueEqual(val1[i], val2[i]); + } + return areEqual; +} + typedef struct YGCachedMeasurement { float availableWidth; float availableHeight; @@ -37,12 +59,12 @@ typedef struct YGCachedMeasurement { // layouts should not require more than 16 entries to fit within the cache. #define YG_MAX_CACHED_RESULT_COUNT 16 -typedef struct YGLayout { - float position[4]; - float dimensions[2]; - float margin[6]; - float border[6]; - float padding[6]; +struct YGLayout { + std::array position; + std::array dimensions; + std::array margin; + std::array border; + std::array padding; YGDirection direction; uint32_t computedFlexBasisGeneration; @@ -56,12 +78,12 @@ typedef struct YGLayout { uint32_t nextCachedMeasurementsIndex; YGCachedMeasurement cachedMeasurements[YG_MAX_CACHED_RESULT_COUNT]; - float measuredDimensions[2]; + std::array measuredDimensions; YGCachedMeasurement cachedLayout; -} YGLayout; +}; -typedef struct YGStyle { +struct YGStyle { YGDirection direction; YGFlexDirection flexDirection; YGJustify justifyContent; @@ -76,17 +98,58 @@ typedef struct YGStyle { float flexGrow; float flexShrink; YGValue flexBasis; - YGValue margin[YGEdgeCount]; - YGValue position[YGEdgeCount]; - YGValue padding[YGEdgeCount]; - YGValue border[YGEdgeCount]; - YGValue dimensions[2]; - YGValue minDimensions[2]; - YGValue maxDimensions[2]; + std::array margin; + std::array position; + std::array padding; + std::array border; + std::array dimensions; + std::array minDimensions; + std::array maxDimensions; // Yoga specific properties, not compatible with flexbox specification float aspectRatio; -} YGStyle; + bool operator==(YGStyle style) { + bool areNonFloatValuesEqual = direction == style.direction && + flexDirection == style.flexDirection && + justifyContent == style.justifyContent && + alignContent == style.alignContent && alignItems == style.alignItems && + alignSelf == style.alignSelf && positionType == style.positionType && + flexWrap == style.flexWrap && overflow == style.overflow && + display == style.display && YGValueEqual(flexBasis, style.flexBasis) && + YGValueArrayEqual(margin, style.margin) && + YGValueArrayEqual(position, style.position) && + YGValueArrayEqual(padding, style.padding) && + YGValueArrayEqual(border, style.border) && + YGValueArrayEqual(dimensions, style.dimensions) && + YGValueArrayEqual(minDimensions, style.minDimensions) && + YGValueArrayEqual(maxDimensions, style.maxDimensions); + + if (!(std::isnan(flex) && std::isnan(style.flex))) { + areNonFloatValuesEqual = areNonFloatValuesEqual && flex == style.flex; + } + + if (!(std::isnan(flexGrow) && std::isnan(style.flexGrow))) { + areNonFloatValuesEqual = + areNonFloatValuesEqual && flexGrow == style.flexGrow; + } + + if (!(std::isnan(flexShrink) && std::isnan(style.flexShrink))) { + areNonFloatValuesEqual = + areNonFloatValuesEqual && flexShrink == style.flexShrink; + } + + if (!(std::isnan(aspectRatio) && std::isnan(style.aspectRatio))) { + areNonFloatValuesEqual = + areNonFloatValuesEqual && aspectRatio == style.aspectRatio; + } + + return areNonFloatValuesEqual; + } + + bool operator!=(YGStyle style) { + return !(*this == style); + } +}; typedef struct YGConfig { bool experimentalFeatures[YGExperimentalFeatureCount + 1]; @@ -98,29 +161,6 @@ typedef struct YGConfig { void* context; } YGConfig; -typedef struct YGNode { - YGStyle style; - YGLayout layout; - uint32_t lineIndex; - - YGNodeRef parent; - YGVector children; - - struct YGNode* nextChild; - - YGMeasureFunc measure; - YGBaselineFunc baseline; - YGPrintFunc print; - YGConfigRef config; - void* context; - - bool isDirty; - bool hasNewLayout; - YGNodeType nodeType; - - YGValue const* resolvedDimensions[2]; -} YGNode; - #define YG_UNDEFINED_VALUES \ { .value = YGUndefined, .unit = YGUnitUndefined } @@ -167,19 +207,51 @@ static const YGStyle gYGNodeStyleDefaults = { .flexGrow = YGUndefined, .flexShrink = YGUndefined, .flexBasis = YG_AUTO_VALUES, - .margin = YG_DEFAULT_EDGE_VALUES_UNIT, - .position = YG_DEFAULT_EDGE_VALUES_UNIT, - .padding = YG_DEFAULT_EDGE_VALUES_UNIT, - .border = YG_DEFAULT_EDGE_VALUES_UNIT, - .dimensions = YG_DEFAULT_DIMENSION_VALUES_AUTO_UNIT, - .minDimensions = YG_DEFAULT_DIMENSION_VALUES_UNIT, - .maxDimensions = YG_DEFAULT_DIMENSION_VALUES_UNIT, + .margin = {{YG_UNDEFINED_VALUES, + YG_UNDEFINED_VALUES, + YG_UNDEFINED_VALUES, + YG_UNDEFINED_VALUES, + YG_UNDEFINED_VALUES, + YG_UNDEFINED_VALUES, + YG_UNDEFINED_VALUES, + YG_UNDEFINED_VALUES, + YG_UNDEFINED_VALUES}}, + .position = {{YG_UNDEFINED_VALUES, + YG_UNDEFINED_VALUES, + YG_UNDEFINED_VALUES, + YG_UNDEFINED_VALUES, + YG_UNDEFINED_VALUES, + YG_UNDEFINED_VALUES, + YG_UNDEFINED_VALUES, + YG_UNDEFINED_VALUES, + YG_UNDEFINED_VALUES}}, + .padding = {{YG_UNDEFINED_VALUES, + YG_UNDEFINED_VALUES, + YG_UNDEFINED_VALUES, + YG_UNDEFINED_VALUES, + YG_UNDEFINED_VALUES, + YG_UNDEFINED_VALUES, + YG_UNDEFINED_VALUES, + YG_UNDEFINED_VALUES, + YG_UNDEFINED_VALUES}}, + .border = {{YG_UNDEFINED_VALUES, + YG_UNDEFINED_VALUES, + YG_UNDEFINED_VALUES, + YG_UNDEFINED_VALUES, + YG_UNDEFINED_VALUES, + YG_UNDEFINED_VALUES, + YG_UNDEFINED_VALUES, + YG_UNDEFINED_VALUES, + YG_UNDEFINED_VALUES}}, + .dimensions = {{YG_AUTO_VALUES, YG_AUTO_VALUES}}, + .minDimensions = {{YG_UNDEFINED_VALUES, YG_UNDEFINED_VALUES}}, + .maxDimensions = {{YG_UNDEFINED_VALUES, YG_UNDEFINED_VALUES}}, .aspectRatio = YGUndefined, }; static const YGLayout gYGNodeLayoutDefaults = { .position = {}, - .dimensions = YG_DEFAULT_DIMENSION_VALUES, + .dimensions = {{YGUndefined, YGUndefined}}, .margin = {}, .border = {}, .padding = {}, @@ -191,7 +263,7 @@ static const YGLayout gYGNodeLayoutDefaults = { .lastParentDirection = (YGDirection)-1, .nextCachedMeasurementsIndex = 0, .cachedMeasurements = {}, - .measuredDimensions = YG_DEFAULT_DIMENSION_VALUES, + .measuredDimensions = {{YGUndefined, YGUndefined}}, .cachedLayout = { .availableWidth = 0, @@ -203,28 +275,9 @@ static const YGLayout gYGNodeLayoutDefaults = { }, }; -static const YGNode gYGNodeDefaults = { - .style = gYGNodeStyleDefaults, - .layout = gYGNodeLayoutDefaults, - .lineIndex = 0, - .parent = nullptr, - .children = YGVector(), - .nextChild = nullptr, - .measure = nullptr, - .baseline = nullptr, - .print = nullptr, - .config = nullptr, - .context = nullptr, - .isDirty = false, - .hasNewLayout = true, - .nodeType = YGNodeTypeDefault, - .resolvedDimensions = {[YGDimensionWidth] = &YGValueUndefined, - [YGDimensionHeight] = &YGValueUndefined}, -}; - extern bool YGFloatsEqual(const float a, const float b); extern bool YGValueEqual(const YGValue a, const YGValue b); extern const YGValue* YGComputedEdgeValue( - const YGValue edges[YGEdgeCount], + const std::array& edges, const YGEdge edge, const YGValue* const defaultValue); diff --git a/ReactCommon/yoga/yoga/Yoga.cpp b/ReactCommon/yoga/yoga/Yoga.cpp index 3ccd103c10bede..188354db85a988 100644 --- a/ReactCommon/yoga/yoga/Yoga.cpp +++ b/ReactCommon/yoga/yoga/Yoga.cpp @@ -10,17 +10,12 @@ #include "Yoga.h" #include #include +#include "YGNode.h" #include "YGNodePrint.h" #include "Yoga-internal.h" #ifdef _MSC_VER #include -#ifndef isnan -#define isnan _isnan -#endif -#ifndef __cplusplus -#define inline __inline -#endif /* define fmaxf if < VC12 */ #if _MSC_VER < 1800 @@ -61,19 +56,11 @@ static YGConfig gYGConfigDefaults = { .context = nullptr, }; -static void YGNodeMarkDirtyInternal(const YGNodeRef node); - -static YGValue YGValueZero = {.value = 0, .unit = YGUnitPoint}; +const YGValue YGValueZero = {.value = 0, .unit = YGUnitPoint}; +const YGValue YGValueUndefined = {YGUndefined, YGUnitUndefined}; +const YGValue YGValueAuto = {YGUndefined, YGUnitAuto}; -static bool YGNodeListDelete(YGVector& list, const YGNodeRef node) { - std::vector::iterator p = - std::find(list.begin(), list.end(), node); - if (p != list.end()) { - list.erase(p); - return true; - } - return false; -} +static void YGNodeMarkDirtyInternal(const YGNodeRef node); #ifdef ANDROID #include @@ -133,18 +120,11 @@ static int YGDefaultLog(const YGConfigRef config, #endif bool YGFloatIsUndefined(const float value) { -// TODO(gkm): Ugh! Some Android builds (r13b & clang-3.8) fail -// with the kludge below, so we must tailor it specifically for -// NDK r15c which has clang-5.0. NDK r16 will make it all better. -#if __ANDROID__ && __clang_major__ == 5 // TODO(gkm): remove for NDK >= 16 -#undef isnan -#define isnan __builtin_isnan -#endif - return isnan(value); + return std::isnan(value); } const YGValue* YGComputedEdgeValue( - const YGValue edges[YGEdgeCount], + const std::array& edges, const YGEdge edge, const YGValue* const defaultValue) { if (edges[edge].unit != YGUnitUndefined) { @@ -172,38 +152,93 @@ const YGValue* YGComputedEdgeValue( return defaultValue; } -static inline float YGResolveValue(const YGValue *const value, const float parentSize) { - switch (value->unit) { +static inline float YGResolveValue( + const YGValue value, + const float parentSize) { + switch (value.unit) { case YGUnitUndefined: case YGUnitAuto: return YGUndefined; case YGUnitPoint: - return value->value; + return value.value; case YGUnitPercent: - return value->value * parentSize / 100.0f; + return value.value * parentSize / 100.0f; } return YGUndefined; } -static inline float YGResolveValueMargin(const YGValue *const value, const float parentSize) { - return value->unit == YGUnitAuto ? 0 : YGResolveValue(value, parentSize); +static inline float YGResolveValueMargin( + const YGValue value, + const float parentSize) { + return value.unit == YGUnitAuto ? 0 : YGResolveValue(value, parentSize); +} + +void* YGNodeGetContext(YGNodeRef node) { + return node->getContext(); +} + +void YGNodeSetContext(YGNodeRef node, void* context) { + return node->setContext(context); +} + +YGMeasureFunc YGNodeGetMeasureFunc(YGNodeRef node) { + return node->getMeasure(); +} + +void YGNodeSetMeasureFunc(YGNodeRef node, YGMeasureFunc measureFunc) { + node->setMeasureFunc(measureFunc); +} + +YGBaselineFunc YGNodeGetBaselineFunc(YGNodeRef node) { + return node->getBaseline(); +} + +void YGNodeSetBaselineFunc(YGNodeRef node, YGBaselineFunc baselineFunc) { + node->setBaseLineFunc(baselineFunc); +} + +YGPrintFunc YGNodeGetPrintFunc(YGNodeRef node) { + return node->getPrintFunc(); +} + +void YGNodeSetPrintFunc(YGNodeRef node, YGPrintFunc printFunc) { + node->setPrintFunc(printFunc); +} + +bool YGNodeGetHasNewLayout(YGNodeRef node) { + return node->getHasNewLayout(); +} + +void YGNodeSetHasNewLayout(YGNodeRef node, bool hasNewLayout) { + node->setHasNewLayout(hasNewLayout); +} + +YGNodeType YGNodeGetNodeType(YGNodeRef node) { + return node->getNodeType(); +} + +void YGNodeSetNodeType(YGNodeRef node, YGNodeType nodeType) { + return node->setNodeType(nodeType); +} + +bool YGNodeIsDirty(YGNodeRef node) { + return node->isDirty(); } int32_t gNodeInstanceCount = 0; int32_t gConfigInstanceCount = 0; WIN_EXPORT YGNodeRef YGNodeNewWithConfig(const YGConfigRef config) { - const YGNodeRef node = (const YGNodeRef)malloc(sizeof(YGNode)); + const YGNodeRef node = new YGNode(); YGAssertWithConfig( config, node != nullptr, "Could not allocate memory for node"); gNodeInstanceCount++; - memcpy(node, &gYGNodeDefaults, sizeof(YGNode)); if (config->useWebDefaults) { - node->style.flexDirection = YGFlexDirectionRow; - node->style.alignContent = YGAlignStretch; + node->setStyleFlexDirection(YGFlexDirectionRow); + node->setStyleAlignContent(YGAlignStretch); } - node->config = config; + node->setConfig(config); return node; } @@ -214,26 +249,27 @@ YGNodeRef YGNodeNew(void) { YGNodeRef YGNodeClone(YGNodeRef oldNode) { YGNodeRef node = new YGNode(*oldNode); YGAssertWithConfig( - oldNode->config, node != nullptr, "Could not allocate memory for node"); + oldNode->getConfig(), + node != nullptr, + "Could not allocate memory for node"); gNodeInstanceCount++; - node->parent = nullptr; + node->setParent(nullptr); return node; } void YGNodeFree(const YGNodeRef node) { - if (node->parent) { - YGNodeListDelete(node->parent->children, node); - node->parent = nullptr; + if (node->getParent()) { + node->getParent()->removeChild(node); + node->setParent(nullptr); } const uint32_t childCount = YGNodeGetChildCount(node); for (uint32_t i = 0; i < childCount; i++) { const YGNodeRef child = YGNodeGetChild(node, i); - child->parent = nullptr; + child->setParent(nullptr); } - node->children.clear(); - node->children.shrink_to_fit(); + node->clearChildren(); free(node); gNodeInstanceCount--; } @@ -241,7 +277,7 @@ void YGNodeFree(const YGNodeRef node) { void YGNodeFreeRecursive(const YGNodeRef root) { while (YGNodeGetChildCount(root) > 0) { const YGNodeRef child = YGNodeGetChild(root, 0); - if (child->parent != root) { + if (child->getParent() != root) { // Don't free shared nodes that we don't own. break; } @@ -257,19 +293,18 @@ void YGNodeReset(const YGNodeRef node) { "Cannot reset a node which still has children attached"); YGAssertWithNode( node, - node->parent == nullptr, + node->getParent() == nullptr, "Cannot reset a node still attached to a parent"); - node->children.clear(); - node->children.shrink_to_fit(); + node->clearChildren(); - const YGConfigRef config = node->config; - memcpy(node, &gYGNodeDefaults, sizeof(YGNode)); + const YGConfigRef config = node->getConfig(); + *node = YGNode(); if (config->useWebDefaults) { - node->style.flexDirection = YGFlexDirectionRow; - node->style.alignContent = YGAlignStretch; + node->setStyleFlexDirection(YGFlexDirectionRow); + node->setStyleAlignContent(YGAlignStretch); } - node->config = config; + node->setConfig(config); } int32_t YGNodeGetInstanceCount(void) { @@ -304,43 +339,15 @@ void YGConfigCopy(const YGConfigRef dest, const YGConfigRef src) { } static void YGNodeMarkDirtyInternal(const YGNodeRef node) { - if (!node->isDirty) { - node->isDirty = true; - node->layout.computedFlexBasis = YGUndefined; - if (node->parent) { - YGNodeMarkDirtyInternal(node->parent); + if (!node->isDirty()) { + node->setDirty(true); + node->setLayoutComputedFlexBasis(YGUndefined); + if (node->getParent()) { + YGNodeMarkDirtyInternal(node->getParent()); } } } -void YGNodeSetMeasureFunc(const YGNodeRef node, YGMeasureFunc measureFunc) { - if (measureFunc == nullptr) { - node->measure = nullptr; - // TODO: t18095186 Move nodeType to opt-in function and mark appropriate places in Litho - node->nodeType = YGNodeTypeDefault; - } else { - YGAssertWithNode( - node, - YGNodeGetChildCount(node) == 0, - "Cannot set measure function: Nodes with measure functions cannot have children."); - node->measure = measureFunc; - // TODO: t18095186 Move nodeType to opt-in function and mark appropriate places in Litho - node->nodeType = YGNodeTypeText; - } -} - -YGMeasureFunc YGNodeGetMeasureFunc(const YGNodeRef node) { - return node->measure; -} - -void YGNodeSetBaselineFunc(const YGNodeRef node, YGBaselineFunc baselineFunc) { - node->baseline = baselineFunc; -} - -YGBaselineFunc YGNodeGetBaselineFunc(const YGNodeRef node) { - return node->baseline; -} - static void YGCloneChildrenIfNeeded(const YGNodeRef parent) { // YGNodeRemoveChild has a forked variant of this algorithm optimized for deletions. const uint32_t childCount = YGNodeGetChildCount(parent); @@ -350,7 +357,7 @@ static void YGCloneChildrenIfNeeded(const YGNodeRef parent) { } const YGNodeRef firstChild = YGNodeGetChild(parent, 0); - if (firstChild->parent == parent) { + if (firstChild->getParent() == parent) { // If the first child has this node as its parent, we assume that it is already unique. // We can do this because if we have it has a child, that means that its parent was at some // point cloned which made that subtree immutable. @@ -358,12 +365,13 @@ static void YGCloneChildrenIfNeeded(const YGNodeRef parent) { return; } - const YGNodeClonedFunc cloneNodeCallback = parent->config->cloneNodeCallback; + const YGNodeClonedFunc cloneNodeCallback = + parent->getConfig()->cloneNodeCallback; for (uint32_t i = 0; i < childCount; i++) { - const YGNodeRef oldChild = parent->children[i]; + const YGNodeRef oldChild = parent->getChild(i); const YGNodeRef newChild = YGNodeClone(oldChild); - parent->children[i] = newChild; - newChild->parent = parent; + parent->replaceChild(newChild, i); + newChild->setParent(parent); if (cloneNodeCallback) { cloneNodeCallback(oldChild, newChild, parent, i); } @@ -373,16 +381,16 @@ static void YGCloneChildrenIfNeeded(const YGNodeRef parent) { void YGNodeInsertChild(const YGNodeRef node, const YGNodeRef child, const uint32_t index) { YGAssertWithNode( node, - child->parent == nullptr, + child->getParent() == nullptr, "Child already has a parent, it must be removed first."); YGAssertWithNode( node, - node->measure == nullptr, + node->getMeasure() == nullptr, "Cannot add child: Nodes with measure functions cannot have children."); YGCloneChildrenIfNeeded(node); - node->children.insert(node->children.begin() + index, child); - child->parent = node; + node->insertChild(child, index); + child->setParent(node); YGNodeMarkDirtyInternal(node); } @@ -395,12 +403,13 @@ void YGNodeRemoveChild(const YGNodeRef parent, const YGNodeRef excludedChild) { return; } const YGNodeRef firstChild = YGNodeGetChild(parent, 0); - if (firstChild->parent == parent) { + if (firstChild->getParent() == parent) { // If the first child has this node as its parent, we assume that it is already unique. // We can now try to delete a child in this list. - if (YGNodeListDelete(parent->children, excludedChild)) { - excludedChild->layout = gYGNodeDefaults.layout; // layout is no longer valid - excludedChild->parent = nullptr; + if (parent->removeChild(excludedChild)) { + excludedChild->setLayout( + YGNode().getLayout()); // layout is no longer valid + excludedChild->setParent(nullptr); YGNodeMarkDirtyInternal(parent); } return; @@ -408,10 +417,11 @@ void YGNodeRemoveChild(const YGNodeRef parent, const YGNodeRef excludedChild) { // Otherwise we have to clone the node list except for the child we're trying to delete. // We don't want to simply clone all children, because then the host will need to free // the clone of the child that was just deleted. - const YGNodeClonedFunc cloneNodeCallback = parent->config->cloneNodeCallback; + const YGNodeClonedFunc cloneNodeCallback = + parent->getConfig()->cloneNodeCallback; uint32_t nextInsertIndex = 0; for (uint32_t i = 0; i < childCount; i++) { - const YGNodeRef oldChild = parent->children[i]; + const YGNodeRef oldChild = parent->getChild(i); if (excludedChild == oldChild) { // Ignore the deleted child. Don't reset its layout or parent since it is still valid // in the other parent. However, since this parent has now changed, we need to mark it @@ -420,15 +430,15 @@ void YGNodeRemoveChild(const YGNodeRef parent, const YGNodeRef excludedChild) { continue; } const YGNodeRef newChild = YGNodeClone(oldChild); - parent->children[nextInsertIndex] = newChild; - newChild->parent = parent; + parent->replaceChild(newChild, nextInsertIndex); + newChild->setParent(parent); if (cloneNodeCallback) { cloneNodeCallback(oldChild, newChild, parent, nextInsertIndex); } nextInsertIndex++; } while (nextInsertIndex < childCount) { - parent->children.erase(parent->children.begin() + nextInsertIndex); + parent->removeChild(nextInsertIndex); nextInsertIndex++; } } @@ -440,123 +450,108 @@ void YGNodeRemoveAllChildren(const YGNodeRef parent) { return; } const YGNodeRef firstChild = YGNodeGetChild(parent, 0); - if (firstChild->parent == parent) { + if (firstChild->getParent() == parent) { // If the first child has this node as its parent, we assume that this child set is unique. for (uint32_t i = 0; i < childCount; i++) { const YGNodeRef oldChild = YGNodeGetChild(parent, i); - oldChild->layout = gYGNodeDefaults.layout; // layout is no longer valid - oldChild->parent = nullptr; + oldChild->setLayout(YGNode().getLayout()); // layout is no longer valid + oldChild->setParent(nullptr); } - parent->children.clear(); - parent->children.shrink_to_fit(); + parent->clearChildren(); YGNodeMarkDirtyInternal(parent); return; } // Otherwise, we are not the owner of the child set. We don't have to do anything to clear it. - parent->children = YGVector(); + parent->setChildren(YGVector()); YGNodeMarkDirtyInternal(parent); } YGNodeRef YGNodeGetChild(const YGNodeRef node, const uint32_t index) { - if (index < node->children.size()) { - return node->children[index]; + if (index < node->getChildren().size()) { + return node->getChild(index); } return nullptr; } -YGNodeRef YGNodeGetParent(const YGNodeRef node) { - return node->parent; +uint32_t YGNodeGetChildCount(const YGNodeRef node) { + return node->getChildren().size(); } -uint32_t YGNodeGetChildCount(const YGNodeRef node) { - return node->children.size(); +YGNodeRef YGNodeGetParent(const YGNodeRef node) { + return node->getParent(); } void YGNodeMarkDirty(const YGNodeRef node) { YGAssertWithNode( node, - node->measure != nullptr, + node->getMeasure() != nullptr, "Only leaf nodes with custom measure functions" "should manually mark themselves as dirty"); YGNodeMarkDirtyInternal(node); } -bool YGNodeIsDirty(const YGNodeRef node) { - return node->isDirty; -} - void YGNodeCopyStyle(const YGNodeRef dstNode, const YGNodeRef srcNode) { - if (memcmp(&dstNode->style, &srcNode->style, sizeof(YGStyle)) != 0) { - memcpy(&dstNode->style, &srcNode->style, sizeof(YGStyle)); + if (!(dstNode->getStyle() == srcNode->getStyle())) { + dstNode->setStyle(srcNode->getStyle()); YGNodeMarkDirtyInternal(dstNode); } } static inline float YGResolveFlexGrow(const YGNodeRef node) { // Root nodes flexGrow should always be 0 - if (node->parent == nullptr) { + if (node->getParent() == nullptr) { return 0.0; } - if (!YGFloatIsUndefined(node->style.flexGrow)) { - return node->style.flexGrow; + if (!YGFloatIsUndefined(node->getStyle().flexGrow)) { + return node->getStyle().flexGrow; } - if (!YGFloatIsUndefined(node->style.flex) && node->style.flex > 0.0f) { - return node->style.flex; + if (!YGFloatIsUndefined(node->getStyle().flex) && + node->getStyle().flex > 0.0f) { + return node->getStyle().flex; } return kDefaultFlexGrow; } float YGNodeStyleGetFlexGrow(const YGNodeRef node) { - return YGFloatIsUndefined(node->style.flexGrow) ? kDefaultFlexGrow : node->style.flexGrow; + return YGFloatIsUndefined(node->getStyle().flexGrow) + ? kDefaultFlexGrow + : node->getStyle().flexGrow; } float YGNodeStyleGetFlexShrink(const YGNodeRef node) { - return YGFloatIsUndefined(node->style.flexShrink) - ? (node->config->useWebDefaults ? kWebDefaultFlexShrink : kDefaultFlexShrink) - : node->style.flexShrink; + return YGFloatIsUndefined(node->getStyle().flexShrink) + ? (node->getConfig()->useWebDefaults ? kWebDefaultFlexShrink + : kDefaultFlexShrink) + : node->getStyle().flexShrink; } static inline float YGNodeResolveFlexShrink(const YGNodeRef node) { // Root nodes flexShrink should always be 0 - if (node->parent == nullptr) { + if (node->getParent() == nullptr) { return 0.0; } - if (!YGFloatIsUndefined(node->style.flexShrink)) { - return node->style.flexShrink; - } - if (!node->config->useWebDefaults && !YGFloatIsUndefined(node->style.flex) && - node->style.flex < 0.0f) { - return -node->style.flex; - } - return node->config->useWebDefaults ? kWebDefaultFlexShrink : kDefaultFlexShrink; -} - -static inline const YGValue *YGNodeResolveFlexBasisPtr(const YGNodeRef node) { - if (node->style.flexBasis.unit != YGUnitAuto && node->style.flexBasis.unit != YGUnitUndefined) { - return &node->style.flexBasis; + if (!YGFloatIsUndefined(node->getStyle().flexShrink)) { + return node->getStyle().flexShrink; } - if (!YGFloatIsUndefined(node->style.flex) && node->style.flex > 0.0f) { - return node->config->useWebDefaults ? &YGValueAuto : &YGValueZero; + if (!node->getConfig()->useWebDefaults && + !YGFloatIsUndefined(node->getStyle().flex) && + node->getStyle().flex < 0.0f) { + return -node->getStyle().flex; } - return &YGValueAuto; + return node->getConfig()->useWebDefaults ? kWebDefaultFlexShrink + : kDefaultFlexShrink; } -#define YG_NODE_PROPERTY_IMPL(type, name, paramName, instanceName) \ - void YGNodeSet##name(const YGNodeRef node, type paramName) { \ - node->instanceName = paramName; \ - } \ - \ - type YGNodeGet##name(const YGNodeRef node) { \ - return node->instanceName; \ - } - -#define YG_NODE_STYLE_PROPERTY_SETTER_IMPL(type, name, paramName, instanceName) \ - void YGNodeStyleSet##name(const YGNodeRef node, const type paramName) { \ - if (node->style.instanceName != paramName) { \ - node->style.instanceName = paramName; \ - YGNodeMarkDirtyInternal(node); \ - } \ +#define YG_NODE_STYLE_PROPERTY_SETTER_IMPL( \ + type, name, paramName, instanceName) \ + void YGNodeStyleSet##name(const YGNodeRef node, const type paramName) { \ + if (node->getStyle().instanceName != paramName) { \ + YGStyle style = node->getStyle(); \ + style.instanceName = paramName; \ + node->setStyle(style); \ + YGNodeMarkDirtyInternal(node); \ + } \ } #define YG_NODE_STYLE_PROPERTY_SETTER_UNIT_IMPL( \ @@ -566,10 +561,12 @@ static inline const YGValue *YGNodeResolveFlexBasisPtr(const YGNodeRef node) { .value = paramName, \ .unit = YGFloatIsUndefined(paramName) ? YGUnitUndefined : YGUnitPoint, \ }; \ - if ((node->style.instanceName.value != value.value && \ + if ((node->getStyle().instanceName.value != value.value && \ value.unit != YGUnitUndefined) || \ - node->style.instanceName.unit != value.unit) { \ - node->style.instanceName = value; \ + node->getStyle().instanceName.unit != value.unit) { \ + YGStyle style = node->getStyle(); \ + style.instanceName = value; \ + node->setStyle(style); \ YGNodeMarkDirtyInternal(node); \ } \ } \ @@ -581,10 +578,13 @@ static inline const YGValue *YGNodeResolveFlexBasisPtr(const YGNodeRef node) { .unit = \ YGFloatIsUndefined(paramName) ? YGUnitUndefined : YGUnitPercent, \ }; \ - if ((node->style.instanceName.value != value.value && \ + if ((node->getStyle().instanceName.value != value.value && \ value.unit != YGUnitUndefined) || \ - node->style.instanceName.unit != value.unit) { \ - node->style.instanceName = value; \ + node->getStyle().instanceName.unit != value.unit) { \ + YGStyle style = node->getStyle(); \ + \ + style.instanceName = value; \ + node->setStyle(style); \ YGNodeMarkDirtyInternal(node); \ } \ } @@ -596,29 +596,35 @@ static inline const YGValue *YGNodeResolveFlexBasisPtr(const YGNodeRef node) { .value = paramName, \ .unit = YGFloatIsUndefined(paramName) ? YGUnitUndefined : YGUnitPoint, \ }; \ - if ((node->style.instanceName.value != value.value && \ + if ((node->getStyle().instanceName.value != value.value && \ value.unit != YGUnitUndefined) || \ - node->style.instanceName.unit != value.unit) { \ - node->style.instanceName = value; \ + node->getStyle().instanceName.unit != value.unit) { \ + YGStyle style = node->getStyle(); \ + style.instanceName = value; \ + node->setStyle(style); \ YGNodeMarkDirtyInternal(node); \ } \ } \ \ void YGNodeStyleSet##name##Percent( \ const YGNodeRef node, const type paramName) { \ - if (node->style.instanceName.value != paramName || \ - node->style.instanceName.unit != YGUnitPercent) { \ - node->style.instanceName.value = paramName; \ - node->style.instanceName.unit = \ + if (node->getStyle().instanceName.value != paramName || \ + node->getStyle().instanceName.unit != YGUnitPercent) { \ + YGStyle style = node->getStyle(); \ + style.instanceName.value = paramName; \ + style.instanceName.unit = \ YGFloatIsUndefined(paramName) ? YGUnitAuto : YGUnitPercent; \ + node->setStyle(style); \ YGNodeMarkDirtyInternal(node); \ } \ } \ \ void YGNodeStyleSet##name##Auto(const YGNodeRef node) { \ - if (node->style.instanceName.unit != YGUnitAuto) { \ - node->style.instanceName.value = YGUndefined; \ - node->style.instanceName.unit = YGUnitAuto; \ + if (node->getStyle().instanceName.unit != YGUnitAuto) { \ + YGStyle style = node->getStyle(); \ + style.instanceName.value = YGUndefined; \ + style.instanceName.unit = YGUnitAuto; \ + node->setStyle(style); \ YGNodeMarkDirtyInternal(node); \ } \ } @@ -627,28 +633,33 @@ static inline const YGValue *YGNodeResolveFlexBasisPtr(const YGNodeRef node) { YG_NODE_STYLE_PROPERTY_SETTER_IMPL(type, name, paramName, instanceName) \ \ type YGNodeStyleGet##name(const YGNodeRef node) { \ - return node->style.instanceName; \ + return node->getStyle().instanceName; \ } -#define YG_NODE_STYLE_PROPERTY_UNIT_IMPL(type, name, paramName, instanceName) \ - YG_NODE_STYLE_PROPERTY_SETTER_UNIT_IMPL(float, name, paramName, instanceName) \ - \ - type YGNodeStyleGet##name(const YGNodeRef node) { \ - return node->style.instanceName; \ +#define YG_NODE_STYLE_PROPERTY_UNIT_IMPL(type, name, paramName, instanceName) \ + YG_NODE_STYLE_PROPERTY_SETTER_UNIT_IMPL( \ + float, name, paramName, instanceName) \ + \ + type YGNodeStyleGet##name(const YGNodeRef node) { \ + return node->getStyle().instanceName; \ } -#define YG_NODE_STYLE_PROPERTY_UNIT_AUTO_IMPL(type, name, paramName, instanceName) \ - YG_NODE_STYLE_PROPERTY_SETTER_UNIT_AUTO_IMPL(float, name, paramName, instanceName) \ - \ - type YGNodeStyleGet##name(const YGNodeRef node) { \ - return node->style.instanceName; \ +#define YG_NODE_STYLE_PROPERTY_UNIT_AUTO_IMPL( \ + type, name, paramName, instanceName) \ + YG_NODE_STYLE_PROPERTY_SETTER_UNIT_AUTO_IMPL( \ + float, name, paramName, instanceName) \ + \ + type YGNodeStyleGet##name(const YGNodeRef node) { \ + return node->getStyle().instanceName; \ } #define YG_NODE_STYLE_EDGE_PROPERTY_UNIT_AUTO_IMPL(type, name, instanceName) \ void YGNodeStyleSet##name##Auto(const YGNodeRef node, const YGEdge edge) { \ - if (node->style.instanceName[edge].unit != YGUnitAuto) { \ - node->style.instanceName[edge].value = YGUndefined; \ - node->style.instanceName[edge].unit = YGUnitAuto; \ + if (node->getStyle().instanceName[edge].unit != YGUnitAuto) { \ + YGStyle style = node->getStyle(); \ + style.instanceName[edge].value = YGUndefined; \ + style.instanceName[edge].unit = YGUnitAuto; \ + node->setStyle(style); \ YGNodeMarkDirtyInternal(node); \ } \ } @@ -661,10 +672,12 @@ static inline const YGValue *YGNodeResolveFlexBasisPtr(const YGNodeRef node) { .value = paramName, \ .unit = YGFloatIsUndefined(paramName) ? YGUnitUndefined : YGUnitPoint, \ }; \ - if ((node->style.instanceName[edge].value != value.value && \ + if ((node->getStyle().instanceName[edge].value != value.value && \ value.unit != YGUnitUndefined) || \ - node->style.instanceName[edge].unit != value.unit) { \ - node->style.instanceName[edge] = value; \ + node->getStyle().instanceName[edge].unit != value.unit) { \ + YGStyle style = node->getStyle(); \ + style.instanceName[edge] = value; \ + node->setStyle(style); \ YGNodeMarkDirtyInternal(node); \ } \ } \ @@ -676,17 +689,19 @@ static inline const YGValue *YGNodeResolveFlexBasisPtr(const YGNodeRef node) { .unit = \ YGFloatIsUndefined(paramName) ? YGUnitUndefined : YGUnitPercent, \ }; \ - if ((node->style.instanceName[edge].value != value.value && \ + if ((node->getStyle().instanceName[edge].value != value.value && \ value.unit != YGUnitUndefined) || \ - node->style.instanceName[edge].unit != value.unit) { \ - node->style.instanceName[edge] = value; \ + node->getStyle().instanceName[edge].unit != value.unit) { \ + YGStyle style = node->getStyle(); \ + style.instanceName[edge] = value; \ + node->setStyle(style); \ YGNodeMarkDirtyInternal(node); \ } \ } \ \ WIN_STRUCT(type) \ YGNodeStyleGet##name(const YGNodeRef node, const YGEdge edge) { \ - return WIN_STRUCT_REF(node->style.instanceName[edge]); \ + return WIN_STRUCT_REF(node->getStyle().instanceName[edge]); \ } #define YG_NODE_STYLE_EDGE_PROPERTY_IMPL(type, name, paramName, instanceName) \ @@ -696,21 +711,23 @@ static inline const YGValue *YGNodeResolveFlexBasisPtr(const YGNodeRef node) { .value = paramName, \ .unit = YGFloatIsUndefined(paramName) ? YGUnitUndefined : YGUnitPoint, \ }; \ - if ((node->style.instanceName[edge].value != value.value && \ + if ((node->getStyle().instanceName[edge].value != value.value && \ value.unit != YGUnitUndefined) || \ - node->style.instanceName[edge].unit != value.unit) { \ - node->style.instanceName[edge] = value; \ + node->getStyle().instanceName[edge].unit != value.unit) { \ + YGStyle style = node->getStyle(); \ + style.instanceName[edge] = value; \ + node->setStyle(style); \ YGNodeMarkDirtyInternal(node); \ } \ } \ \ float YGNodeStyleGet##name(const YGNodeRef node, const YGEdge edge) { \ - return node->style.instanceName[edge].value; \ + return node->getStyle().instanceName[edge].value; \ } #define YG_NODE_LAYOUT_PROPERTY_IMPL(type, name, instanceName) \ type YGNodeLayoutGet##name(const YGNodeRef node) { \ - return node->layout.instanceName; \ + return node->getLayout().instanceName; \ } #define YG_NODE_LAYOUT_RESOLVED_PROPERTY_IMPL(type, name, instanceName) \ @@ -721,28 +738,28 @@ static inline const YGValue *YGNodeResolveFlexBasisPtr(const YGNodeRef node) { "Cannot get layout properties of multi-edge shorthands"); \ \ if (edge == YGEdgeLeft) { \ - if (node->layout.direction == YGDirectionRTL) { \ - return node->layout.instanceName[YGEdgeEnd]; \ + if (node->getLayout().direction == YGDirectionRTL) { \ + return node->getLayout().instanceName[YGEdgeEnd]; \ } else { \ - return node->layout.instanceName[YGEdgeStart]; \ + return node->getLayout().instanceName[YGEdgeStart]; \ } \ } \ \ if (edge == YGEdgeRight) { \ - if (node->layout.direction == YGDirectionRTL) { \ - return node->layout.instanceName[YGEdgeStart]; \ + if (node->getLayout().direction == YGDirectionRTL) { \ + return node->getLayout().instanceName[YGEdgeStart]; \ } else { \ - return node->layout.instanceName[YGEdgeEnd]; \ + return node->getLayout().instanceName[YGEdgeEnd]; \ } \ } \ \ - return node->layout.instanceName[edge]; \ + return node->getLayout().instanceName[edge]; \ } -YG_NODE_PROPERTY_IMPL(void *, Context, context, context); -YG_NODE_PROPERTY_IMPL(YGPrintFunc, PrintFunc, printFunc, print); -YG_NODE_PROPERTY_IMPL(bool, HasNewLayout, hasNewLayout, hasNewLayout); -YG_NODE_PROPERTY_IMPL(YGNodeType, NodeType, nodeType, nodeType); +// YG_NODE_PROPERTY_IMPL(void *, Context, context, context); +// YG_NODE_PROPERTY_IMPL(YGPrintFunc, PrintFunc, printFunc, print); +// YG_NODE_PROPERTY_IMPL(bool, HasNewLayout, hasNewLayout, hasNewLayout); +// YG_NODE_PROPERTY_IMPL(YGNodeType, NodeType, nodeType, nodeType); YG_NODE_STYLE_PROPERTY_IMPL(YGDirection, Direction, direction, direction); YG_NODE_STYLE_PROPERTY_IMPL(YGFlexDirection, FlexDirection, flexDirection, flexDirection); @@ -808,24 +825,14 @@ bool YGValueEqual(const YGValue a, const YGValue b) { return false; } - if (a.unit == YGUnitUndefined) { + if (a.unit == YGUnitUndefined || + (std::isnan(a.value) && std::isnan(b.value))) { return true; } return fabs(a.value - b.value) < 0.0001f; } -static inline void YGResolveDimensions(YGNodeRef node) { - for (uint32_t dim = YGDimensionWidth; dim < YGDimensionCount; dim++) { - if (node->style.maxDimensions[dim].unit != YGUnitUndefined && - YGValueEqual(node->style.maxDimensions[dim], node->style.minDimensions[dim])) { - node->resolvedDimensions[dim] = &node->style.maxDimensions[dim]; - } else { - node->resolvedDimensions[dim] = &node->style.dimensions[dim]; - } - } -} - bool YGFloatsEqual(const float a, const float b) { if (YGFloatIsUndefined(a)) { return YGFloatIsUndefined(b); @@ -844,32 +851,21 @@ void YGNodePrint(const YGNodeRef node, const YGPrintOptions options) { YGNodePrintInternal(node, options); } -static const YGEdge leading[4] = { - [YGFlexDirectionColumn] = YGEdgeTop, - [YGFlexDirectionColumnReverse] = YGEdgeBottom, - [YGFlexDirectionRow] = YGEdgeLeft, - [YGFlexDirectionRowReverse] = YGEdgeRight, -}; -static const YGEdge trailing[4] = { - [YGFlexDirectionColumn] = YGEdgeBottom, - [YGFlexDirectionColumnReverse] = YGEdgeTop, - [YGFlexDirectionRow] = YGEdgeRight, - [YGFlexDirectionRowReverse] = YGEdgeLeft, -}; -static const YGEdge pos[4] = { - [YGFlexDirectionColumn] = YGEdgeTop, - [YGFlexDirectionColumnReverse] = YGEdgeBottom, - [YGFlexDirectionRow] = YGEdgeLeft, - [YGFlexDirectionRowReverse] = YGEdgeRight, -}; -static const YGDimension dim[4] = { - [YGFlexDirectionColumn] = YGDimensionHeight, - [YGFlexDirectionColumnReverse] = YGDimensionHeight, - [YGFlexDirectionRow] = YGDimensionWidth, - [YGFlexDirectionRowReverse] = YGDimensionWidth, -}; +const std::array leading = { + {YGEdgeTop, YGEdgeBottom, YGEdgeLeft, YGEdgeRight}}; + +const std::array trailing = { + {YGEdgeBottom, YGEdgeTop, YGEdgeRight, YGEdgeLeft}}; +static const std::array pos = {{ + YGEdgeTop, + YGEdgeBottom, + YGEdgeLeft, + YGEdgeRight, +}}; +static const std::array dim = { + {YGDimensionHeight, YGDimensionHeight, YGDimensionWidth, YGDimensionWidth}}; -static inline bool YGFlexDirectionIsRow(const YGFlexDirection flexDirection) { +bool YGFlexDirectionIsRow(const YGFlexDirection flexDirection) { return flexDirection == YGFlexDirectionRow || flexDirection == YGFlexDirectionRowReverse; } @@ -880,73 +876,103 @@ static inline bool YGFlexDirectionIsColumn(const YGFlexDirection flexDirection) static inline float YGNodeLeadingMargin(const YGNodeRef node, const YGFlexDirection axis, const float widthSize) { - if (YGFlexDirectionIsRow(axis) && node->style.margin[YGEdgeStart].unit != YGUnitUndefined) { - return YGResolveValueMargin(&node->style.margin[YGEdgeStart], widthSize); + if (YGFlexDirectionIsRow(axis) && + node->getStyle().margin[YGEdgeStart].unit != YGUnitUndefined) { + return YGResolveValueMargin( + node->getStyle().margin[YGEdgeStart], widthSize); } - return YGResolveValueMargin(YGComputedEdgeValue(node->style.margin, leading[axis], &YGValueZero), - widthSize); + return YGResolveValueMargin( + *YGComputedEdgeValue( + node->getStyle().margin, leading[axis], &YGValueZero), + widthSize); } static float YGNodeTrailingMargin(const YGNodeRef node, const YGFlexDirection axis, const float widthSize) { - if (YGFlexDirectionIsRow(axis) && node->style.margin[YGEdgeEnd].unit != YGUnitUndefined) { - return YGResolveValueMargin(&node->style.margin[YGEdgeEnd], widthSize); + if (YGFlexDirectionIsRow(axis) && + node->getStyle().margin[YGEdgeEnd].unit != YGUnitUndefined) { + return YGResolveValueMargin(node->getStyle().margin[YGEdgeEnd], widthSize); } - return YGResolveValueMargin(YGComputedEdgeValue(node->style.margin, trailing[axis], &YGValueZero), - widthSize); + return YGResolveValueMargin( + *YGComputedEdgeValue( + node->getStyle().margin, trailing[axis], &YGValueZero), + widthSize); } static float YGNodeLeadingPadding(const YGNodeRef node, const YGFlexDirection axis, const float widthSize) { - if (YGFlexDirectionIsRow(axis) && node->style.padding[YGEdgeStart].unit != YGUnitUndefined && - YGResolveValue(&node->style.padding[YGEdgeStart], widthSize) >= 0.0f) { - return YGResolveValue(&node->style.padding[YGEdgeStart], widthSize); + if (YGFlexDirectionIsRow(axis) && + node->getStyle().padding[YGEdgeStart].unit != YGUnitUndefined && + YGResolveValue(node->getStyle().padding[YGEdgeStart], widthSize) >= + 0.0f) { + return YGResolveValue(node->getStyle().padding[YGEdgeStart], widthSize); } - return fmaxf(YGResolveValue(YGComputedEdgeValue(node->style.padding, leading[axis], &YGValueZero), - widthSize), - 0.0f); + return fmaxf( + YGResolveValue( + *YGComputedEdgeValue( + node->getStyle().padding, leading[axis], &YGValueZero), + widthSize), + 0.0f); } static float YGNodeTrailingPadding(const YGNodeRef node, const YGFlexDirection axis, const float widthSize) { - if (YGFlexDirectionIsRow(axis) && node->style.padding[YGEdgeEnd].unit != YGUnitUndefined && - YGResolveValue(&node->style.padding[YGEdgeEnd], widthSize) >= 0.0f) { - return YGResolveValue(&node->style.padding[YGEdgeEnd], widthSize); + if (YGFlexDirectionIsRow(axis) && + node->getStyle().padding[YGEdgeEnd].unit != YGUnitUndefined && + YGResolveValue(node->getStyle().padding[YGEdgeEnd], widthSize) >= 0.0f) { + return YGResolveValue(node->getStyle().padding[YGEdgeEnd], widthSize); } - return fmaxf(YGResolveValue(YGComputedEdgeValue(node->style.padding, trailing[axis], &YGValueZero), - widthSize), - 0.0f); + return fmaxf( + YGResolveValue( + *YGComputedEdgeValue( + node->getStyle().padding, trailing[axis], &YGValueZero), + widthSize), + 0.0f); } -static float YGNodeLeadingBorder(const YGNodeRef node, const YGFlexDirection axis) { - if (YGFlexDirectionIsRow(axis) && node->style.border[YGEdgeStart].unit != YGUnitUndefined && - node->style.border[YGEdgeStart].value >= 0.0f) { - return node->style.border[YGEdgeStart].value; +static float YGNodeLeadingBorder( + const YGNodeRef node, + const YGFlexDirection axis) { + if (YGFlexDirectionIsRow(axis) && + node->getStyle().border[YGEdgeStart].unit != YGUnitUndefined && + node->getStyle().border[YGEdgeStart].value >= 0.0f) { + return node->getStyle().border[YGEdgeStart].value; } - return fmaxf(YGComputedEdgeValue(node->style.border, leading[axis], &YGValueZero)->value, 0.0f); + return fmaxf( + YGComputedEdgeValue(node->getStyle().border, leading[axis], &YGValueZero) + ->value, + 0.0f); } -static float YGNodeTrailingBorder(const YGNodeRef node, const YGFlexDirection axis) { - if (YGFlexDirectionIsRow(axis) && node->style.border[YGEdgeEnd].unit != YGUnitUndefined && - node->style.border[YGEdgeEnd].value >= 0.0f) { - return node->style.border[YGEdgeEnd].value; +static float YGNodeTrailingBorder( + const YGNodeRef node, + const YGFlexDirection axis) { + if (YGFlexDirectionIsRow(axis) && + node->getStyle().border[YGEdgeEnd].unit != YGUnitUndefined && + node->getStyle().border[YGEdgeEnd].value >= 0.0f) { + return node->getStyle().border[YGEdgeEnd].value; } - return fmaxf(YGComputedEdgeValue(node->style.border, trailing[axis], &YGValueZero)->value, 0.0f); + return fmaxf( + YGComputedEdgeValue(node->getStyle().border, trailing[axis], &YGValueZero) + ->value, + 0.0f); } -static inline float YGNodeLeadingPaddingAndBorder(const YGNodeRef node, - const YGFlexDirection axis, - const float widthSize) { - return YGNodeLeadingPadding(node, axis, widthSize) + YGNodeLeadingBorder(node, axis); +static inline float YGNodeLeadingPaddingAndBorder( + const YGNodeRef node, + const YGFlexDirection axis, + const float widthSize) { + return YGNodeLeadingPadding(node, axis, widthSize) + + YGNodeLeadingBorder(node, axis); } static inline float YGNodeTrailingPaddingAndBorder(const YGNodeRef node, @@ -969,9 +995,11 @@ static inline float YGNodePaddingAndBorderForAxis(const YGNodeRef node, } static inline YGAlign YGNodeAlignItem(const YGNodeRef node, const YGNodeRef child) { - const YGAlign align = - child->style.alignSelf == YGAlignAuto ? node->style.alignItems : child->style.alignSelf; - if (align == YGAlignBaseline && YGFlexDirectionIsColumn(node->style.flexDirection)) { + const YGAlign align = child->getStyle().alignSelf == YGAlignAuto + ? node->getStyle().alignItems + : child->getStyle().alignSelf; + if (align == YGAlignBaseline && + YGFlexDirectionIsColumn(node->getStyle().flexDirection)) { return YGAlignFlexStart; } return align; @@ -979,18 +1007,19 @@ static inline YGAlign YGNodeAlignItem(const YGNodeRef node, const YGNodeRef chil static inline YGDirection YGNodeResolveDirection(const YGNodeRef node, const YGDirection parentDirection) { - if (node->style.direction == YGDirectionInherit) { + if (node->getStyle().direction == YGDirectionInherit) { return parentDirection > YGDirectionInherit ? parentDirection : YGDirectionLTR; } else { - return node->style.direction; + return node->getStyle().direction; } } static float YGBaseline(const YGNodeRef node) { - if (node->baseline != nullptr) { - const float baseline = node->baseline(node, - node->layout.measuredDimensions[YGDimensionWidth], - node->layout.measuredDimensions[YGDimensionHeight]); + if (node->getBaseline() != nullptr) { + const float baseline = node->getBaseline()( + node, + node->getLayout().measuredDimensions[YGDimensionWidth], + node->getLayout().measuredDimensions[YGDimensionHeight]); YGAssertWithNode(node, !YGFloatIsUndefined(baseline), "Expect custom baseline function to not return NaN"); @@ -1001,10 +1030,10 @@ static float YGBaseline(const YGNodeRef node) { const uint32_t childCount = YGNodeGetChildCount(node); for (uint32_t i = 0; i < childCount; i++) { const YGNodeRef child = YGNodeGetChild(node, i); - if (child->lineIndex > 0) { + if (child->getLineIndex() > 0) { break; } - if (child->style.positionType == YGPositionTypeAbsolute) { + if (child->getStyle().positionType == YGPositionTypeAbsolute) { continue; } if (YGNodeAlignItem(node, child) == YGAlignBaseline) { @@ -1018,11 +1047,11 @@ static float YGBaseline(const YGNodeRef node) { } if (baselineChild == nullptr) { - return node->layout.measuredDimensions[YGDimensionHeight]; + return node->getLayout().measuredDimensions[YGDimensionHeight]; } const float baseline = YGBaseline(baselineChild); - return baseline + baselineChild->layout.position[YGEdgeTop]; + return baseline + baselineChild->getLayout().position[YGEdgeTop]; } static inline YGFlexDirection YGResolveFlexDirection(const YGFlexDirection flexDirection, @@ -1046,22 +1075,23 @@ static YGFlexDirection YGFlexDirectionCross(const YGFlexDirection flexDirection, } static inline bool YGNodeIsFlex(const YGNodeRef node) { - return (node->style.positionType == YGPositionTypeRelative && - (YGResolveFlexGrow(node) != 0 || YGNodeResolveFlexShrink(node) != 0)); + return ( + node->getStyle().positionType == YGPositionTypeRelative && + (YGResolveFlexGrow(node) != 0 || YGNodeResolveFlexShrink(node) != 0)); } static bool YGIsBaselineLayout(const YGNodeRef node) { - if (YGFlexDirectionIsColumn(node->style.flexDirection)) { + if (YGFlexDirectionIsColumn(node->getStyle().flexDirection)) { return false; } - if (node->style.alignItems == YGAlignBaseline) { + if (node->getStyle().alignItems == YGAlignBaseline) { return true; } const uint32_t childCount = YGNodeGetChildCount(node); for (uint32_t i = 0; i < childCount; i++) { const YGNodeRef child = YGNodeGetChild(node, i); - if (child->style.positionType == YGPositionTypeRelative && - child->style.alignSelf == YGAlignBaseline) { + if (child->getStyle().positionType == YGPositionTypeRelative && + child->getStyle().alignSelf == YGAlignBaseline) { return true; } } @@ -1072,76 +1102,87 @@ static bool YGIsBaselineLayout(const YGNodeRef node) { static inline float YGNodeDimWithMargin(const YGNodeRef node, const YGFlexDirection axis, const float widthSize) { - return node->layout.measuredDimensions[dim[axis]] + YGNodeLeadingMargin(node, axis, widthSize) + - YGNodeTrailingMargin(node, axis, widthSize); + return node->getLayout().measuredDimensions[dim[axis]] + + YGNodeLeadingMargin(node, axis, widthSize) + + YGNodeTrailingMargin(node, axis, widthSize); } static inline bool YGNodeIsStyleDimDefined(const YGNodeRef node, const YGFlexDirection axis, const float parentSize) { - return !(node->resolvedDimensions[dim[axis]]->unit == YGUnitAuto || - node->resolvedDimensions[dim[axis]]->unit == YGUnitUndefined || - (node->resolvedDimensions[dim[axis]]->unit == YGUnitPoint && - node->resolvedDimensions[dim[axis]]->value < 0.0f) || - (node->resolvedDimensions[dim[axis]]->unit == YGUnitPercent && - (node->resolvedDimensions[dim[axis]]->value < 0.0f || YGFloatIsUndefined(parentSize)))); + return !( + node->getResolvedDimension(dim[axis]).unit == YGUnitAuto || + node->getResolvedDimension(dim[axis]).unit == YGUnitUndefined || + (node->getResolvedDimension(dim[axis]).unit == YGUnitPoint && + node->getResolvedDimension(dim[axis]).value < 0.0f) || + (node->getResolvedDimension(dim[axis]).unit == YGUnitPercent && + (node->getResolvedDimension(dim[axis]).value < 0.0f || + YGFloatIsUndefined(parentSize)))); } static inline bool YGNodeIsLayoutDimDefined(const YGNodeRef node, const YGFlexDirection axis) { - const float value = node->layout.measuredDimensions[dim[axis]]; + const float value = node->getLayout().measuredDimensions[dim[axis]]; return !YGFloatIsUndefined(value) && value >= 0.0f; } static inline bool YGNodeIsLeadingPosDefined(const YGNodeRef node, const YGFlexDirection axis) { return (YGFlexDirectionIsRow(axis) && - YGComputedEdgeValue(node->style.position, YGEdgeStart, &YGValueUndefined)->unit != - YGUnitUndefined) || - YGComputedEdgeValue(node->style.position, leading[axis], &YGValueUndefined)->unit != - YGUnitUndefined; + YGComputedEdgeValue( + node->getStyle().position, YGEdgeStart, &YGValueUndefined) + ->unit != YGUnitUndefined) || + YGComputedEdgeValue( + node->getStyle().position, leading[axis], &YGValueUndefined) + ->unit != YGUnitUndefined; } static inline bool YGNodeIsTrailingPosDefined(const YGNodeRef node, const YGFlexDirection axis) { return (YGFlexDirectionIsRow(axis) && - YGComputedEdgeValue(node->style.position, YGEdgeEnd, &YGValueUndefined)->unit != - YGUnitUndefined) || - YGComputedEdgeValue(node->style.position, trailing[axis], &YGValueUndefined)->unit != - YGUnitUndefined; + YGComputedEdgeValue( + node->getStyle().position, YGEdgeEnd, &YGValueUndefined) + ->unit != YGUnitUndefined) || + YGComputedEdgeValue( + node->getStyle().position, trailing[axis], &YGValueUndefined) + ->unit != YGUnitUndefined; } static float YGNodeLeadingPosition(const YGNodeRef node, const YGFlexDirection axis, const float axisSize) { if (YGFlexDirectionIsRow(axis)) { - const YGValue *leadingPosition = - YGComputedEdgeValue(node->style.position, YGEdgeStart, &YGValueUndefined); + const YGValue* leadingPosition = YGComputedEdgeValue( + node->getStyle().position, YGEdgeStart, &YGValueUndefined); if (leadingPosition->unit != YGUnitUndefined) { - return YGResolveValue(leadingPosition, axisSize); + return YGResolveValue( + *leadingPosition, + axisSize); // leadingPosition->resolveValue(axisSize); } } - const YGValue *leadingPosition = - YGComputedEdgeValue(node->style.position, leading[axis], &YGValueUndefined); + const YGValue* leadingPosition = YGComputedEdgeValue( + node->getStyle().position, leading[axis], &YGValueUndefined); - return leadingPosition->unit == YGUnitUndefined ? 0.0f - : YGResolveValue(leadingPosition, axisSize); + return leadingPosition->unit == YGUnitUndefined + ? 0.0f + : YGResolveValue(*leadingPosition, axisSize); } static float YGNodeTrailingPosition(const YGNodeRef node, const YGFlexDirection axis, const float axisSize) { if (YGFlexDirectionIsRow(axis)) { - const YGValue *trailingPosition = - YGComputedEdgeValue(node->style.position, YGEdgeEnd, &YGValueUndefined); + const YGValue* trailingPosition = YGComputedEdgeValue( + node->getStyle().position, YGEdgeEnd, &YGValueUndefined); if (trailingPosition->unit != YGUnitUndefined) { - return YGResolveValue(trailingPosition, axisSize); + return YGResolveValue(*trailingPosition, axisSize); } } - const YGValue *trailingPosition = - YGComputedEdgeValue(node->style.position, trailing[axis], &YGValueUndefined); + const YGValue* trailingPosition = YGComputedEdgeValue( + node->getStyle().position, trailing[axis], &YGValueUndefined); - return trailingPosition->unit == YGUnitUndefined ? 0.0f - : YGResolveValue(trailingPosition, axisSize); + return trailingPosition->unit == YGUnitUndefined + ? 0.0f + : YGResolveValue(*trailingPosition, axisSize); } static float YGNodeBoundAxisWithinMinAndMax(const YGNodeRef node, @@ -1152,11 +1193,15 @@ static float YGNodeBoundAxisWithinMinAndMax(const YGNodeRef node, float max = YGUndefined; if (YGFlexDirectionIsColumn(axis)) { - min = YGResolveValue(&node->style.minDimensions[YGDimensionHeight], axisSize); - max = YGResolveValue(&node->style.maxDimensions[YGDimensionHeight], axisSize); + min = YGResolveValue( + node->getStyle().minDimensions[YGDimensionHeight], axisSize); + max = YGResolveValue( + node->getStyle().maxDimensions[YGDimensionHeight], axisSize); } else if (YGFlexDirectionIsRow(axis)) { - min = YGResolveValue(&node->style.minDimensions[YGDimensionWidth], axisSize); - max = YGResolveValue(&node->style.maxDimensions[YGDimensionWidth], axisSize); + min = YGResolveValue( + node->getStyle().minDimensions[YGDimensionWidth], axisSize); + max = YGResolveValue( + node->getStyle().maxDimensions[YGDimensionWidth], axisSize); } float boundValue = value; @@ -1172,22 +1217,6 @@ static float YGNodeBoundAxisWithinMinAndMax(const YGNodeRef node, return boundValue; } -static inline YGValue *YGMarginLeadingValue(const YGNodeRef node, const YGFlexDirection axis) { - if (YGFlexDirectionIsRow(axis) && node->style.margin[YGEdgeStart].unit != YGUnitUndefined) { - return &node->style.margin[YGEdgeStart]; - } else { - return &node->style.margin[leading[axis]]; - } -} - -static inline YGValue *YGMarginTrailingValue(const YGNodeRef node, const YGFlexDirection axis) { - if (YGFlexDirectionIsRow(axis) && node->style.margin[YGEdgeEnd].unit != YGUnitUndefined) { - return &node->style.margin[YGEdgeEnd]; - } else { - return &node->style.margin[trailing[axis]]; - } -} - // Like YGNodeBoundAxisWithinMinAndMax but also ensures that the value doesn't go // below the // padding and border amount. @@ -1203,9 +1232,11 @@ static inline float YGNodeBoundAxis(const YGNodeRef node, static void YGNodeSetChildTrailingPosition(const YGNodeRef node, const YGNodeRef child, const YGFlexDirection axis) { - const float size = child->layout.measuredDimensions[dim[axis]]; - child->layout.position[trailing[axis]] = - node->layout.measuredDimensions[dim[axis]] - size - child->layout.position[pos[axis]]; + const float size = child->getLayout().measuredDimensions[dim[axis]]; + child->setLayoutPosition( + node->getLayout().measuredDimensions[dim[axis]] - size - + child->getLayout().position[pos[axis]], + trailing[axis]); } // If both left and right are defined, then use left. Otherwise return @@ -1223,8 +1254,10 @@ static void YGConstrainMaxSizeForMode(const YGNodeRef node, const float parentWidth, YGMeasureMode *mode, float *size) { - const float maxSize = YGResolveValue(&node->style.maxDimensions[dim[axis]], parentAxisSize) + - YGNodeMarginForAxis(node, axis, parentWidth); + const float maxSize = + YGResolveValue( + node->getStyle().maxDimensions[dim[axis]], parentAxisSize) + + YGNodeMarginForAxis(node, axis, parentWidth); switch (*mode) { case YGMeasureModeExactly: case YGMeasureModeAtMost: @@ -1246,22 +1279,27 @@ static void YGNodeSetPosition(const YGNodeRef node, const float parentWidth) { /* Root nodes should be always layouted as LTR, so we don't return negative values. */ const YGDirection directionRespectingRoot = - node->parent != nullptr ? direction : YGDirectionLTR; - const YGFlexDirection mainAxis = - YGResolveFlexDirection(node->style.flexDirection, directionRespectingRoot); + node->getParent() != nullptr ? direction : YGDirectionLTR; + const YGFlexDirection mainAxis = YGResolveFlexDirection( + node->getStyle().flexDirection, directionRespectingRoot); const YGFlexDirection crossAxis = YGFlexDirectionCross(mainAxis, directionRespectingRoot); const float relativePositionMain = YGNodeRelativePosition(node, mainAxis, mainSize); const float relativePositionCross = YGNodeRelativePosition(node, crossAxis, crossSize); - node->layout.position[leading[mainAxis]] = - YGNodeLeadingMargin(node, mainAxis, parentWidth) + relativePositionMain; - node->layout.position[trailing[mainAxis]] = - YGNodeTrailingMargin(node, mainAxis, parentWidth) + relativePositionMain; - node->layout.position[leading[crossAxis]] = - YGNodeLeadingMargin(node, crossAxis, parentWidth) + relativePositionCross; - node->layout.position[trailing[crossAxis]] = - YGNodeTrailingMargin(node, crossAxis, parentWidth) + relativePositionCross; + node->setLayoutPosition( + YGNodeLeadingMargin(node, mainAxis, parentWidth) + relativePositionMain, + leading[mainAxis]); + node->setLayoutPosition( + YGNodeTrailingMargin(node, mainAxis, parentWidth) + relativePositionMain, + trailing[mainAxis]); + node->setLayoutPosition( + YGNodeLeadingMargin(node, crossAxis, parentWidth) + relativePositionCross, + leading[crossAxis]); + node->setLayoutPosition( + YGNodeTrailingMargin(node, crossAxis, parentWidth) + + relativePositionCross, + trailing[crossAxis]); } static void YGNodeComputeFlexBasisForChild(const YGNodeRef node, @@ -1274,7 +1312,8 @@ static void YGNodeComputeFlexBasisForChild(const YGNodeRef node, const YGMeasureMode heightMode, const YGDirection direction, const YGConfigRef config) { - const YGFlexDirection mainAxis = YGResolveFlexDirection(node->style.flexDirection, direction); + const YGFlexDirection mainAxis = + YGResolveFlexDirection(node->getStyle().flexDirection, direction); const bool isMainAxisRow = YGFlexDirectionIsRow(mainAxis); const float mainAxisSize = isMainAxisRow ? width : height; const float mainAxisParentSize = isMainAxisRow ? parentWidth : parentHeight; @@ -1285,28 +1324,34 @@ static void YGNodeComputeFlexBasisForChild(const YGNodeRef node, YGMeasureMode childHeightMeasureMode; const float resolvedFlexBasis = - YGResolveValue(YGNodeResolveFlexBasisPtr(child), mainAxisParentSize); + YGResolveValue(child->resolveFlexBasisPtr(), mainAxisParentSize); const bool isRowStyleDimDefined = YGNodeIsStyleDimDefined(child, YGFlexDirectionRow, parentWidth); const bool isColumnStyleDimDefined = YGNodeIsStyleDimDefined(child, YGFlexDirectionColumn, parentHeight); if (!YGFloatIsUndefined(resolvedFlexBasis) && !YGFloatIsUndefined(mainAxisSize)) { - if (YGFloatIsUndefined(child->layout.computedFlexBasis) || - (YGConfigIsExperimentalFeatureEnabled(child->config, YGExperimentalFeatureWebFlexBasis) && - child->layout.computedFlexBasisGeneration != gCurrentGenerationCount)) { - child->layout.computedFlexBasis = - fmaxf(resolvedFlexBasis, YGNodePaddingAndBorderForAxis(child, mainAxis, parentWidth)); + if (YGFloatIsUndefined(child->getLayout().computedFlexBasis) || + (YGConfigIsExperimentalFeatureEnabled( + child->getConfig(), YGExperimentalFeatureWebFlexBasis) && + child->getLayout().computedFlexBasisGeneration != + gCurrentGenerationCount)) { + child->setLayoutComputedFlexBasis(fmaxf( + resolvedFlexBasis, + YGNodePaddingAndBorderForAxis(child, mainAxis, parentWidth))); } } else if (isMainAxisRow && isRowStyleDimDefined) { // The width is definite, so use that as the flex basis. - child->layout.computedFlexBasis = - fmaxf(YGResolveValue(child->resolvedDimensions[YGDimensionWidth], parentWidth), - YGNodePaddingAndBorderForAxis(child, YGFlexDirectionRow, parentWidth)); + child->setLayoutComputedFlexBasis(fmaxf( + YGResolveValue( + child->getResolvedDimension(YGDimensionWidth), parentWidth), + YGNodePaddingAndBorderForAxis(child, YGFlexDirectionRow, parentWidth))); } else if (!isMainAxisRow && isColumnStyleDimDefined) { // The height is definite, so use that as the flex basis. - child->layout.computedFlexBasis = - fmaxf(YGResolveValue(child->resolvedDimensions[YGDimensionHeight], parentHeight), - YGNodePaddingAndBorderForAxis(child, YGFlexDirectionColumn, parentWidth)); + child->setLayoutComputedFlexBasis(fmaxf( + YGResolveValue( + child->getResolvedDimension(YGDimensionHeight), parentHeight), + YGNodePaddingAndBorderForAxis( + child, YGFlexDirectionColumn, parentWidth))); } else { // Compute the flex basis and hypothetical main size (i.e. the clamped // flex basis). @@ -1315,44 +1360,51 @@ static void YGNodeComputeFlexBasisForChild(const YGNodeRef node, childWidthMeasureMode = YGMeasureModeUndefined; childHeightMeasureMode = YGMeasureModeUndefined; - const float marginRow = YGNodeMarginForAxis(child, YGFlexDirectionRow, parentWidth); - const float marginColumn = YGNodeMarginForAxis(child, YGFlexDirectionColumn, parentWidth); + const float marginRow = + YGNodeMarginForAxis(child, YGFlexDirectionRow, parentWidth); + const float marginColumn = + YGNodeMarginForAxis(child, YGFlexDirectionColumn, parentWidth); if (isRowStyleDimDefined) { childWidth = - YGResolveValue(child->resolvedDimensions[YGDimensionWidth], parentWidth) + marginRow; + YGResolveValue( + child->getResolvedDimension(YGDimensionWidth), parentWidth) + + marginRow; childWidthMeasureMode = YGMeasureModeExactly; } if (isColumnStyleDimDefined) { childHeight = - YGResolveValue(child->resolvedDimensions[YGDimensionHeight], parentHeight) + marginColumn; + YGResolveValue( + child->getResolvedDimension(YGDimensionHeight), parentHeight) + + marginColumn; childHeightMeasureMode = YGMeasureModeExactly; } // The W3C spec doesn't say anything about the 'overflow' property, // but all major browsers appear to implement the following logic. - if ((!isMainAxisRow && node->style.overflow == YGOverflowScroll) || - node->style.overflow != YGOverflowScroll) { + if ((!isMainAxisRow && node->getStyle().overflow == YGOverflowScroll) || + node->getStyle().overflow != YGOverflowScroll) { if (YGFloatIsUndefined(childWidth) && !YGFloatIsUndefined(width)) { childWidth = width; childWidthMeasureMode = YGMeasureModeAtMost; } } - if ((isMainAxisRow && node->style.overflow == YGOverflowScroll) || - node->style.overflow != YGOverflowScroll) { + if ((isMainAxisRow && node->getStyle().overflow == YGOverflowScroll) || + node->getStyle().overflow != YGOverflowScroll) { if (YGFloatIsUndefined(childHeight) && !YGFloatIsUndefined(height)) { childHeight = height; childHeightMeasureMode = YGMeasureModeAtMost; } } - if (!YGFloatIsUndefined(child->style.aspectRatio)) { + if (!YGFloatIsUndefined(child->getStyle().aspectRatio)) { if (!isMainAxisRow && childWidthMeasureMode == YGMeasureModeExactly) { - childHeight = (childWidth - marginRow) / child->style.aspectRatio; + childHeight = (childWidth - marginRow) / child->getStyle().aspectRatio; childHeightMeasureMode = YGMeasureModeExactly; } else if (isMainAxisRow && childHeightMeasureMode == YGMeasureModeExactly) { - childWidth = (childHeight - marginColumn) * child->style.aspectRatio; + childWidth = + (childHeight - marginColumn) * child->getStyle().aspectRatio; childWidthMeasureMode = YGMeasureModeExactly; } } @@ -1367,8 +1419,8 @@ static void YGNodeComputeFlexBasisForChild(const YGNodeRef node, if (!isMainAxisRow && !isRowStyleDimDefined && hasExactWidth && childWidthStretch) { childWidth = width; childWidthMeasureMode = YGMeasureModeExactly; - if (!YGFloatIsUndefined(child->style.aspectRatio)) { - childHeight = (childWidth - marginRow) / child->style.aspectRatio; + if (!YGFloatIsUndefined(child->getStyle().aspectRatio)) { + childHeight = (childWidth - marginRow) / child->getStyle().aspectRatio; childHeightMeasureMode = YGMeasureModeExactly; } } @@ -1380,8 +1432,9 @@ static void YGNodeComputeFlexBasisForChild(const YGNodeRef node, childHeight = height; childHeightMeasureMode = YGMeasureModeExactly; - if (!YGFloatIsUndefined(child->style.aspectRatio)) { - childWidth = (childHeight - marginColumn) * child->style.aspectRatio; + if (!YGFloatIsUndefined(child->getStyle().aspectRatio)) { + childWidth = + (childHeight - marginColumn) * child->getStyle().aspectRatio; childWidthMeasureMode = YGMeasureModeExactly; } } @@ -1408,12 +1461,11 @@ static void YGNodeComputeFlexBasisForChild(const YGNodeRef node, "measure", config); - child->layout.computedFlexBasis = - fmaxf(child->layout.measuredDimensions[dim[mainAxis]], - YGNodePaddingAndBorderForAxis(child, mainAxis, parentWidth)); + child->setLayoutComputedFlexBasis(fmaxf( + child->getLayout().measuredDimensions[dim[mainAxis]], + YGNodePaddingAndBorderForAxis(child, mainAxis, parentWidth))); } - - child->layout.computedFlexBasisGeneration = gCurrentGenerationCount; + child->setLayoutComputedFlexBasisGeneration(gCurrentGenerationCount); } static void YGNodeAbsoluteLayoutChild(const YGNodeRef node, @@ -1423,7 +1475,8 @@ static void YGNodeAbsoluteLayoutChild(const YGNodeRef node, const float height, const YGDirection direction, const YGConfigRef config) { - const YGFlexDirection mainAxis = YGResolveFlexDirection(node->style.flexDirection, direction); + const YGFlexDirection mainAxis = + YGResolveFlexDirection(node->getStyle().flexDirection, direction); const YGFlexDirection crossAxis = YGFlexDirectionCross(mainAxis, direction); const bool isMainAxisRow = YGFlexDirectionIsRow(mainAxis); @@ -1436,36 +1489,39 @@ static void YGNodeAbsoluteLayoutChild(const YGNodeRef node, const float marginColumn = YGNodeMarginForAxis(child, YGFlexDirectionColumn, width); if (YGNodeIsStyleDimDefined(child, YGFlexDirectionRow, width)) { - childWidth = YGResolveValue(child->resolvedDimensions[YGDimensionWidth], width) + marginRow; + childWidth = + YGResolveValue(child->getResolvedDimension(YGDimensionWidth), width) + + marginRow; } else { // If the child doesn't have a specified width, compute the width based // on the left/right // offsets if they're defined. if (YGNodeIsLeadingPosDefined(child, YGFlexDirectionRow) && YGNodeIsTrailingPosDefined(child, YGFlexDirectionRow)) { - childWidth = node->layout.measuredDimensions[YGDimensionWidth] - - (YGNodeLeadingBorder(node, YGFlexDirectionRow) + - YGNodeTrailingBorder(node, YGFlexDirectionRow)) - - (YGNodeLeadingPosition(child, YGFlexDirectionRow, width) + - YGNodeTrailingPosition(child, YGFlexDirectionRow, width)); + childWidth = node->getLayout().measuredDimensions[YGDimensionWidth] - + (YGNodeLeadingBorder(node, YGFlexDirectionRow) + + YGNodeTrailingBorder(node, YGFlexDirectionRow)) - + (YGNodeLeadingPosition(child, YGFlexDirectionRow, width) + + YGNodeTrailingPosition(child, YGFlexDirectionRow, width)); childWidth = YGNodeBoundAxis(child, YGFlexDirectionRow, childWidth, width, width); } } if (YGNodeIsStyleDimDefined(child, YGFlexDirectionColumn, height)) { childHeight = - YGResolveValue(child->resolvedDimensions[YGDimensionHeight], height) + marginColumn; + YGResolveValue(child->getResolvedDimension(YGDimensionHeight), height) + + marginColumn; } else { // If the child doesn't have a specified height, compute the height // based on the top/bottom // offsets if they're defined. if (YGNodeIsLeadingPosDefined(child, YGFlexDirectionColumn) && YGNodeIsTrailingPosDefined(child, YGFlexDirectionColumn)) { - childHeight = node->layout.measuredDimensions[YGDimensionHeight] - - (YGNodeLeadingBorder(node, YGFlexDirectionColumn) + - YGNodeTrailingBorder(node, YGFlexDirectionColumn)) - - (YGNodeLeadingPosition(child, YGFlexDirectionColumn, height) + - YGNodeTrailingPosition(child, YGFlexDirectionColumn, height)); + childHeight = node->getLayout().measuredDimensions[YGDimensionHeight] - + (YGNodeLeadingBorder(node, YGFlexDirectionColumn) + + YGNodeTrailingBorder(node, YGFlexDirectionColumn)) - + (YGNodeLeadingPosition(child, YGFlexDirectionColumn, height) + + YGNodeTrailingPosition(child, YGFlexDirectionColumn, height)); childHeight = YGNodeBoundAxis(child, YGFlexDirectionColumn, childHeight, height, width); } } @@ -1473,11 +1529,13 @@ static void YGNodeAbsoluteLayoutChild(const YGNodeRef node, // Exactly one dimension needs to be defined for us to be able to do aspect ratio // calculation. One dimension being the anchor and the other being flexible. if (YGFloatIsUndefined(childWidth) ^ YGFloatIsUndefined(childHeight)) { - if (!YGFloatIsUndefined(child->style.aspectRatio)) { + if (!YGFloatIsUndefined(child->getStyle().aspectRatio)) { if (YGFloatIsUndefined(childWidth)) { - childWidth = marginRow + (childHeight - marginColumn) * child->style.aspectRatio; + childWidth = marginRow + + (childHeight - marginColumn) * child->getStyle().aspectRatio; } else if (YGFloatIsUndefined(childHeight)) { - childHeight = marginColumn + (childWidth - marginRow) / child->style.aspectRatio; + childHeight = marginColumn + + (childWidth - marginRow) / child->getStyle().aspectRatio; } } } @@ -1509,10 +1567,10 @@ static void YGNodeAbsoluteLayoutChild(const YGNodeRef node, false, "abs-measure", config); - childWidth = child->layout.measuredDimensions[YGDimensionWidth] + - YGNodeMarginForAxis(child, YGFlexDirectionRow, width); - childHeight = child->layout.measuredDimensions[YGDimensionHeight] + - YGNodeMarginForAxis(child, YGFlexDirectionColumn, width); + childWidth = child->getLayout().measuredDimensions[YGDimensionWidth] + + YGNodeMarginForAxis(child, YGFlexDirectionRow, width); + childHeight = child->getLayout().measuredDimensions[YGDimensionHeight] + + YGNodeMarginForAxis(child, YGFlexDirectionColumn, width); } YGLayoutNodeInternal(child, @@ -1528,40 +1586,57 @@ static void YGNodeAbsoluteLayoutChild(const YGNodeRef node, config); if (YGNodeIsTrailingPosDefined(child, mainAxis) && !YGNodeIsLeadingPosDefined(child, mainAxis)) { - child->layout.position[leading[mainAxis]] = - node->layout.measuredDimensions[dim[mainAxis]] - - child->layout.measuredDimensions[dim[mainAxis]] - YGNodeTrailingBorder(node, mainAxis) - - YGNodeTrailingMargin(child, mainAxis, width) - - YGNodeTrailingPosition(child, mainAxis, isMainAxisRow ? width : height); - } else if (!YGNodeIsLeadingPosDefined(child, mainAxis) && - node->style.justifyContent == YGJustifyCenter) { - child->layout.position[leading[mainAxis]] = (node->layout.measuredDimensions[dim[mainAxis]] - - child->layout.measuredDimensions[dim[mainAxis]]) / - 2.0f; - } else if (!YGNodeIsLeadingPosDefined(child, mainAxis) && - node->style.justifyContent == YGJustifyFlexEnd) { - child->layout.position[leading[mainAxis]] = (node->layout.measuredDimensions[dim[mainAxis]] - - child->layout.measuredDimensions[dim[mainAxis]]); + child->setLayoutPosition( + node->getLayout().measuredDimensions[dim[mainAxis]] - + child->getLayout().measuredDimensions[dim[mainAxis]] - + YGNodeTrailingBorder(node, mainAxis) - + YGNodeTrailingMargin(child, mainAxis, width) - + YGNodeTrailingPosition( + child, mainAxis, isMainAxisRow ? width : height), + leading[mainAxis]); + } else if ( + !YGNodeIsLeadingPosDefined(child, mainAxis) && + node->getStyle().justifyContent == YGJustifyCenter) { + child->setLayoutPosition( + (node->getLayout().measuredDimensions[dim[mainAxis]] - + child->getLayout().measuredDimensions[dim[mainAxis]]) / + 2.0f, + leading[mainAxis]); + } else if ( + !YGNodeIsLeadingPosDefined(child, mainAxis) && + node->getStyle().justifyContent == YGJustifyFlexEnd) { + child->setLayoutPosition( + (node->getLayout().measuredDimensions[dim[mainAxis]] - + child->getLayout().measuredDimensions[dim[mainAxis]]), + leading[mainAxis]); } if (YGNodeIsTrailingPosDefined(child, crossAxis) && !YGNodeIsLeadingPosDefined(child, crossAxis)) { - child->layout.position[leading[crossAxis]] = - node->layout.measuredDimensions[dim[crossAxis]] - - child->layout.measuredDimensions[dim[crossAxis]] - YGNodeTrailingBorder(node, crossAxis) - - YGNodeTrailingMargin(child, crossAxis, width) - - YGNodeTrailingPosition(child, crossAxis, isMainAxisRow ? height : width); + child->setLayoutPosition( + node->getLayout().measuredDimensions[dim[crossAxis]] - + child->getLayout().measuredDimensions[dim[crossAxis]] - + YGNodeTrailingBorder(node, crossAxis) - + YGNodeTrailingMargin(child, crossAxis, width) - + YGNodeTrailingPosition( + child, crossAxis, isMainAxisRow ? height : width), + leading[crossAxis]); + } else if (!YGNodeIsLeadingPosDefined(child, crossAxis) && YGNodeAlignItem(node, child) == YGAlignCenter) { - child->layout.position[leading[crossAxis]] = - (node->layout.measuredDimensions[dim[crossAxis]] - - child->layout.measuredDimensions[dim[crossAxis]]) / - 2.0f; - } else if (!YGNodeIsLeadingPosDefined(child, crossAxis) && - ((YGNodeAlignItem(node, child) == YGAlignFlexEnd) ^ - (node->style.flexWrap == YGWrapWrapReverse))) { - child->layout.position[leading[crossAxis]] = (node->layout.measuredDimensions[dim[crossAxis]] - - child->layout.measuredDimensions[dim[crossAxis]]); + child->setLayoutPosition( + (node->getLayout().measuredDimensions[dim[crossAxis]] - + child->getLayout().measuredDimensions[dim[crossAxis]]) / + 2.0f, + leading[crossAxis]); + } else if ( + !YGNodeIsLeadingPosDefined(child, crossAxis) && + ((YGNodeAlignItem(node, child) == YGAlignFlexEnd) ^ + (node->getStyle().flexWrap == YGWrapWrapReverse))) { + child->setLayoutPosition( + (node->getLayout().measuredDimensions[dim[crossAxis]] - + child->getLayout().measuredDimensions[dim[crossAxis]]), + leading[crossAxis]); } } @@ -1574,7 +1649,7 @@ static void YGNodeWithMeasureFuncSetMeasuredDimensions(const YGNodeRef node, const float parentHeight) { YGAssertWithNode( node, - node->measure != nullptr, + node->getMeasure() != nullptr, "Expected node to have custom measure function"); const float paddingAndBorderAxisRow = @@ -1595,33 +1670,50 @@ static void YGNodeWithMeasureFuncSetMeasuredDimensions(const YGNodeRef node, if (widthMeasureMode == YGMeasureModeExactly && heightMeasureMode == YGMeasureModeExactly) { // Don't bother sizing the text if both dimensions are already defined. - node->layout.measuredDimensions[YGDimensionWidth] = YGNodeBoundAxis( - node, YGFlexDirectionRow, availableWidth - marginAxisRow, parentWidth, parentWidth); - node->layout.measuredDimensions[YGDimensionHeight] = YGNodeBoundAxis( - node, YGFlexDirectionColumn, availableHeight - marginAxisColumn, parentHeight, parentWidth); + node->setLayoutMeasuredDimension( + YGNodeBoundAxis( + node, + YGFlexDirectionRow, + availableWidth - marginAxisRow, + parentWidth, + parentWidth), + YGDimensionWidth); + node->setLayoutMeasuredDimension( + YGNodeBoundAxis( + node, + YGFlexDirectionColumn, + availableHeight - marginAxisColumn, + parentHeight, + parentWidth), + YGDimensionHeight); } else { // Measure the text under the current constraints. - const YGSize measuredSize = - node->measure(node, innerWidth, widthMeasureMode, innerHeight, heightMeasureMode); - - node->layout.measuredDimensions[YGDimensionWidth] = - YGNodeBoundAxis(node, - YGFlexDirectionRow, - (widthMeasureMode == YGMeasureModeUndefined || - widthMeasureMode == YGMeasureModeAtMost) - ? measuredSize.width + paddingAndBorderAxisRow - : availableWidth - marginAxisRow, - parentWidth, - parentWidth); - node->layout.measuredDimensions[YGDimensionHeight] = - YGNodeBoundAxis(node, - YGFlexDirectionColumn, - (heightMeasureMode == YGMeasureModeUndefined || - heightMeasureMode == YGMeasureModeAtMost) - ? measuredSize.height + paddingAndBorderAxisColumn - : availableHeight - marginAxisColumn, - parentHeight, - parentWidth); + const YGSize measuredSize = node->getMeasure()( + node, innerWidth, widthMeasureMode, innerHeight, heightMeasureMode); + + node->setLayoutMeasuredDimension( + YGNodeBoundAxis( + node, + YGFlexDirectionRow, + (widthMeasureMode == YGMeasureModeUndefined || + widthMeasureMode == YGMeasureModeAtMost) + ? measuredSize.width + paddingAndBorderAxisRow + : availableWidth - marginAxisRow, + parentWidth, + parentWidth), + YGDimensionWidth); + + node->setLayoutMeasuredDimension( + YGNodeBoundAxis( + node, + YGFlexDirectionColumn, + (heightMeasureMode == YGMeasureModeUndefined || + heightMeasureMode == YGMeasureModeAtMost) + ? measuredSize.height + paddingAndBorderAxisColumn + : availableHeight - marginAxisColumn, + parentHeight, + parentWidth), + YGDimensionHeight); } } @@ -1641,24 +1733,29 @@ static void YGNodeEmptyContainerSetMeasuredDimensions(const YGNodeRef node, const float marginAxisRow = YGNodeMarginForAxis(node, YGFlexDirectionRow, parentWidth); const float marginAxisColumn = YGNodeMarginForAxis(node, YGFlexDirectionColumn, parentWidth); - node->layout.measuredDimensions[YGDimensionWidth] = - YGNodeBoundAxis(node, - YGFlexDirectionRow, - (widthMeasureMode == YGMeasureModeUndefined || - widthMeasureMode == YGMeasureModeAtMost) - ? paddingAndBorderAxisRow - : availableWidth - marginAxisRow, - parentWidth, - parentWidth); - node->layout.measuredDimensions[YGDimensionHeight] = - YGNodeBoundAxis(node, - YGFlexDirectionColumn, - (heightMeasureMode == YGMeasureModeUndefined || - heightMeasureMode == YGMeasureModeAtMost) - ? paddingAndBorderAxisColumn - : availableHeight - marginAxisColumn, - parentHeight, - parentWidth); + node->setLayoutMeasuredDimension( + YGNodeBoundAxis( + node, + YGFlexDirectionRow, + (widthMeasureMode == YGMeasureModeUndefined || + widthMeasureMode == YGMeasureModeAtMost) + ? paddingAndBorderAxisRow + : availableWidth - marginAxisRow, + parentWidth, + parentWidth), + YGDimensionWidth); + + node->setLayoutMeasuredDimension( + YGNodeBoundAxis( + node, + YGFlexDirectionColumn, + (heightMeasureMode == YGMeasureModeUndefined || + heightMeasureMode == YGMeasureModeAtMost) + ? paddingAndBorderAxisColumn + : availableHeight - marginAxisColumn, + parentHeight, + parentWidth), + YGDimensionHeight); } static bool YGNodeFixedSizeSetMeasuredDimensions(const YGNodeRef node, @@ -1674,26 +1771,31 @@ static bool YGNodeFixedSizeSetMeasuredDimensions(const YGNodeRef node, const float marginAxisColumn = YGNodeMarginForAxis(node, YGFlexDirectionColumn, parentWidth); const float marginAxisRow = YGNodeMarginForAxis(node, YGFlexDirectionRow, parentWidth); - node->layout.measuredDimensions[YGDimensionWidth] = - YGNodeBoundAxis(node, - YGFlexDirectionRow, - YGFloatIsUndefined(availableWidth) || - (widthMeasureMode == YGMeasureModeAtMost && availableWidth < 0.0f) - ? 0.0f - : availableWidth - marginAxisRow, - parentWidth, - parentWidth); - - node->layout.measuredDimensions[YGDimensionHeight] = - YGNodeBoundAxis(node, - YGFlexDirectionColumn, - YGFloatIsUndefined(availableHeight) || - (heightMeasureMode == YGMeasureModeAtMost && availableHeight < 0.0f) - ? 0.0f - : availableHeight - marginAxisColumn, - parentHeight, - parentWidth); - + node->setLayoutMeasuredDimension( + YGNodeBoundAxis( + node, + YGFlexDirectionRow, + YGFloatIsUndefined(availableWidth) || + (widthMeasureMode == YGMeasureModeAtMost && + availableWidth < 0.0f) + ? 0.0f + : availableWidth - marginAxisRow, + parentWidth, + parentWidth), + YGDimensionWidth); + + node->setLayoutMeasuredDimension( + YGNodeBoundAxis( + node, + YGFlexDirectionColumn, + YGFloatIsUndefined(availableHeight) || + (heightMeasureMode == YGMeasureModeAtMost && + availableHeight < 0.0f) + ? 0.0f + : availableHeight - marginAxisColumn, + parentHeight, + parentWidth), + YGDimensionHeight); return true; } @@ -1701,12 +1803,12 @@ static bool YGNodeFixedSizeSetMeasuredDimensions(const YGNodeRef node, } static void YGZeroOutLayoutRecursivly(const YGNodeRef node) { - memset(&(node->layout), 0, sizeof(YGLayout)); - node->hasNewLayout = true; + memset(&(node->getLayoutRef()), 0, sizeof(YGLayout)); + node->setHasNewLayout(true); YGCloneChildrenIfNeeded(node); const uint32_t childCount = YGNodeGetChildCount(node); for (uint32_t i = 0; i < childCount; i++) { - const YGNodeRef child = node->children[i]; + const YGNodeRef child = node->getChild(i); YGZeroOutLayoutRecursivly(child); } } @@ -1820,29 +1922,42 @@ static void YGNodelayoutImpl(const YGNodeRef node, // Set the resolved resolution in the node's layout. const YGDirection direction = YGNodeResolveDirection(node, parentDirection); - node->layout.direction = direction; + node->setLayoutDirection(direction); const YGFlexDirection flexRowDirection = YGResolveFlexDirection(YGFlexDirectionRow, direction); const YGFlexDirection flexColumnDirection = YGResolveFlexDirection(YGFlexDirectionColumn, direction); - node->layout.margin[YGEdgeStart] = YGNodeLeadingMargin(node, flexRowDirection, parentWidth); - node->layout.margin[YGEdgeEnd] = YGNodeTrailingMargin(node, flexRowDirection, parentWidth); - node->layout.margin[YGEdgeTop] = YGNodeLeadingMargin(node, flexColumnDirection, parentWidth); - node->layout.margin[YGEdgeBottom] = YGNodeTrailingMargin(node, flexColumnDirection, parentWidth); - - node->layout.border[YGEdgeStart] = YGNodeLeadingBorder(node, flexRowDirection); - node->layout.border[YGEdgeEnd] = YGNodeTrailingBorder(node, flexRowDirection); - node->layout.border[YGEdgeTop] = YGNodeLeadingBorder(node, flexColumnDirection); - node->layout.border[YGEdgeBottom] = YGNodeTrailingBorder(node, flexColumnDirection); - - node->layout.padding[YGEdgeStart] = YGNodeLeadingPadding(node, flexRowDirection, parentWidth); - node->layout.padding[YGEdgeEnd] = YGNodeTrailingPadding(node, flexRowDirection, parentWidth); - node->layout.padding[YGEdgeTop] = YGNodeLeadingPadding(node, flexColumnDirection, parentWidth); - node->layout.padding[YGEdgeBottom] = - YGNodeTrailingPadding(node, flexColumnDirection, parentWidth); - - if (node->measure) { + node->setLayoutMargin( + YGNodeLeadingMargin(node, flexRowDirection, parentWidth), YGEdgeStart); + node->setLayoutMargin( + YGNodeTrailingMargin(node, flexRowDirection, parentWidth), YGEdgeEnd); + node->setLayoutMargin( + YGNodeLeadingMargin(node, flexColumnDirection, parentWidth), YGEdgeTop); + node->setLayoutMargin( + YGNodeTrailingMargin(node, flexColumnDirection, parentWidth), + YGEdgeBottom); + + node->setLayoutBorder( + YGNodeLeadingBorder(node, flexRowDirection), YGEdgeStart); + node->setLayoutBorder( + YGNodeTrailingBorder(node, flexRowDirection), YGEdgeEnd); + node->setLayoutBorder( + YGNodeLeadingBorder(node, flexColumnDirection), YGEdgeTop); + node->setLayoutBorder( + YGNodeTrailingBorder(node, flexColumnDirection), YGEdgeBottom); + + node->setLayoutPadding( + YGNodeLeadingPadding(node, flexRowDirection, parentWidth), YGEdgeStart); + node->setLayoutPadding( + YGNodeTrailingPadding(node, flexRowDirection, parentWidth), YGEdgeEnd); + node->setLayoutPadding( + YGNodeLeadingPadding(node, flexColumnDirection, parentWidth), YGEdgeTop); + node->setLayoutPadding( + YGNodeTrailingPadding(node, flexColumnDirection, parentWidth), + YGEdgeBottom); + + if (node->getMeasure() != nullptr) { YGNodeWithMeasureFuncSetMeasuredDimensions(node, availableWidth, availableHeight, @@ -1853,7 +1968,7 @@ static void YGNodelayoutImpl(const YGNodeRef node, return; } - const uint32_t childCount = node->children.size(); + const uint32_t childCount = node->getChildren().size(); if (childCount == 0) { YGNodeEmptyContainerSetMeasuredDimensions(node, availableWidth, @@ -1881,14 +1996,15 @@ static void YGNodelayoutImpl(const YGNodeRef node, YGCloneChildrenIfNeeded(node); // Reset layout flags, as they could have changed. - node->layout.hadOverflow = false; + node->setLayoutHadOverflow(false); // STEP 1: CALCULATE VALUES FOR REMAINDER OF ALGORITHM - const YGFlexDirection mainAxis = YGResolveFlexDirection(node->style.flexDirection, direction); + const YGFlexDirection mainAxis = + YGResolveFlexDirection(node->getStyle().flexDirection, direction); const YGFlexDirection crossAxis = YGFlexDirectionCross(mainAxis, direction); const bool isMainAxisRow = YGFlexDirectionIsRow(mainAxis); - const YGJustify justifyContent = node->style.justifyContent; - const bool isNodeFlexWrap = node->style.flexWrap != YGWrapNoWrap; + const YGJustify justifyContent = node->getStyle().justifyContent; + const bool isNodeFlexWrap = node->getStyle().flexWrap != YGWrapNoWrap; const float mainAxisParentSize = isMainAxisRow ? parentWidth : parentHeight; const float crossAxisParentSize = isMainAxisRow ? parentHeight : parentWidth; @@ -1919,16 +2035,20 @@ static void YGNodelayoutImpl(const YGNodeRef node, // STEP 2: DETERMINE AVAILABLE SIZE IN MAIN AND CROSS DIRECTIONS const float minInnerWidth = - YGResolveValue(&node->style.minDimensions[YGDimensionWidth], parentWidth) - + YGResolveValue( + node->getStyle().minDimensions[YGDimensionWidth], parentWidth) - paddingAndBorderAxisRow; const float maxInnerWidth = - YGResolveValue(&node->style.maxDimensions[YGDimensionWidth], parentWidth) - + YGResolveValue( + node->getStyle().maxDimensions[YGDimensionWidth], parentWidth) - paddingAndBorderAxisRow; const float minInnerHeight = - YGResolveValue(&node->style.minDimensions[YGDimensionHeight], parentHeight) - + YGResolveValue( + node->getStyle().minDimensions[YGDimensionHeight], parentHeight) - paddingAndBorderAxisColumn; const float maxInnerHeight = - YGResolveValue(&node->style.maxDimensions[YGDimensionHeight], parentHeight) - + YGResolveValue( + node->getStyle().maxDimensions[YGDimensionHeight], parentHeight) - paddingAndBorderAxisColumn; const float minInnerMainDim = isMainAxisRow ? minInnerWidth : minInnerHeight; const float maxInnerMainDim = isMainAxisRow ? maxInnerWidth : maxInnerHeight; @@ -1973,14 +2093,14 @@ static void YGNodelayoutImpl(const YGNodeRef node, // STEP 3: DETERMINE FLEX BASIS FOR EACH ITEM for (uint32_t i = 0; i < childCount; i++) { - const YGNodeRef child = node->children[i]; - if (child->style.display == YGDisplayNone) { + const YGNodeRef child = node->getChild(i); + if (child->getStyle().display == YGDisplayNone) { YGZeroOutLayoutRecursivly(child); - child->hasNewLayout = true; - child->isDirty = false; + child->setHasNewLayout(true); + child->setDirty(false); continue; } - YGResolveDimensions(child); + child->resolveDimension(); if (performLayout) { // Set the initial position (relative to the parent). const YGDirection childDirection = YGNodeResolveDirection(child, direction); @@ -1993,21 +2113,21 @@ static void YGNodelayoutImpl(const YGNodeRef node, // Absolute-positioned children don't participate in flex layout. Add them // to a list that we can process later. - if (child->style.positionType == YGPositionTypeAbsolute) { + if (child->getStyle().positionType == YGPositionTypeAbsolute) { // Store a private linked list of absolutely positioned children // so that we can efficiently traverse them later. if (firstAbsoluteChild == nullptr) { firstAbsoluteChild = child; } if (currentAbsoluteChild != nullptr) { - currentAbsoluteChild->nextChild = child; + currentAbsoluteChild->setNextChild(child); } currentAbsoluteChild = child; - child->nextChild = nullptr; + child->setNextChild(nullptr); } else { if (child == singleFlexChild) { - child->layout.computedFlexBasisGeneration = gCurrentGenerationCount; - child->layout.computedFlexBasis = 0; + child->setLayoutComputedFlexBasisGeneration(gCurrentGenerationCount); + child->setLayoutComputedFlexBasis(0); } else { YGNodeComputeFlexBasisForChild(node, child, @@ -2022,8 +2142,8 @@ static void YGNodelayoutImpl(const YGNodeRef node, } } - totalOuterFlexBasis += - child->layout.computedFlexBasis + YGNodeMarginForAxis(child, mainAxis, availableInnerWidth); + totalOuterFlexBasis += child->getLayout().computedFlexBasis + + YGNodeMarginForAxis(child, mainAxis, availableInnerWidth); ; } @@ -2072,20 +2192,24 @@ static void YGNodelayoutImpl(const YGNodeRef node, // Add items to the current line until it's full or we run out of items. for (uint32_t i = startOfLineIndex; i < childCount; i++, endOfLineIndex++) { - const YGNodeRef child = node->children[i]; - if (child->style.display == YGDisplayNone) { + const YGNodeRef child = node->getChild(i); + if (child->getStyle().display == YGDisplayNone) { continue; } - child->lineIndex = lineCount; + child->setLineIndex(lineCount); - if (child->style.positionType != YGPositionTypeAbsolute) { + if (child->getStyle().positionType != YGPositionTypeAbsolute) { const float childMarginMainAxis = YGNodeMarginForAxis(child, mainAxis, availableInnerWidth); - const float flexBasisWithMaxConstraints = - fminf(YGResolveValue(&child->style.maxDimensions[dim[mainAxis]], mainAxisParentSize), - child->layout.computedFlexBasis); - const float flexBasisWithMinAndMaxConstraints = - fmaxf(YGResolveValue(&child->style.minDimensions[dim[mainAxis]], mainAxisParentSize), - flexBasisWithMaxConstraints); + const float flexBasisWithMaxConstraints = fminf( + YGResolveValue( + child->getStyle().maxDimensions[dim[mainAxis]], + mainAxisParentSize), + child->getLayout().computedFlexBasis); + const float flexBasisWithMinAndMaxConstraints = fmaxf( + YGResolveValue( + child->getStyle().minDimensions[dim[mainAxis]], + mainAxisParentSize), + flexBasisWithMaxConstraints); // If this is a multi-line flow and this item pushes us over the // available size, we've @@ -2107,8 +2231,8 @@ static void YGNodelayoutImpl(const YGNodeRef node, totalFlexGrowFactors += YGResolveFlexGrow(child); // Unlike the grow factor, the shrink factor is scaled relative to the child dimension. - totalFlexShrinkScaledFactors += - -YGNodeResolveFlexShrink(child) * child->layout.computedFlexBasis; + totalFlexShrinkScaledFactors += -YGNodeResolveFlexShrink(child) * + child->getLayout().computedFlexBasis; } // Store a private linked list of children that need to be layed out. @@ -2116,10 +2240,10 @@ static void YGNodelayoutImpl(const YGNodeRef node, firstRelativeChild = child; } if (currentRelativeChild != nullptr) { - currentRelativeChild->nextChild = child; + currentRelativeChild->setNextChild(child); } currentRelativeChild = child; - child->nextChild = nullptr; + child->setNextChild(nullptr); } } @@ -2157,13 +2281,13 @@ static void YGNodelayoutImpl(const YGNodeRef node, sizeConsumedOnCurrentLine > maxInnerMainDim) { availableInnerMainDim = maxInnerMainDim; } else { - if (!node->config->useLegacyStretchBehaviour && + if (!node->getConfig()->useLegacyStretchBehaviour && (totalFlexGrowFactors == 0 || YGResolveFlexGrow(node) == 0)) { // If we don't have any children to flex or we can't flex the node itself, // space we've used is all space we need. Root node also should be shrunk to minimum availableInnerMainDim = sizeConsumedOnCurrentLine; } - sizeBasedOnContent = !node->config->useLegacyStretchBehaviour; + sizeBasedOnContent = !node->getConfig()->useLegacyStretchBehaviour; } } @@ -2215,12 +2339,16 @@ static void YGNodelayoutImpl(const YGNodeRef node, float deltaFlexGrowFactors = 0; currentRelativeChild = firstRelativeChild; while (currentRelativeChild != nullptr) { - childFlexBasis = - fminf(YGResolveValue(¤tRelativeChild->style.maxDimensions[dim[mainAxis]], - mainAxisParentSize), - fmaxf(YGResolveValue(¤tRelativeChild->style.minDimensions[dim[mainAxis]], - mainAxisParentSize), - currentRelativeChild->layout.computedFlexBasis)); + childFlexBasis = fminf( + YGResolveValue( + currentRelativeChild->getStyle().maxDimensions[dim[mainAxis]], + mainAxisParentSize), + fmaxf( + YGResolveValue( + currentRelativeChild->getStyle() + .minDimensions[dim[mainAxis]], + mainAxisParentSize), + currentRelativeChild->getLayout().computedFlexBasis)); if (remainingFreeSpace < 0) { flexShrinkScaledFactor = -YGNodeResolveFlexShrink(currentRelativeChild) * childFlexBasis; @@ -2272,7 +2400,7 @@ static void YGNodelayoutImpl(const YGNodeRef node, } } - currentRelativeChild = currentRelativeChild->nextChild; + currentRelativeChild = currentRelativeChild->getNextChild(); } totalFlexShrinkScaledFactors += deltaFlexShrinkScaledFactors; @@ -2283,12 +2411,16 @@ static void YGNodelayoutImpl(const YGNodeRef node, deltaFreeSpace = 0; currentRelativeChild = firstRelativeChild; while (currentRelativeChild != nullptr) { - childFlexBasis = - fminf(YGResolveValue(¤tRelativeChild->style.maxDimensions[dim[mainAxis]], - mainAxisParentSize), - fmaxf(YGResolveValue(¤tRelativeChild->style.minDimensions[dim[mainAxis]], - mainAxisParentSize), - currentRelativeChild->layout.computedFlexBasis)); + childFlexBasis = fminf( + YGResolveValue( + currentRelativeChild->getStyle().maxDimensions[dim[mainAxis]], + mainAxisParentSize), + fmaxf( + YGResolveValue( + currentRelativeChild->getStyle() + .minDimensions[dim[mainAxis]], + mainAxisParentSize), + currentRelativeChild->getLayout().computedFlexBasis)); float updatedMainSize = childFlexBasis; if (remainingFreeSpace < 0) { @@ -2338,23 +2470,25 @@ static void YGNodelayoutImpl(const YGNodeRef node, YGMeasureMode childCrossMeasureMode; YGMeasureMode childMainMeasureMode = YGMeasureModeExactly; - if (!YGFloatIsUndefined(currentRelativeChild->style.aspectRatio)) { - childCrossSize = - isMainAxisRow - ? (childMainSize - marginMain) / currentRelativeChild->style.aspectRatio - : (childMainSize - marginMain) * currentRelativeChild->style.aspectRatio; + if (!YGFloatIsUndefined(currentRelativeChild->getStyle().aspectRatio)) { + childCrossSize = isMainAxisRow ? (childMainSize - marginMain) / + currentRelativeChild->getStyle().aspectRatio + : (childMainSize - marginMain) * + currentRelativeChild->getStyle().aspectRatio; childCrossMeasureMode = YGMeasureModeExactly; childCrossSize += marginCross; - } else if (!YGFloatIsUndefined(availableInnerCrossDim) && - !YGNodeIsStyleDimDefined(currentRelativeChild, - crossAxis, - availableInnerCrossDim) && - measureModeCrossDim == YGMeasureModeExactly && - !(isNodeFlexWrap && flexBasisOverflows) && - YGNodeAlignItem(node, currentRelativeChild) == YGAlignStretch && - YGMarginLeadingValue(currentRelativeChild, crossAxis)->unit != YGUnitAuto && - YGMarginTrailingValue(currentRelativeChild, crossAxis)->unit != YGUnitAuto) { + } else if ( + !YGFloatIsUndefined(availableInnerCrossDim) && + !YGNodeIsStyleDimDefined( + currentRelativeChild, crossAxis, availableInnerCrossDim) && + measureModeCrossDim == YGMeasureModeExactly && + !(isNodeFlexWrap && flexBasisOverflows) && + YGNodeAlignItem(node, currentRelativeChild) == YGAlignStretch && + currentRelativeChild->marginLeadingValue(crossAxis).unit != + YGUnitAuto && + currentRelativeChild->marginTrailingValue(crossAxis).unit != + YGUnitAuto) { childCrossSize = availableInnerCrossDim; childCrossMeasureMode = YGMeasureModeExactly; } else if (!YGNodeIsStyleDimDefined(currentRelativeChild, @@ -2364,35 +2498,44 @@ static void YGNodelayoutImpl(const YGNodeRef node, childCrossMeasureMode = YGFloatIsUndefined(childCrossSize) ? YGMeasureModeUndefined : YGMeasureModeAtMost; } else { - childCrossSize = YGResolveValue(currentRelativeChild->resolvedDimensions[dim[crossAxis]], - availableInnerCrossDim) + - marginCross; + childCrossSize = + YGResolveValue( + currentRelativeChild->getResolvedDimension(dim[crossAxis]), + availableInnerCrossDim) + + marginCross; const bool isLoosePercentageMeasurement = - currentRelativeChild->resolvedDimensions[dim[crossAxis]]->unit == YGUnitPercent && + currentRelativeChild->getResolvedDimension(dim[crossAxis]).unit == + YGUnitPercent && measureModeCrossDim != YGMeasureModeExactly; - childCrossMeasureMode = YGFloatIsUndefined(childCrossSize) || isLoosePercentageMeasurement - ? YGMeasureModeUndefined - : YGMeasureModeExactly; + childCrossMeasureMode = + YGFloatIsUndefined(childCrossSize) || isLoosePercentageMeasurement + ? YGMeasureModeUndefined + : YGMeasureModeExactly; } - YGConstrainMaxSizeForMode(currentRelativeChild, - mainAxis, - availableInnerMainDim, - availableInnerWidth, - &childMainMeasureMode, - &childMainSize); - YGConstrainMaxSizeForMode(currentRelativeChild, - crossAxis, - availableInnerCrossDim, - availableInnerWidth, - &childCrossMeasureMode, - &childCrossSize); + YGConstrainMaxSizeForMode( + currentRelativeChild, + mainAxis, + availableInnerMainDim, + availableInnerWidth, + &childMainMeasureMode, + &childMainSize); + YGConstrainMaxSizeForMode( + currentRelativeChild, + crossAxis, + availableInnerCrossDim, + availableInnerWidth, + &childCrossMeasureMode, + &childCrossSize); const bool requiresStretchLayout = - !YGNodeIsStyleDimDefined(currentRelativeChild, crossAxis, availableInnerCrossDim) && + !YGNodeIsStyleDimDefined( + currentRelativeChild, crossAxis, availableInnerCrossDim) && YGNodeAlignItem(node, currentRelativeChild) == YGAlignStretch && - YGMarginLeadingValue(currentRelativeChild, crossAxis)->unit != YGUnitAuto && - YGMarginTrailingValue(currentRelativeChild, crossAxis)->unit != YGUnitAuto; + currentRelativeChild->marginLeadingValue(crossAxis).unit != + YGUnitAuto && + currentRelativeChild->marginTrailingValue(crossAxis).unit != + YGUnitAuto; const float childWidth = isMainAxisRow ? childMainSize : childCrossSize; const float childHeight = !isMainAxisRow ? childMainSize : childCrossSize; @@ -2415,14 +2558,16 @@ static void YGNodelayoutImpl(const YGNodeRef node, performLayout && !requiresStretchLayout, "flex", config); - node->layout.hadOverflow |= currentRelativeChild->layout.hadOverflow; - - currentRelativeChild = currentRelativeChild->nextChild; + node->setLayoutHadOverflow( + node->getLayout().hadOverflow | + currentRelativeChild->getLayout().hadOverflow); + currentRelativeChild = currentRelativeChild->getNextChild(); } } remainingFreeSpace = originalRemainingFreeSpace + deltaFreeSpace; - node->layout.hadOverflow |= (remainingFreeSpace < 0); + node->setLayoutHadOverflow( + node->getLayout().hadOverflow | (remainingFreeSpace < 0)); // STEP 6: MAIN-AXIS JUSTIFICATION & CROSS-AXIS SIZE DETERMINATION @@ -2437,12 +2582,17 @@ static void YGNodelayoutImpl(const YGNodeRef node, // constraint by the min size defined for the main axis. if (measureModeMainDim == YGMeasureModeAtMost && remainingFreeSpace > 0) { - if (node->style.minDimensions[dim[mainAxis]].unit != YGUnitUndefined && - YGResolveValue(&node->style.minDimensions[dim[mainAxis]], mainAxisParentSize) >= 0) { - remainingFreeSpace = - fmaxf(0, - YGResolveValue(&node->style.minDimensions[dim[mainAxis]], mainAxisParentSize) - - (availableInnerMainDim - remainingFreeSpace)); + if (node->getStyle().minDimensions[dim[mainAxis]].unit != + YGUnitUndefined && + YGResolveValue( + node->getStyle().minDimensions[dim[mainAxis]], + mainAxisParentSize) >= 0) { + remainingFreeSpace = fmaxf( + 0, + YGResolveValue( + node->getStyle().minDimensions[dim[mainAxis]], + mainAxisParentSize) - + (availableInnerMainDim - remainingFreeSpace)); } else { remainingFreeSpace = 0; } @@ -2450,12 +2600,12 @@ static void YGNodelayoutImpl(const YGNodeRef node, int numberOfAutoMarginsOnCurrentLine = 0; for (uint32_t i = startOfLineIndex; i < endOfLineIndex; i++) { - const YGNodeRef child = node->children[i]; - if (child->style.positionType == YGPositionTypeRelative) { - if (YGMarginLeadingValue(child, mainAxis)->unit == YGUnitAuto) { + const YGNodeRef child = node->getChild(i); + if (child->getStyle().positionType == YGPositionTypeRelative) { + if (child->marginLeadingValue(mainAxis).unit == YGUnitAuto) { numberOfAutoMarginsOnCurrentLine++; } - if (YGMarginTrailingValue(child, mainAxis)->unit == YGUnitAuto) { + if (child->marginTrailingValue(mainAxis).unit == YGUnitAuto) { numberOfAutoMarginsOnCurrentLine++; } } @@ -2495,35 +2645,38 @@ static void YGNodelayoutImpl(const YGNodeRef node, float crossDim = 0; for (uint32_t i = startOfLineIndex; i < endOfLineIndex; i++) { - const YGNodeRef child = node->children[i]; - if (child->style.display == YGDisplayNone) { + const YGNodeRef child = node->getChild(i); + if (child->getStyle().display == YGDisplayNone) { continue; } - if (child->style.positionType == YGPositionTypeAbsolute && + if (child->getStyle().positionType == YGPositionTypeAbsolute && YGNodeIsLeadingPosDefined(child, mainAxis)) { if (performLayout) { // In case the child is position absolute and has left/top being // defined, we override the position to whatever the user said // (and margin/border). - child->layout.position[pos[mainAxis]] = + child->setLayoutPosition( YGNodeLeadingPosition(child, mainAxis, availableInnerMainDim) + - YGNodeLeadingBorder(node, mainAxis) + - YGNodeLeadingMargin(child, mainAxis, availableInnerWidth); + YGNodeLeadingBorder(node, mainAxis) + + YGNodeLeadingMargin(child, mainAxis, availableInnerWidth), + pos[mainAxis]); } } else { // Now that we placed the element, we need to update the variables. // We need to do that only for relative elements. Absolute elements // do not take part in that phase. - if (child->style.positionType == YGPositionTypeRelative) { - if (YGMarginLeadingValue(child, mainAxis)->unit == YGUnitAuto) { + if (child->getStyle().positionType == YGPositionTypeRelative) { + if (child->marginLeadingValue(mainAxis).unit == YGUnitAuto) { mainDim += remainingFreeSpace / numberOfAutoMarginsOnCurrentLine; } if (performLayout) { - child->layout.position[pos[mainAxis]] += mainDim; + child->setLayoutPosition( + child->getLayout().position[pos[mainAxis]] + mainDim, + pos[mainAxis]); } - if (YGMarginTrailingValue(child, mainAxis)->unit == YGUnitAuto) { + if (child->marginTrailingValue(mainAxis).unit == YGUnitAuto) { mainDim += remainingFreeSpace / numberOfAutoMarginsOnCurrentLine; } @@ -2531,8 +2684,9 @@ static void YGNodelayoutImpl(const YGNodeRef node, // If we skipped the flex step, then we can't rely on the // measuredDims because // they weren't computed. This means we can't call YGNodeDimWithMargin. - mainDim += betweenMainDim + YGNodeMarginForAxis(child, mainAxis, availableInnerWidth) + - child->layout.computedFlexBasis; + mainDim += betweenMainDim + + YGNodeMarginForAxis(child, mainAxis, availableInnerWidth) + + child->getLayout().computedFlexBasis; crossDim = availableInnerCrossDim; } else { // The main dimension is the sum of all the elements dimension plus the spacing. @@ -2543,8 +2697,10 @@ static void YGNodelayoutImpl(const YGNodeRef node, crossDim = fmaxf(crossDim, YGNodeDimWithMargin(child, crossAxis, availableInnerWidth)); } } else if (performLayout) { - child->layout.position[pos[mainAxis]] += - YGNodeLeadingBorder(node, mainAxis) + leadingMainDim; + child->setLayoutPosition( + child->getLayout().position[pos[mainAxis]] + + YGNodeLeadingBorder(node, mainAxis) + leadingMainDim, + pos[mainAxis]); } } } @@ -2580,27 +2736,31 @@ static void YGNodelayoutImpl(const YGNodeRef node, // We can skip child alignment if we're just measuring the container. if (performLayout) { for (uint32_t i = startOfLineIndex; i < endOfLineIndex; i++) { - const YGNodeRef child = node->children[i]; - if (child->style.display == YGDisplayNone) { + const YGNodeRef child = node->getChild(i); + if (child->getStyle().display == YGDisplayNone) { continue; } - if (child->style.positionType == YGPositionTypeAbsolute) { + if (child->getStyle().positionType == YGPositionTypeAbsolute) { // If the child is absolutely positioned and has a // top/left/bottom/right // set, override all the previously computed positions to set it // correctly. const bool isChildLeadingPosDefined = YGNodeIsLeadingPosDefined(child, crossAxis); if (isChildLeadingPosDefined) { - child->layout.position[pos[crossAxis]] = - YGNodeLeadingPosition(child, crossAxis, availableInnerCrossDim) + - YGNodeLeadingBorder(node, crossAxis) + - YGNodeLeadingMargin(child, crossAxis, availableInnerWidth); + child->setLayoutPosition( + YGNodeLeadingPosition( + child, crossAxis, availableInnerCrossDim) + + YGNodeLeadingBorder(node, crossAxis) + + YGNodeLeadingMargin(child, crossAxis, availableInnerWidth), + pos[crossAxis]); } // If leading position is not defined or calculations result in Nan, default to border + margin - if (!isChildLeadingPosDefined || YGFloatIsUndefined(child->layout.position[pos[crossAxis]])) { - child->layout.position[pos[crossAxis]] = + if (!isChildLeadingPosDefined || + YGFloatIsUndefined(child->getLayout().position[pos[crossAxis]])) { + child->setLayoutPosition( YGNodeLeadingBorder(node, crossAxis) + - YGNodeLeadingMargin(child, crossAxis, availableInnerWidth); + YGNodeLeadingMargin(child, crossAxis, availableInnerWidth), + pos[crossAxis]); } } else { float leadingCrossDim = leadingPaddingAndBorderCross; @@ -2615,18 +2775,21 @@ static void YGNodelayoutImpl(const YGNodeRef node, // forcing the cross-axis size to be the computed cross size for the // current line. if (alignItem == YGAlignStretch && - YGMarginLeadingValue(child, crossAxis)->unit != YGUnitAuto && - YGMarginTrailingValue(child, crossAxis)->unit != YGUnitAuto) { + child->marginLeadingValue(crossAxis).unit != YGUnitAuto && + child->marginTrailingValue(crossAxis).unit != YGUnitAuto) { // If the child defines a definite size for its cross axis, there's // no need to stretch. if (!YGNodeIsStyleDimDefined(child, crossAxis, availableInnerCrossDim)) { - float childMainSize = child->layout.measuredDimensions[dim[mainAxis]]; + float childMainSize = + child->getLayout().measuredDimensions[dim[mainAxis]]; float childCrossSize = - !YGFloatIsUndefined(child->style.aspectRatio) - ? ((YGNodeMarginForAxis(child, crossAxis, availableInnerWidth) + - (isMainAxisRow ? childMainSize / child->style.aspectRatio - : childMainSize * child->style.aspectRatio))) - : crossDim; + !YGFloatIsUndefined(child->getStyle().aspectRatio) + ? ((YGNodeMarginForAxis( + child, crossAxis, availableInnerWidth) + + (isMainAxisRow + ? childMainSize / child->getStyle().aspectRatio + : childMainSize * child->getStyle().aspectRatio))) + : crossDim; childMainSize += YGNodeMarginForAxis(child, mainAxis, availableInnerWidth); @@ -2649,32 +2812,37 @@ static void YGNodelayoutImpl(const YGNodeRef node, const float childHeight = !isMainAxisRow ? childMainSize : childCrossSize; const YGMeasureMode childWidthMeasureMode = - YGFloatIsUndefined(childWidth) ? YGMeasureModeUndefined : YGMeasureModeExactly; + YGFloatIsUndefined(childWidth) ? YGMeasureModeUndefined + : YGMeasureModeExactly; const YGMeasureMode childHeightMeasureMode = - YGFloatIsUndefined(childHeight) ? YGMeasureModeUndefined : YGMeasureModeExactly; - - YGLayoutNodeInternal(child, - childWidth, - childHeight, - direction, - childWidthMeasureMode, - childHeightMeasureMode, - availableInnerWidth, - availableInnerHeight, - true, - "stretch", - config); + YGFloatIsUndefined(childHeight) ? YGMeasureModeUndefined + : YGMeasureModeExactly; + + YGLayoutNodeInternal( + child, + childWidth, + childHeight, + direction, + childWidthMeasureMode, + childHeightMeasureMode, + availableInnerWidth, + availableInnerHeight, + true, + "stretch", + config); } } else { - const float remainingCrossDim = - containerCrossAxis - YGNodeDimWithMargin(child, crossAxis, availableInnerWidth); + const float remainingCrossDim = containerCrossAxis - + YGNodeDimWithMargin(child, crossAxis, availableInnerWidth); - if (YGMarginLeadingValue(child, crossAxis)->unit == YGUnitAuto && - YGMarginTrailingValue(child, crossAxis)->unit == YGUnitAuto) { + if (child->marginLeadingValue(crossAxis).unit == YGUnitAuto && + child->marginTrailingValue(crossAxis).unit == YGUnitAuto) { leadingCrossDim += fmaxf(0.0f, remainingCrossDim / 2); - } else if (YGMarginTrailingValue(child, crossAxis)->unit == YGUnitAuto) { + } else if ( + child->marginTrailingValue(crossAxis).unit == YGUnitAuto) { // No-Op - } else if (YGMarginLeadingValue(child, crossAxis)->unit == YGUnitAuto) { + } else if ( + child->marginLeadingValue(crossAxis).unit == YGUnitAuto) { leadingCrossDim += fmaxf(0.0f, remainingCrossDim); } else if (alignItem == YGAlignFlexStart) { // No-Op @@ -2685,7 +2853,10 @@ static void YGNodelayoutImpl(const YGNodeRef node, } } // And we apply the position - child->layout.position[pos[crossAxis]] += totalLineCrossDim + leadingCrossDim; + child->setLayoutPosition( + child->getLayout().position[pos[crossAxis]] + totalLineCrossDim + + leadingCrossDim, + pos[crossAxis]); } } } @@ -2702,7 +2873,7 @@ static void YGNodelayoutImpl(const YGNodeRef node, float crossDimLead = 0; float currentLead = leadingPaddingAndBorderCross; - switch (node->style.alignContent) { + switch (node->getStyle().alignContent) { case YGAlignFlexEnd: currentLead += remainingAlignContentDim; break; @@ -2745,26 +2916,29 @@ static void YGNodelayoutImpl(const YGNodeRef node, float maxAscentForCurrentLine = 0; float maxDescentForCurrentLine = 0; for (ii = startIndex; ii < childCount; ii++) { - const YGNodeRef child = node->children[ii]; - if (child->style.display == YGDisplayNone) { + const YGNodeRef child = node->getChild(ii); + if (child->getStyle().display == YGDisplayNone) { continue; } - if (child->style.positionType == YGPositionTypeRelative) { - if (child->lineIndex != i) { + if (child->getStyle().positionType == YGPositionTypeRelative) { + if (child->getLineIndex() != i) { break; } if (YGNodeIsLayoutDimDefined(child, crossAxis)) { - lineHeight = fmaxf(lineHeight, - child->layout.measuredDimensions[dim[crossAxis]] + - YGNodeMarginForAxis(child, crossAxis, availableInnerWidth)); + lineHeight = fmaxf( + lineHeight, + child->getLayout().measuredDimensions[dim[crossAxis]] + + YGNodeMarginForAxis(child, crossAxis, availableInnerWidth)); } if (YGNodeAlignItem(node, child) == YGAlignBaseline) { const float ascent = YGBaseline(child) + YGNodeLeadingMargin(child, YGFlexDirectionColumn, availableInnerWidth); const float descent = - child->layout.measuredDimensions[YGDimensionHeight] + - YGNodeMarginForAxis(child, YGFlexDirectionColumn, availableInnerWidth) - ascent; + child->getLayout().measuredDimensions[YGDimensionHeight] + + YGNodeMarginForAxis( + child, YGFlexDirectionColumn, availableInnerWidth) - + ascent; maxAscentForCurrentLine = fmaxf(maxAscentForCurrentLine, ascent); maxDescentForCurrentLine = fmaxf(maxDescentForCurrentLine, descent); lineHeight = fmaxf(lineHeight, maxAscentForCurrentLine + maxDescentForCurrentLine); @@ -2776,51 +2950,70 @@ static void YGNodelayoutImpl(const YGNodeRef node, if (performLayout) { for (ii = startIndex; ii < endIndex; ii++) { - const YGNodeRef child = node->children[ii]; - if (child->style.display == YGDisplayNone) { + const YGNodeRef child = node->getChild(ii); + if (child->getStyle().display == YGDisplayNone) { continue; } - if (child->style.positionType == YGPositionTypeRelative) { + if (child->getStyle().positionType == YGPositionTypeRelative) { switch (YGNodeAlignItem(node, child)) { case YGAlignFlexStart: { - child->layout.position[pos[crossAxis]] = - currentLead + YGNodeLeadingMargin(child, crossAxis, availableInnerWidth); + child->setLayoutPosition( + currentLead + + YGNodeLeadingMargin( + child, crossAxis, availableInnerWidth), + pos[crossAxis]); break; } case YGAlignFlexEnd: { - child->layout.position[pos[crossAxis]] = + child->setLayoutPosition( currentLead + lineHeight - - YGNodeTrailingMargin(child, crossAxis, availableInnerWidth) - - child->layout.measuredDimensions[dim[crossAxis]]; + YGNodeTrailingMargin( + child, crossAxis, availableInnerWidth) - + child->getLayout().measuredDimensions[dim[crossAxis]], + pos[crossAxis]); break; } case YGAlignCenter: { - float childHeight = child->layout.measuredDimensions[dim[crossAxis]]; - child->layout.position[pos[crossAxis]] = - currentLead + (lineHeight - childHeight) / 2; + float childHeight = + child->getLayout().measuredDimensions[dim[crossAxis]]; + + child->setLayoutPosition( + currentLead + (lineHeight - childHeight) / 2, + pos[crossAxis]); break; } case YGAlignStretch: { - child->layout.position[pos[crossAxis]] = - currentLead + YGNodeLeadingMargin(child, crossAxis, availableInnerWidth); + child->setLayoutPosition( + currentLead + + YGNodeLeadingMargin( + child, crossAxis, availableInnerWidth), + pos[crossAxis]); // Remeasure child with the line height as it as been only measured with the // parents height yet. if (!YGNodeIsStyleDimDefined(child, crossAxis, availableInnerCrossDim)) { - const float childWidth = - isMainAxisRow ? (child->layout.measuredDimensions[YGDimensionWidth] + - YGNodeMarginForAxis(child, mainAxis, availableInnerWidth)) - : lineHeight; - - const float childHeight = - !isMainAxisRow ? (child->layout.measuredDimensions[YGDimensionHeight] + - YGNodeMarginForAxis(child, crossAxis, availableInnerWidth)) - : lineHeight; - - if (!(YGFloatsEqual(childWidth, - child->layout.measuredDimensions[YGDimensionWidth]) && - YGFloatsEqual(childHeight, - child->layout.measuredDimensions[YGDimensionHeight]))) { + const float childWidth = isMainAxisRow + ? (child->getLayout() + .measuredDimensions[YGDimensionWidth] + + YGNodeMarginForAxis( + child, mainAxis, availableInnerWidth)) + : lineHeight; + + const float childHeight = !isMainAxisRow + ? (child->getLayout() + .measuredDimensions[YGDimensionHeight] + + YGNodeMarginForAxis( + child, crossAxis, availableInnerWidth)) + : lineHeight; + + if (!(YGFloatsEqual( + childWidth, + child->getLayout() + .measuredDimensions[YGDimensionWidth]) && + YGFloatsEqual( + childHeight, + child->getLayout() + .measuredDimensions[YGDimensionHeight]))) { YGLayoutNodeInternal(child, childWidth, childHeight, @@ -2837,9 +3030,14 @@ static void YGNodelayoutImpl(const YGNodeRef node, break; } case YGAlignBaseline: { - child->layout.position[YGEdgeTop] = + child->setLayoutPosition( currentLead + maxAscentForCurrentLine - YGBaseline(child) + - YGNodeLeadingPosition(child, YGFlexDirectionColumn, availableInnerCrossDim); + YGNodeLeadingPosition( + child, + YGFlexDirectionColumn, + availableInnerCrossDim), + YGEdgeTop); + break; } case YGAlignAuto: @@ -2856,56 +3054,91 @@ static void YGNodelayoutImpl(const YGNodeRef node, } // STEP 9: COMPUTING FINAL DIMENSIONS - node->layout.measuredDimensions[YGDimensionWidth] = YGNodeBoundAxis( - node, YGFlexDirectionRow, availableWidth - marginAxisRow, parentWidth, parentWidth); - node->layout.measuredDimensions[YGDimensionHeight] = YGNodeBoundAxis( - node, YGFlexDirectionColumn, availableHeight - marginAxisColumn, parentHeight, parentWidth); + + node->setLayoutMeasuredDimension( + YGNodeBoundAxis( + node, + YGFlexDirectionRow, + availableWidth - marginAxisRow, + parentWidth, + parentWidth), + YGDimensionWidth); + + node->setLayoutMeasuredDimension( + YGNodeBoundAxis( + node, + YGFlexDirectionColumn, + availableHeight - marginAxisColumn, + parentHeight, + parentWidth), + YGDimensionHeight); // If the user didn't specify a width or height for the node, set the // dimensions based on the children. if (measureModeMainDim == YGMeasureModeUndefined || - (node->style.overflow != YGOverflowScroll && measureModeMainDim == YGMeasureModeAtMost)) { + (node->getStyle().overflow != YGOverflowScroll && + measureModeMainDim == YGMeasureModeAtMost)) { // Clamp the size to the min/max size, if specified, and make sure it // doesn't go below the padding and border amount. - node->layout.measuredDimensions[dim[mainAxis]] = - YGNodeBoundAxis(node, mainAxis, maxLineMainDim, mainAxisParentSize, parentWidth); - } else if (measureModeMainDim == YGMeasureModeAtMost && - node->style.overflow == YGOverflowScroll) { - node->layout.measuredDimensions[dim[mainAxis]] = fmaxf( - fminf(availableInnerMainDim + paddingAndBorderAxisMain, - YGNodeBoundAxisWithinMinAndMax(node, mainAxis, maxLineMainDim, mainAxisParentSize)), - paddingAndBorderAxisMain); + node->setLayoutMeasuredDimension( + YGNodeBoundAxis( + node, mainAxis, maxLineMainDim, mainAxisParentSize, parentWidth), + dim[mainAxis]); + + } else if ( + measureModeMainDim == YGMeasureModeAtMost && + node->getStyle().overflow == YGOverflowScroll) { + node->setLayoutMeasuredDimension( + fmaxf( + fminf( + availableInnerMainDim + paddingAndBorderAxisMain, + YGNodeBoundAxisWithinMinAndMax( + node, mainAxis, maxLineMainDim, mainAxisParentSize)), + paddingAndBorderAxisMain), + dim[mainAxis]); } if (measureModeCrossDim == YGMeasureModeUndefined || - (node->style.overflow != YGOverflowScroll && measureModeCrossDim == YGMeasureModeAtMost)) { + (node->getStyle().overflow != YGOverflowScroll && + measureModeCrossDim == YGMeasureModeAtMost)) { // Clamp the size to the min/max size, if specified, and make sure it // doesn't go below the padding and border amount. - node->layout.measuredDimensions[dim[crossAxis]] = - YGNodeBoundAxis(node, - crossAxis, - totalLineCrossDim + paddingAndBorderAxisCross, - crossAxisParentSize, - parentWidth); - } else if (measureModeCrossDim == YGMeasureModeAtMost && - node->style.overflow == YGOverflowScroll) { - node->layout.measuredDimensions[dim[crossAxis]] = - fmaxf(fminf(availableInnerCrossDim + paddingAndBorderAxisCross, - YGNodeBoundAxisWithinMinAndMax(node, - crossAxis, - totalLineCrossDim + paddingAndBorderAxisCross, - crossAxisParentSize)), - paddingAndBorderAxisCross); + + node->setLayoutMeasuredDimension( + YGNodeBoundAxis( + node, + crossAxis, + totalLineCrossDim + paddingAndBorderAxisCross, + crossAxisParentSize, + parentWidth), + dim[crossAxis]); + + } else if ( + measureModeCrossDim == YGMeasureModeAtMost && + node->getStyle().overflow == YGOverflowScroll) { + node->setLayoutMeasuredDimension( + fmaxf( + fminf( + availableInnerCrossDim + paddingAndBorderAxisCross, + YGNodeBoundAxisWithinMinAndMax( + node, + crossAxis, + totalLineCrossDim + paddingAndBorderAxisCross, + crossAxisParentSize)), + paddingAndBorderAxisCross), + dim[crossAxis]); } // As we only wrapped in normal direction yet, we need to reverse the positions on wrap-reverse. - if (performLayout && node->style.flexWrap == YGWrapWrapReverse) { + if (performLayout && node->getStyle().flexWrap == YGWrapWrapReverse) { for (uint32_t i = 0; i < childCount; i++) { const YGNodeRef child = YGNodeGetChild(node, i); - if (child->style.positionType == YGPositionTypeRelative) { - child->layout.position[pos[crossAxis]] = node->layout.measuredDimensions[dim[crossAxis]] - - child->layout.position[pos[crossAxis]] - - child->layout.measuredDimensions[dim[crossAxis]]; + if (child->getStyle().positionType == YGPositionTypeRelative) { + child->setLayoutPosition( + node->getLayout().measuredDimensions[dim[crossAxis]] - + child->getLayout().position[pos[crossAxis]] - + child->getLayout().measuredDimensions[dim[crossAxis]], + pos[crossAxis]); } } } @@ -2914,7 +3147,7 @@ static void YGNodelayoutImpl(const YGNodeRef node, // STEP 10: SIZING AND POSITIONING ABSOLUTE CHILDREN for (currentAbsoluteChild = firstAbsoluteChild; currentAbsoluteChild != nullptr; - currentAbsoluteChild = currentAbsoluteChild->nextChild) { + currentAbsoluteChild = currentAbsoluteChild->getNextChild()) { YGNodeAbsoluteLayoutChild(node, currentAbsoluteChild, availableInnerWidth, @@ -2933,8 +3166,8 @@ static void YGNodelayoutImpl(const YGNodeRef node, // Set trailing position if necessary. if (needsMainTrailingPos || needsCrossTrailingPos) { for (uint32_t i = 0; i < childCount; i++) { - const YGNodeRef child = node->children[i]; - if (child->style.display == YGDisplayNone) { + const YGNodeRef child = node->getChild(i); + if (child->getStyle().display == YGDisplayNone) { continue; } if (needsMainTrailingPos) { @@ -3108,12 +3341,12 @@ bool YGLayoutNodeInternal(const YGNodeRef node, const bool performLayout, const char *reason, const YGConfigRef config) { - YGLayout *layout = &node->layout; + YGLayout* layout = &node->getLayoutRef(); gDepth++; const bool needToVisitNode = - (node->isDirty && layout->generationCount != gCurrentGenerationCount) || + (node->isDirty() && layout->generationCount != gCurrentGenerationCount) || layout->lastParentDirection != parentDirection; if (needToVisitNode) { @@ -3139,7 +3372,7 @@ bool YGLayoutNodeInternal(const YGNodeRef node, // most // expensive to measure, so it's worth avoiding redundant measurements if at // all possible. - if (node->measure) { + if (node->getMeasure() != nullptr) { const float marginAxisRow = YGNodeMarginForAxis(node, YGFlexDirectionRow, parentWidth); const float marginAxisColumn = YGNodeMarginForAxis(node, YGFlexDirectionColumn, parentWidth); @@ -3204,8 +3437,8 @@ bool YGLayoutNodeInternal(const YGNodeRef node, if (gPrintChanges && gPrintSkips) { YGLog(node, YGLogLevelVerbose, "%s%d.{[skipped] ", YGSpacer(gDepth), gDepth); - if (node->print) { - node->print(node); + if (node->getPrintFunc() != nullptr) { + node->getPrintFunc()(node); } YGLog( node, @@ -3228,8 +3461,8 @@ bool YGLayoutNodeInternal(const YGNodeRef node, YGSpacer(gDepth), gDepth, needToVisitNode ? "*" : ""); - if (node->print) { - node->print(node); + if (node->getPrintFunc() != nullptr) { + node->getPrintFunc()(node); } YGLog( node, @@ -3261,8 +3494,8 @@ bool YGLayoutNodeInternal(const YGNodeRef node, YGSpacer(gDepth), gDepth, needToVisitNode ? "*" : ""); - if (node->print) { - node->print(node); + if (node->getPrintFunc() != nullptr) { + node->getPrintFunc()(node); } YGLog( node, @@ -3305,10 +3538,15 @@ bool YGLayoutNodeInternal(const YGNodeRef node, } if (performLayout) { - node->layout.dimensions[YGDimensionWidth] = node->layout.measuredDimensions[YGDimensionWidth]; - node->layout.dimensions[YGDimensionHeight] = node->layout.measuredDimensions[YGDimensionHeight]; - node->hasNewLayout = true; - node->isDirty = false; + node->setLayoutDimension( + node->getLayout().measuredDimensions[YGDimensionWidth], + YGDimensionWidth); + node->setLayoutDimension( + node->getLayout().measuredDimensions[YGDimensionHeight], + YGDimensionHeight); + + node->setHasNewLayout(true); + node->setDirty(false); } gDepth--; @@ -3336,11 +3574,11 @@ static void YGRoundToPixelGrid(const YGNodeRef node, return; } - const float nodeLeft = node->layout.position[YGEdgeLeft]; - const float nodeTop = node->layout.position[YGEdgeTop]; + const float nodeLeft = node->getLayout().position[YGEdgeLeft]; + const float nodeTop = node->getLayout().position[YGEdgeTop]; - const float nodeWidth = node->layout.dimensions[YGDimensionWidth]; - const float nodeHeight = node->layout.dimensions[YGDimensionHeight]; + const float nodeWidth = node->getLayout().dimensions[YGDimensionWidth]; + const float nodeHeight = node->getLayout().dimensions[YGDimensionHeight]; const float absoluteNodeLeft = absoluteLeft + nodeLeft; const float absoluteNodeTop = absoluteTop + nodeTop; @@ -3350,12 +3588,15 @@ static void YGRoundToPixelGrid(const YGNodeRef node, // If a node has a custom measure function we never want to round down its size as this could // lead to unwanted text truncation. - const bool textRounding = node->nodeType == YGNodeTypeText; + const bool textRounding = node->getNodeType() == YGNodeTypeText; + + node->setLayoutPosition( + YGRoundValueToPixelGrid(nodeLeft, pointScaleFactor, false, textRounding), + YGEdgeLeft); - node->layout.position[YGEdgeLeft] = - YGRoundValueToPixelGrid(nodeLeft, pointScaleFactor, false, textRounding); - node->layout.position[YGEdgeTop] = - YGRoundValueToPixelGrid(nodeTop, pointScaleFactor, false, textRounding); + node->setLayoutPosition( + YGRoundValueToPixelGrid(nodeTop, pointScaleFactor, false, textRounding), + YGEdgeTop); // We multiply dimension by scale factor and if the result is close to the whole number, we don't // have any fraction @@ -3365,20 +3606,27 @@ static void YGRoundToPixelGrid(const YGNodeRef node, const bool hasFractionalHeight = !YGFloatsEqual(fmodf(nodeHeight * pointScaleFactor, 1.0), 0) && !YGFloatsEqual(fmodf(nodeHeight * pointScaleFactor, 1.0), 1.0); - node->layout.dimensions[YGDimensionWidth] = - YGRoundValueToPixelGrid(absoluteNodeRight, - pointScaleFactor, - (textRounding && hasFractionalWidth), - (textRounding && !hasFractionalWidth)) - - YGRoundValueToPixelGrid(absoluteNodeLeft, pointScaleFactor, false, textRounding); - node->layout.dimensions[YGDimensionHeight] = - YGRoundValueToPixelGrid(absoluteNodeBottom, - pointScaleFactor, - (textRounding && hasFractionalHeight), - (textRounding && !hasFractionalHeight)) - - YGRoundValueToPixelGrid(absoluteNodeTop, pointScaleFactor, false, textRounding); - - const uint32_t childCount = node->children.size(); + node->setLayoutDimension( + YGRoundValueToPixelGrid( + absoluteNodeRight, + pointScaleFactor, + (textRounding && hasFractionalWidth), + (textRounding && !hasFractionalWidth)) - + YGRoundValueToPixelGrid( + absoluteNodeLeft, pointScaleFactor, false, textRounding), + YGDimensionWidth); + + node->setLayoutDimension( + YGRoundValueToPixelGrid( + absoluteNodeBottom, + pointScaleFactor, + (textRounding && hasFractionalHeight), + (textRounding && !hasFractionalHeight)) - + YGRoundValueToPixelGrid( + absoluteNodeTop, pointScaleFactor, false, textRounding), + YGDimensionHeight); + + const uint32_t childCount = node->getChildren().size(); for (uint32_t i = 0; i < childCount; i++) { YGRoundToPixelGrid(YGNodeGetChild(node, i), pointScaleFactor, absoluteNodeLeft, absoluteNodeTop); } @@ -3395,16 +3643,21 @@ void YGNodeCalculateLayout(const YGNodeRef node, // parameters don't change. gCurrentGenerationCount++; - YGResolveDimensions(node); - + node->resolveDimension(); float width = YGUndefined; YGMeasureMode widthMeasureMode = YGMeasureModeUndefined; if (YGNodeIsStyleDimDefined(node, YGFlexDirectionRow, parentWidth)) { - width = YGResolveValue(node->resolvedDimensions[dim[YGFlexDirectionRow]], parentWidth) + - YGNodeMarginForAxis(node, YGFlexDirectionRow, parentWidth); + width = + YGResolveValue( + node->getResolvedDimension(dim[YGFlexDirectionRow]), parentWidth) + + YGNodeMarginForAxis(node, YGFlexDirectionRow, parentWidth); widthMeasureMode = YGMeasureModeExactly; - } else if (YGResolveValue(&node->style.maxDimensions[YGDimensionWidth], parentWidth) >= 0.0f) { - width = YGResolveValue(&node->style.maxDimensions[YGDimensionWidth], parentWidth); + } else if ( + YGResolveValue( + node->getStyle().maxDimensions[YGDimensionWidth], parentWidth) >= + 0.0f) { + width = YGResolveValue( + node->getStyle().maxDimensions[YGDimensionWidth], parentWidth); widthMeasureMode = YGMeasureModeAtMost; } else { width = parentWidth; @@ -3414,30 +3667,42 @@ void YGNodeCalculateLayout(const YGNodeRef node, float height = YGUndefined; YGMeasureMode heightMeasureMode = YGMeasureModeUndefined; if (YGNodeIsStyleDimDefined(node, YGFlexDirectionColumn, parentHeight)) { - height = YGResolveValue(node->resolvedDimensions[dim[YGFlexDirectionColumn]], parentHeight) + - YGNodeMarginForAxis(node, YGFlexDirectionColumn, parentWidth); + height = YGResolveValue( + node->getResolvedDimension(dim[YGFlexDirectionColumn]), + parentHeight) + + YGNodeMarginForAxis(node, YGFlexDirectionColumn, parentWidth); heightMeasureMode = YGMeasureModeExactly; - } else if (YGResolveValue(&node->style.maxDimensions[YGDimensionHeight], parentHeight) >= 0.0f) { - height = YGResolveValue(&node->style.maxDimensions[YGDimensionHeight], parentHeight); + } else if ( + YGResolveValue( + node->getStyle().maxDimensions[YGDimensionHeight], parentHeight) >= + 0.0f) { + height = YGResolveValue( + node->getStyle().maxDimensions[YGDimensionHeight], parentHeight); heightMeasureMode = YGMeasureModeAtMost; } else { height = parentHeight; heightMeasureMode = YGFloatIsUndefined(height) ? YGMeasureModeUndefined : YGMeasureModeExactly; } - if (YGLayoutNodeInternal(node, - width, - height, - parentDirection, - widthMeasureMode, - heightMeasureMode, - parentWidth, - parentHeight, - true, - "initial", - node->config)) { - YGNodeSetPosition(node, node->layout.direction, parentWidth, parentHeight, parentWidth); - YGRoundToPixelGrid(node, node->config->pointScaleFactor, 0.0f, 0.0f); + if (YGLayoutNodeInternal( + node, + width, + height, + parentDirection, + widthMeasureMode, + heightMeasureMode, + parentWidth, + parentHeight, + true, + "initial", + node->getConfig())) { + YGNodeSetPosition( + node, + node->getLayout().direction, + parentWidth, + parentHeight, + parentWidth); + YGRoundToPixelGrid(node, node->getConfig()->pointScaleFactor, 0.0f, 0.0f); if (gPrintTree) { YGNodePrint( @@ -3484,7 +3749,8 @@ void YGLogWithConfig(const YGConfigRef config, YGLogLevel level, const char *for void YGLog(const YGNodeRef node, YGLogLevel level, const char *format, ...) { va_list args; va_start(args, format); - YGVLog(node == nullptr ? nullptr : node->config, node, level, format, args); + YGVLog( + node == nullptr ? nullptr : node->getConfig(), node, level, format, args); va_end(args); } diff --git a/ReactCommon/yoga/yoga/Yoga.h b/ReactCommon/yoga/yoga/Yoga.h index fe5df6272a2513..90f1f5fc05608c 100644 --- a/ReactCommon/yoga/yoga/Yoga.h +++ b/ReactCommon/yoga/yoga/Yoga.h @@ -43,11 +43,13 @@ typedef struct YGValue { YGUnit unit; } YGValue; -static const YGValue YGValueUndefined = {YGUndefined, YGUnitUndefined}; -static const YGValue YGValueAuto = {YGUndefined, YGUnitAuto}; +extern const YGValue YGValueUndefined; +extern const YGValue YGValueAuto; typedef struct YGConfig *YGConfigRef; -typedef struct YGNode *YGNodeRef; + +typedef struct YGNode* YGNodeRef; + typedef YGSize (*YGMeasureFunc)(YGNodeRef node, float width, YGMeasureMode widthMode, @@ -95,7 +97,6 @@ WIN_EXPORT void YGNodeCalculateLayout(const YGNodeRef node, // depends on information not known to YG they must perform this dirty // marking manually. WIN_EXPORT void YGNodeMarkDirty(const YGNodeRef node); -WIN_EXPORT bool YGNodeIsDirty(const YGNodeRef node); WIN_EXPORT void YGNodePrint(const YGNodeRef node, const YGPrintOptions options); @@ -158,12 +159,19 @@ WIN_EXPORT void YGNodeCopyStyle(const YGNodeRef dstNode, const YGNodeRef srcNode #define YG_NODE_LAYOUT_EDGE_PROPERTY(type, name) \ WIN_EXPORT type YGNodeLayoutGet##name(const YGNodeRef node, const YGEdge edge); -YG_NODE_PROPERTY(void *, Context, context); -YG_NODE_PROPERTY(YGMeasureFunc, MeasureFunc, measureFunc); -YG_NODE_PROPERTY(YGBaselineFunc, BaselineFunc, baselineFunc) -YG_NODE_PROPERTY(YGPrintFunc, PrintFunc, printFunc); -YG_NODE_PROPERTY(bool, HasNewLayout, hasNewLayout); -YG_NODE_PROPERTY(YGNodeType, NodeType, nodeType); +void* YGNodeGetContext(YGNodeRef node); +void YGNodeSetContext(YGNodeRef node, void* context); +YGMeasureFunc YGNodeGetMeasureFunc(YGNodeRef node); +void YGNodeSetMeasureFunc(YGNodeRef node, YGMeasureFunc measureFunc); +YGBaselineFunc YGNodeGetBaselineFunc(YGNodeRef node); +void YGNodeSetBaselineFunc(YGNodeRef node, YGBaselineFunc baselineFunc); +YGPrintFunc YGNodeGetPrintFunc(YGNodeRef node); +void YGNodeSetPrintFunc(YGNodeRef node, YGPrintFunc printFunc); +bool YGNodeGetHasNewLayout(YGNodeRef node); +void YGNodeSetHasNewLayout(YGNodeRef node, bool hasNewLayout); +YGNodeType YGNodeGetNodeType(YGNodeRef node); +void YGNodeSetNodeType(YGNodeRef node, YGNodeType nodeType); +bool YGNodeIsDirty(YGNodeRef node); YG_NODE_STYLE_PROPERTY(YGDirection, Direction, direction); YG_NODE_STYLE_PROPERTY(YGFlexDirection, FlexDirection, flexDirection);