From ee2d86ca8118a576606d3d81cfcc44401c577bfe Mon Sep 17 00:00:00 2001 From: heoblitz Date: Fri, 14 Jun 2024 21:28:09 +0900 Subject: [PATCH 01/11] Add position static --- Sources/Swift/FlexLayout.swift | 6 ++++-- Sources/Swift/Impl/FlexLayout+Enum.swift | 2 ++ 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/Sources/Swift/FlexLayout.swift b/Sources/Swift/FlexLayout.swift index 5aa9901e..ccf0d47a 100644 --- a/Sources/Swift/FlexLayout.swift +++ b/Sources/Swift/FlexLayout.swift @@ -1424,10 +1424,12 @@ public final class Flex { /** */ public enum Position { - /// Default value. + /// Default value. Positioned according to the flex container's flow. The item offset is positioned using properties top, bottom, left, right, start, end. case relative - /// Positioned absolutely in regards to its container. The item is positionned using properties top, bottom, left, right, start, end. + /// Positioned absolutely, removed from the flex container's flow. The item is positioned using properties top, bottom, left, right, start, end. case absolute + /// Positioned like relative but ignores insets. + case `static` } /** diff --git a/Sources/Swift/Impl/FlexLayout+Enum.swift b/Sources/Swift/Impl/FlexLayout+Enum.swift index 92cf296a..e6db952f 100644 --- a/Sources/Swift/Impl/FlexLayout+Enum.swift +++ b/Sources/Swift/Impl/FlexLayout+Enum.swift @@ -53,6 +53,7 @@ extension YGWrap { extension YGPositionType { static let relative = YGPositionTypeRelative static let absolute = YGPositionTypeAbsolute + static let `static` = YGPositionTypeStatic } extension YGDirection { @@ -149,6 +150,7 @@ extension Flex.Position { switch self { case .relative: return YGPositionType.relative case .absolute: return YGPositionType.absolute + case .static: return YGPositionType.static } } } From fe28ae10dec406a15765212a9fae53eee983042b Mon Sep 17 00:00:00 2001 From: heoblitz Date: Sat, 15 Jun 2024 11:51:18 +0900 Subject: [PATCH 02/11] Update position comment --- Sources/Swift/FlexLayout.swift | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/Sources/Swift/FlexLayout.swift b/Sources/Swift/FlexLayout.swift index ccf0d47a..ea5b6f55 100644 --- a/Sources/Swift/FlexLayout.swift +++ b/Sources/Swift/FlexLayout.swift @@ -545,7 +545,7 @@ public final class Flex { } // - // MARK: Absolute positionning + // MARK: Position / Insets // /** @@ -581,7 +581,6 @@ public final class Flex { /** Set the top edge distance from the container top edge in pixels. - This method is valid only when the item position is absolute (`view.flex.position(.absolute)`) */ @discardableResult public func top(_ value: CGFloat) -> Flex { @@ -1424,11 +1423,11 @@ public final class Flex { /** */ public enum Position { - /// Default value. Positioned according to the flex container's flow. The item offset is positioned using properties top, bottom, left, right, start, end. + /// Default value. Positioned according to the flex container's flow. The item is positioned using Insets properties (top, bottom, left, right, start, end) from its normal position within its flex container and will take up space within the flex container. This node will always form a containing block. case relative - /// Positioned absolutely, removed from the flex container's flow. The item is positioned using properties top, bottom, left, right, start, end. + /// Positioned absolutely, removed from the flex container's flow. The item is positioned using Insets properties (top, bottom, left, right, start, end). Insets will offset the node from its containing block. case absolute - /// Positioned like relative but ignores insets. + /// Positioned like relative but ignores insets and will not form a containing block. case `static` } From b06718fb8fcacb0434cb43e369bd386fa9960d8e Mon Sep 17 00:00:00 2001 From: heoblitz Date: Sat, 15 Jun 2024 12:15:15 +0900 Subject: [PATCH 03/11] Update inset comment --- Sources/Swift/FlexLayout.swift | 53 +++++++++++++++++++--------------- 1 file changed, 30 insertions(+), 23 deletions(-) diff --git a/Sources/Swift/FlexLayout.swift b/Sources/Swift/FlexLayout.swift index ea5b6f55..ffcb949f 100644 --- a/Sources/Swift/FlexLayout.swift +++ b/Sources/Swift/FlexLayout.swift @@ -545,7 +545,7 @@ public final class Flex { } // - // MARK: Position / Insets + // MARK: Position / Inset // /** @@ -561,7 +561,7 @@ public final class Flex { /** Set the left edge distance from the container left edge in pixels. - This method is valid only when the item position is absolute (`view.flex.position(.absolute)`) + This method is valid only when the item position is absolute or relative. It is not valid when the position is static. */ @discardableResult public func left(_ value: CGFloat) -> Flex { @@ -571,7 +571,7 @@ public final class Flex { /** Set the left edge distance from the container left edge in percentage of its container width. - This method is valid only when the item position is absolute (`view.flex.position(.absolute)`) + This method is valid only when the item position is absolute or relative. It is not valid when the position is static. */ @discardableResult public func left(_ percent: FPercent) -> Flex { @@ -581,6 +581,7 @@ public final class Flex { /** Set the top edge distance from the container top edge in pixels. + This method is valid only when the item position is absolute or relative. It is not valid when the position is static. */ @discardableResult public func top(_ value: CGFloat) -> Flex { @@ -590,7 +591,7 @@ public final class Flex { /** Set the top edge distance from the container top edge in percentage of its container height. - This method is valid only when the item position is absolute (`view.flex.position(.absolute)`) + This method is valid only when the item position is absolute or relative. It is not valid when the position is static. */ @discardableResult public func top(_ percent: FPercent) -> Flex { @@ -600,7 +601,7 @@ public final class Flex { /** Set the right edge distance from the container right edge in pixels. - This method is valid only when the item position is absolute (`view.flex.position(.absolute)`) + This method is valid only when the item position is absolute or relative. It is not valid when the position is static. */ @discardableResult public func right(_ value: CGFloat) -> Flex { @@ -610,7 +611,7 @@ public final class Flex { /** Set the right edge distance from the container right edge in percentage of its container width. - This method is valid only when the item position is absolute (`view.flex.position(.absolute)`) + This method is valid only when the item position is absolute or relative. It is not valid when the position is static. */ @discardableResult public func right(_ percent: FPercent) -> Flex { @@ -620,7 +621,7 @@ public final class Flex { /** Set the bottom edge distance from the container bottom edge in pixels. - This method is valid only when the item position is absolute (`view.flex.position(.absolute)`) + This method is valid only when the item position is absolute or relative. It is not valid when the position is static. */ @discardableResult public func bottom(_ value: CGFloat) -> Flex { @@ -630,7 +631,7 @@ public final class Flex { /** Set the bottom edge distance from the container bottom edge in percentage of its container height. - This method is valid only when the item position is absolute (`view.flex.position(.absolute)`) + This method is valid only when the item position is absolute or relative. It is not valid when the position is static. */ @discardableResult public func bottom(_ percent: FPercent) -> Flex { @@ -640,7 +641,7 @@ public final class Flex { /** Set the start edge (LTR=left, RTL=right) distance from the container start edge in pixels. - This method is valid only when the item position is absolute (`view.flex.position(.absolute)`) + This method is valid only when the item position is absolute or relative. It is not valid when the position is static. */ @discardableResult public func start(_ value: CGFloat) -> Flex { @@ -651,7 +652,7 @@ public final class Flex { /** Set the start edge (LTR=left, RTL=right) distance from the container start edge in percentage of its container width. - This method is valid only when the item position is absolute (`view.flex.position(.absolute)`) + This method is valid only when the item position is absolute or relative. It is not valid when the position is static. */ @discardableResult public func start(_ percent: FPercent) -> Flex { @@ -661,7 +662,7 @@ public final class Flex { /** Set the end edge (LTR=right, RTL=left) distance from the container end edge in pixels. - This method is valid only when the item position is absolute (`view.flex.position(.absolute)`) + This method is valid only when the item position is absolute or relative. It is not valid when the position is static. */ @discardableResult public func end(_ value: CGFloat) -> Flex { @@ -672,7 +673,7 @@ public final class Flex { /** Set the end edge (LTR=right, RTL=left) distance from the container end edge in percentage of its container width. - This method is valid only when the item position is absolute (`view.flex.position(.absolute)`) + This method is valid only when the item position is absolute or relative. It is not valid when the position is static. */ @discardableResult public func end(_ percent: FPercent) -> Flex { @@ -681,9 +682,10 @@ public final class Flex { } /** - Set the left and right edges distance from the container edges in pixels. - This method is valid only when the item position is absolute (`view.flex.position(.absolute)`) - */ + Set the left and right edges distance from the container edges in pixels. + This method is valid only when the item position is absolute or relative. It is not valid when the position is static. + For relative position, the right edge will be ignored. + */ @discardableResult public func horizontally(_ value: CGFloat) -> Flex { yoga.left = YGValue(value) @@ -691,10 +693,11 @@ public final class Flex { return self } - /** - Set the left and right edges distance from the container edges in percentage of its container width. - This method is valid only when the item position is absolute (`view.flex.position(.absolute)`) - */ + /** + Set the left and right edges distance from the container edges in percentage of its container width. + This method is valid only when the item position is absolute or relative. It is not valid when the position is static. + For relative position, the right edge will be ignored. + */ @discardableResult public func horizontally(_ percent: FPercent) -> Flex { yoga.left = YGValue(value: Float(percent.value), unit: .percent) @@ -704,7 +707,8 @@ public final class Flex { /** Set the top and bottom edges distance from the container edges in pixels. - This method is valid only when the item position is absolute (`view.flex.position(.absolute)`) + This method is valid only when the item position is absolute or relative. It is not valid when the position is static. + For relative position, the bottom edge will be ignored. */ @discardableResult public func vertically(_ value: CGFloat) -> Flex { @@ -715,7 +719,8 @@ public final class Flex { /** Set the top and bottom edges distance from the container edges in percentage of its container height. - This method is valid only when the item position is absolute (`view.flex.position(.absolute)`) + This method is valid only when the item position is absolute or relative. It is not valid when the position is static. + For relative position, the bottom edge will be ignored. */ @discardableResult public func vertically(_ percent: FPercent) -> Flex { @@ -726,7 +731,8 @@ public final class Flex { /** Set all edges distance from the container edges in pixels. - This method is valid only when the item position is absolute (`view.flex.position(.absolute)`) + This method is valid only when the item position is absolute or relative. It is not valid when the position is static. + For relative position, the bottom and right edges will be ignored. */ @discardableResult public func all(_ value: CGFloat) -> Flex { @@ -739,7 +745,8 @@ public final class Flex { /** Set all edges distance from the container edges in percentage of its container size. - This method is valid only when the item position is absolute (`view.flex.position(.absolute)`) + This method is valid only when the item position is absolute or relative. It is not valid when the position is static. + For relative position, the bottom and right edges will be ignored. */ @discardableResult public func all(_ percent: FPercent) -> Flex { From 3ecb7671a38f434da041c6fbf148196901d22cca Mon Sep 17 00:00:00 2001 From: heoblitz Date: Sat, 15 Jun 2024 13:40:37 +0900 Subject: [PATCH 04/11] Update README.md --- README.md | 23 +++++++++++++++-------- 1 file changed, 15 insertions(+), 8 deletions(-) diff --git a/README.md b/README.md index 60df48e8..8ad88dce 100644 --- a/README.md +++ b/README.md @@ -36,7 +36,7 @@ Flexbox is an incredible improvement over UIStackView. It is simpler to use, muc * [Creation, modification and definition of flexbox containers](#create_modify_define_containers) * [Flexbox containers properties](#containers_properties) * [Flexbox items properties](#intems_properties) - * [Absolute positioning](#absolute_positioning) + * [Positioning](#positioning) * [Adjusting the size](#adjusting_size) * [Width, height and size](#width_height_size) * [minWidth, maxWidth, minHeight, maxHeight](#minmax_width_height_size) @@ -778,8 +778,8 @@ Item natural size, considering only properties of the view itself. Independent o
- -## 4. Absolute positioning + +## 4. Positioning - Applies to: `flex items` - Parameter: CGFloat @@ -787,16 +787,23 @@ Item natural size, considering only properties of the view itself. Independent o * **`position(_: Position)`** The position property tells Flexbox how you want your item to be positioned within its parent. Position values: - * **`relative (default)`** - * **`absolute`**: The view is positioned using properties: top(), bottom(), left(), right(), start(), end(). + * **`relative (default)`** The view is positioned using Insets properties (top, bottom, left, right, start, end) from its normal position within its flex container and will take up space within the flex container. This node will always form a containing block. + * **`absolute`**: The view is removed from the flex container's flow and is positioned using Insets properties (top, bottom, left, right, start, end). Insets will offset the node from its containing block. + * **`static`**: The view ignores insets and will not form a containing block. ###### Usage examples: ```swift + view.flex.position(.relative).top(10).left(10).size(50) + view.flex.position(.absolute).top(10).left(10).size(50) ``` ### top(), bottom(), left(), right(), start(), end(), vertically(), horizontally(), all() -A flex item which is `position` is set to `.absolute` is positioned absolutely in regards to its parent. This is done through the following methods: +A flex item with position set to .relative is positioned relative to its normal position within its flex container. Only one property can be applied in each direction, either vertical or horizontal. If both `top` and `bottom` properties are set, `top` takes precedence. If both `left` and `right` properties are set, `left` takes precedence. + +A flex item with position set to .absolute is positioned absolutely with respect to its containing block. Using these properties you can control the size and position of an absolute item within its parent. Because absolutely positioned children don’t affect their sibling's layout. Absolute position can be used to create overlays and stack children in the Z axis. + +This is done through the following methods: **Methods:** @@ -819,10 +826,10 @@ Controls the distance child’s left and right edges from the parent’s edges. * **`all(: CGFloat)`** / **`all(: FPercent)`**: Controls the distance child’s edges from the parent’s edges. Equal to `top().bottom().left().right()`. -Using these properties you can control the size and position of an absolute item within its parent. Because absolutely positioned children don’t affect their sibling's layout. Absolute position can be used to create overlays and stack children in the Z axis. - ###### Usage examples: ```swift + view.flex.position(.relative).top(10).right(10).width(100).height(50) + view.flex.position(.absolute).top(10).right(10).width(100).height(50) view.flex.position(.absolute).left(20%).right(20%) ``` From ff83132e8da82949896f8d5bd0bbbb5b86ca0baa Mon Sep 17 00:00:00 2001 From: heoblitz Date: Sat, 15 Jun 2024 14:50:13 +0900 Subject: [PATCH 05/11] Add InsetTests --- FlexLayout.xcodeproj/project.pbxproj | 4 ++ Tests/FlexLayoutTests/InsetTests.swift | 81 ++++++++++++++++++++++++++ 2 files changed, 85 insertions(+) create mode 100644 Tests/FlexLayoutTests/InsetTests.swift diff --git a/FlexLayout.xcodeproj/project.pbxproj b/FlexLayout.xcodeproj/project.pbxproj index 359d9cb4..8a65c8c3 100644 --- a/FlexLayout.xcodeproj/project.pbxproj +++ b/FlexLayout.xcodeproj/project.pbxproj @@ -99,6 +99,7 @@ EF0E61762C1A811100DF30F6 /* YGNodeStyle.cpp in Sources */ = {isa = PBXBuildFile; fileRef = EF0E612C2C1A811100DF30F6 /* YGNodeStyle.cpp */; }; EF0E61772C1A811100DF30F6 /* YGPixelGrid.cpp in Sources */ = {isa = PBXBuildFile; fileRef = EF0E612D2C1A811100DF30F6 /* YGPixelGrid.cpp */; }; EF0E61782C1A811100DF30F6 /* YGValue.cpp in Sources */ = {isa = PBXBuildFile; fileRef = EF0E612E2C1A811100DF30F6 /* YGValue.cpp */; }; + EF5445402C1D607100BF4A33 /* InsetTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = EF54453F2C1D607100BF4A33 /* InsetTests.swift */; }; /* End PBXBuildFile section */ /* Begin PBXContainerItemProxy section */ @@ -223,6 +224,7 @@ EF0E612C2C1A811100DF30F6 /* YGNodeStyle.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = YGNodeStyle.cpp; sourceTree = ""; }; EF0E612D2C1A811100DF30F6 /* YGPixelGrid.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = YGPixelGrid.cpp; sourceTree = ""; }; EF0E612E2C1A811100DF30F6 /* YGValue.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = YGValue.cpp; sourceTree = ""; }; + EF54453F2C1D607100BF4A33 /* InsetTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = InsetTests.swift; sourceTree = ""; }; /* End PBXFileReference section */ /* Begin PBXFrameworksBuildPhase section */ @@ -310,6 +312,7 @@ 711F2EE32ACC727000DDDD67 /* FlexLayoutTests.swift */, 711F2EE42ACC727000DDDD67 /* MarginTests.swift */, 711F2EE52ACC727000DDDD67 /* JustifyContentTests.swift */, + EF54453F2C1D607100BF4A33 /* InsetTests.swift */, ); path = FlexLayoutTests; sourceTree = ""; @@ -717,6 +720,7 @@ 711F2EE82ACC727000DDDD67 /* PaddingTests.swift in Sources */, 711F2EE62ACC727000DDDD67 /* AbsolutionPositionContentTests.swift in Sources */, 711F2EEB2ACC727000DDDD67 /* JustifyContentTests.swift in Sources */, + EF5445402C1D607100BF4A33 /* InsetTests.swift in Sources */, 711F2EE72ACC727000DDDD67 /* WidthSizeContentTests.swift in Sources */, ); runOnlyForDeploymentPostprocessing = 0; diff --git a/Tests/FlexLayoutTests/InsetTests.swift b/Tests/FlexLayoutTests/InsetTests.swift new file mode 100644 index 00000000..11596db3 --- /dev/null +++ b/Tests/FlexLayoutTests/InsetTests.swift @@ -0,0 +1,81 @@ +// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" +// AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +// IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE +// ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE +// LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR +// CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF +// SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS +// INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN +// CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) +// ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE +// POSSIBILITY OF SUCH DAMAGE. + +import FlexLayout +import XCTest + +final class InsetTests: XCTestCase { + + var viewController: UIViewController! + var rootFlexContainer: UIView! + var aView: UIView! + + override func setUp() { + super.setUp() + + viewController = UIViewController() + + rootFlexContainer = UIView() + rootFlexContainer.frame = CGRect(x: 0, y: 0, width: 400, height: 400) + viewController.view.addSubview(rootFlexContainer) + + aView = UIView() + } + + func test_adjust_the_aView_size_and_relative_position_with_left() { + rootFlexContainer.flex.define { flex in + flex.addItem(aView).position(.relative).grow(1).left(10) + } + rootFlexContainer.flex.layout() + XCTAssertEqual(aView.frame, CGRect(x: 10.0, y: 0.0, width: 400.0, height: 400.0)) + } + + func test_adjust_the_aView_size_and_relative_position_with_top() { + rootFlexContainer.flex.define { flex in + flex.addItem(aView).position(.relative).grow(1).top(10) + } + rootFlexContainer.flex.layout() + XCTAssertEqual(aView.frame, CGRect(x: 0.0, y: 10.0, width: 400.0, height: 400.0)) + } + + func test_adjust_the_aView_size_and_relative_position_with_right() { + rootFlexContainer.flex.define { flex in + flex.addItem(aView).position(.relative).grow(1).right(10) + } + rootFlexContainer.flex.layout() + XCTAssertEqual(aView.frame, CGRect(x: -10.0, y: 0.0, width: 400.0, height: 400.0)) + } + + func test_adjust_the_aView_size_and_relative_position_with_bottom() { + rootFlexContainer.flex.define { flex in + flex.addItem(aView).position(.relative).grow(1).bottom(10) + } + rootFlexContainer.flex.layout() + XCTAssertEqual(aView.frame, CGRect(x: 0.0, y: -10.0, width: 400.0, height: 400.0)) + } + + func test_adjust_the_aView_size_and_relative_position_with_horizontally() { + rootFlexContainer.flex.define { flex in + flex.addItem(aView).position(.relative).grow(1).horizontally(10) + } + rootFlexContainer.flex.layout() + XCTAssertEqual(aView.frame, CGRect(x: 10.0, y: 0.0, width: 400.0, height: 400.0)) + } + + func test_adjust_the_aView_size_and_relative_position_with_vertically() { + rootFlexContainer.flex.define { flex in + flex.addItem(aView).position(.relative).grow(1).vertically(10) + } + rootFlexContainer.flex.layout() + XCTAssertEqual(aView.frame, CGRect(x: 0.0, y: 10.0, width: 400.0, height: 400.0)) + } +} From f842df50a93d6601741873a20dc4ec8da6317778 Mon Sep 17 00:00:00 2001 From: heoblitz Date: Sat, 15 Jun 2024 14:55:56 +0900 Subject: [PATCH 06/11] Move AbsolutionPositionContentTests to InsetTests --- FlexLayout.xcodeproj/project.pbxproj | 4 -- .../AbsolutionPositionContentTests.swift | 71 ------------------- Tests/FlexLayoutTests/InsetTests.swift | 44 +++++++++++- 3 files changed, 41 insertions(+), 78 deletions(-) delete mode 100644 Tests/FlexLayoutTests/AbsolutionPositionContentTests.swift diff --git a/FlexLayout.xcodeproj/project.pbxproj b/FlexLayout.xcodeproj/project.pbxproj index 8a65c8c3..6e3ea94b 100644 --- a/FlexLayout.xcodeproj/project.pbxproj +++ b/FlexLayout.xcodeproj/project.pbxproj @@ -14,7 +14,6 @@ 24AE97411FEAF30A00995987 /* UIView+FlexLayout.swift in Sources */ = {isa = PBXBuildFile; fileRef = 24AE97321FEAF30A00995987 /* UIView+FlexLayout.swift */; }; 24AE97421FEAF30A00995987 /* Percent.swift in Sources */ = {isa = PBXBuildFile; fileRef = 24AE97331FEAF30A00995987 /* Percent.swift */; }; 24AE974A1FEAF30A00995987 /* YGLayoutExtensions.swift in Sources */ = {isa = PBXBuildFile; fileRef = 24AE973D1FEAF30A00995987 /* YGLayoutExtensions.swift */; }; - 711F2EE62ACC727000DDDD67 /* AbsolutionPositionContentTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 711F2EE02ACC727000DDDD67 /* AbsolutionPositionContentTests.swift */; }; 711F2EE72ACC727000DDDD67 /* WidthSizeContentTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 711F2EE12ACC727000DDDD67 /* WidthSizeContentTests.swift */; }; 711F2EE82ACC727000DDDD67 /* PaddingTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 711F2EE22ACC727000DDDD67 /* PaddingTests.swift */; }; 711F2EE92ACC727000DDDD67 /* FlexLayoutTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 711F2EE32ACC727000DDDD67 /* FlexLayoutTests.swift */; }; @@ -139,7 +138,6 @@ 24DA37631EF843C500D1AB2F /* FlexLayoutTests.xctest */ = {isa = PBXFileReference; explicitFileType = wrapper.cfbundle; includeInIndex = 0; path = FlexLayoutTests.xctest; sourceTree = BUILT_PRODUCTS_DIR; }; 2B210ECFE9D7665DACB8E8A7 /* Pods-FlexLayoutTests.debug.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-FlexLayoutTests.debug.xcconfig"; path = "Target Support Files/Pods-FlexLayoutTests/Pods-FlexLayoutTests.debug.xcconfig"; sourceTree = ""; }; 38E690AA4AF8EDFC95DB6626 /* Pods-FlexLayoutTests.release.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-FlexLayoutTests.release.xcconfig"; path = "Target Support Files/Pods-FlexLayoutTests/Pods-FlexLayoutTests.release.xcconfig"; sourceTree = ""; }; - 711F2EE02ACC727000DDDD67 /* AbsolutionPositionContentTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = AbsolutionPositionContentTests.swift; sourceTree = ""; }; 711F2EE12ACC727000DDDD67 /* WidthSizeContentTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = WidthSizeContentTests.swift; sourceTree = ""; }; 711F2EE22ACC727000DDDD67 /* PaddingTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = PaddingTests.swift; sourceTree = ""; }; 711F2EE32ACC727000DDDD67 /* FlexLayoutTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = FlexLayoutTests.swift; sourceTree = ""; }; @@ -306,7 +304,6 @@ 711F2EDF2ACC727000DDDD67 /* FlexLayoutTests */ = { isa = PBXGroup; children = ( - 711F2EE02ACC727000DDDD67 /* AbsolutionPositionContentTests.swift */, 711F2EE12ACC727000DDDD67 /* WidthSizeContentTests.swift */, 711F2EE22ACC727000DDDD67 /* PaddingTests.swift */, 711F2EE32ACC727000DDDD67 /* FlexLayoutTests.swift */, @@ -718,7 +715,6 @@ 711F2EEA2ACC727000DDDD67 /* MarginTests.swift in Sources */, 711F2EE92ACC727000DDDD67 /* FlexLayoutTests.swift in Sources */, 711F2EE82ACC727000DDDD67 /* PaddingTests.swift in Sources */, - 711F2EE62ACC727000DDDD67 /* AbsolutionPositionContentTests.swift in Sources */, 711F2EEB2ACC727000DDDD67 /* JustifyContentTests.swift in Sources */, EF5445402C1D607100BF4A33 /* InsetTests.swift in Sources */, 711F2EE72ACC727000DDDD67 /* WidthSizeContentTests.swift in Sources */, diff --git a/Tests/FlexLayoutTests/AbsolutionPositionContentTests.swift b/Tests/FlexLayoutTests/AbsolutionPositionContentTests.swift deleted file mode 100644 index 8db3b510..00000000 --- a/Tests/FlexLayoutTests/AbsolutionPositionContentTests.swift +++ /dev/null @@ -1,71 +0,0 @@ -// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" -// AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE -// IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE -// ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE -// LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR -// CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF -// SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS -// INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN -// CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) -// ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE -// POSSIBILITY OF SUCH DAMAGE. - -import FlexLayout -import XCTest - -final class AbsolutionPositionContentTests: XCTestCase { - - var viewController: UIViewController! - var rootFlexContainer: UIView! - var aView: UIView! - - override func setUp() { - super.setUp() - - viewController = UIViewController() - - rootFlexContainer = UIView() - rootFlexContainer.frame = CGRect(x: 0, y: 0, width: 400, height: 400) - viewController.view.addSubview(rootFlexContainer) - - aView = UIView() - } - - func test_absolute_position_1() { - rootFlexContainer.flex.define { flex in - flex.addItem(aView).position(.absolute).left(10).right(10).width(300).height(200) - } - - rootFlexContainer.flex.layout() - XCTAssertEqual(aView.frame, CGRect(x: 10.0, y: 0.0, width: 300.0, height: 200.0)) - } - - func test_absolute_position_2() { - rootFlexContainer.flex.define { flex in - flex.addItem(aView).position(.absolute).left(10).right(10).width(300).height(200) - } - - // Later reset the aspectRatio - aView.flex.left(0) - rootFlexContainer.flex.layout() - XCTAssertEqual(aView.frame, CGRect(x: 0.0, y: 0.0, width: 300.0, height: 200.0)) - } - - func test_absolute_position_3() { - rootFlexContainer.flex.define { flex in - flex.addItem(aView).position(.absolute).horizontally(15).vertically(20) - } - - rootFlexContainer.flex.layout() - XCTAssertEqual(aView.frame, CGRect(x: 15.0, y: 20.0, width: 370.0, height: 360.0)) - } - - func test_absolute_position_4() { - rootFlexContainer.flex.define { flex in - flex.addItem(aView).position(.absolute).all(45) - } - - rootFlexContainer.flex.layout() - XCTAssertEqual(aView.frame, CGRect(x: 45.0, y: 45.0, width: 310.0, height: 310.0)) - } -} diff --git a/Tests/FlexLayoutTests/InsetTests.swift b/Tests/FlexLayoutTests/InsetTests.swift index 11596db3..91ed23ec 100644 --- a/Tests/FlexLayoutTests/InsetTests.swift +++ b/Tests/FlexLayoutTests/InsetTests.swift @@ -21,13 +21,13 @@ final class InsetTests: XCTestCase { override func setUp() { super.setUp() - + viewController = UIViewController() - + rootFlexContainer = UIView() rootFlexContainer.frame = CGRect(x: 0, y: 0, width: 400, height: 400) viewController.view.addSubview(rootFlexContainer) - + aView = UIView() } @@ -78,4 +78,42 @@ final class InsetTests: XCTestCase { rootFlexContainer.flex.layout() XCTAssertEqual(aView.frame, CGRect(x: 0.0, y: 10.0, width: 400.0, height: 400.0)) } + + func test_adjust_the_aView_size_absolute_position_with_left_right() { + rootFlexContainer.flex.define { flex in + flex.addItem(aView).position(.absolute).left(10).right(10).width(300).height(200) + } + + rootFlexContainer.flex.layout() + XCTAssertEqual(aView.frame, CGRect(x: 10.0, y: 0.0, width: 300.0, height: 200.0)) + } + + func test_adjust_the_aView_size_absolute_position_with_right() { + rootFlexContainer.flex.define { flex in + flex.addItem(aView).position(.absolute).left(10).right(10).width(300).height(200) + } + + // Later reset the aspectRatio + aView.flex.left(0) + rootFlexContainer.flex.layout() + XCTAssertEqual(aView.frame, CGRect(x: 0.0, y: 0.0, width: 300.0, height: 200.0)) + } + + func test_adjust_the_aView_size_absolute_position_with_horizontally_vertically() { + rootFlexContainer.flex.define { flex in + flex.addItem(aView).position(.absolute).horizontally(15).vertically(20) + } + + rootFlexContainer.flex.layout() + XCTAssertEqual(aView.frame, CGRect(x: 15.0, y: 20.0, width: 370.0, height: 360.0)) + } + + func test_adjust_the_aView_size_absolute_position_with_horizontally_all() { + rootFlexContainer.flex.define { flex in + flex.addItem(aView).position(.absolute).all(45) + } + + rootFlexContainer.flex.layout() + XCTAssertEqual(aView.frame, CGRect(x: 45.0, y: 45.0, width: 310.0, height: 310.0)) + } } From d4478fb22f502b14dcc15e75aa41b5487a817515 Mon Sep 17 00:00:00 2001 From: heoblitz Date: Sat, 15 Jun 2024 14:58:14 +0900 Subject: [PATCH 07/11] Add static position inset tests --- Tests/FlexLayoutTests/InsetTests.swift | 48 ++++++++++++++++++++++++++ 1 file changed, 48 insertions(+) diff --git a/Tests/FlexLayoutTests/InsetTests.swift b/Tests/FlexLayoutTests/InsetTests.swift index 91ed23ec..55b79d7b 100644 --- a/Tests/FlexLayoutTests/InsetTests.swift +++ b/Tests/FlexLayoutTests/InsetTests.swift @@ -116,4 +116,52 @@ final class InsetTests: XCTestCase { rootFlexContainer.flex.layout() XCTAssertEqual(aView.frame, CGRect(x: 45.0, y: 45.0, width: 310.0, height: 310.0)) } + + func test_adjust_the_aView_size_and_relative_static_with_left() { + rootFlexContainer.flex.define { flex in + flex.addItem(aView).position(.static).grow(1).left(10) + } + rootFlexContainer.flex.layout() + XCTAssertEqual(aView.frame, CGRect(x: 0.0, y: 0.0, width: 400.0, height: 400.0)) + } + + func test_adjust_the_aView_size_and_static_position_with_top() { + rootFlexContainer.flex.define { flex in + flex.addItem(aView).position(.static).grow(1).top(10) + } + rootFlexContainer.flex.layout() + XCTAssertEqual(aView.frame, CGRect(x: 0.0, y: 0.0, width: 400.0, height: 400.0)) + } + + func test_adjust_the_aView_size_and_static_position_with_right() { + rootFlexContainer.flex.define { flex in + flex.addItem(aView).position(.static).grow(1).right(10) + } + rootFlexContainer.flex.layout() + XCTAssertEqual(aView.frame, CGRect(x: 0.0, y: 0.0, width: 400.0, height: 400.0)) + } + + func test_adjust_the_aView_size_and_static_position_with_bottom() { + rootFlexContainer.flex.define { flex in + flex.addItem(aView).position(.static).grow(1).bottom(10) + } + rootFlexContainer.flex.layout() + XCTAssertEqual(aView.frame, CGRect(x: 0.0, y: 0.0, width: 400.0, height: 400.0)) + } + + func test_adjust_the_aView_size_and_static_position_with_horizontally() { + rootFlexContainer.flex.define { flex in + flex.addItem(aView).position(.static).grow(1).horizontally(10) + } + rootFlexContainer.flex.layout() + XCTAssertEqual(aView.frame, CGRect(x: 0.0, y: 0.0, width: 400.0, height: 400.0)) + } + + func test_adjust_the_aView_size_and_static_position_with_vertically() { + rootFlexContainer.flex.define { flex in + flex.addItem(aView).position(.static).grow(1).vertically(10) + } + rootFlexContainer.flex.layout() + XCTAssertEqual(aView.frame, CGRect(x: 0.0, y: 0.0, width: 400.0, height: 400.0)) + } } From 6e064a1d53f64cfede0e5e69f289aebf47ad3a82 Mon Sep 17 00:00:00 2001 From: heoblitz Date: Sat, 15 Jun 2024 15:06:08 +0900 Subject: [PATCH 08/11] Update position docs --- docs/1.1/Classes/Flex/Position.html | 38 +++++++++++++++++++++++++++-- 1 file changed, 36 insertions(+), 2 deletions(-) diff --git a/docs/1.1/Classes/Flex/Position.html b/docs/1.1/Classes/Flex/Position.html index 0d7fbc86..6a7e6ad4 100644 --- a/docs/1.1/Classes/Flex/Position.html +++ b/docs/1.1/Classes/Flex/Position.html @@ -93,7 +93,7 @@

Position

-

Default value.

+

Default value. Positioned according to the flex container's flow. The item is positioned using Insets properties (top, bottom, left, right, start, end) from its normal position within its flex container and will take up space within the flex container. This node will always form a containing block.

@@ -127,7 +127,7 @@

Declaration

-

Positioned absolutely in regards to its container. The item is positionned using properties top, bottom, left, right, start, end.

+

Positioned absolutely, removed from the flex container's flow. The item is positioned using Insets properties (top, bottom, left, right, start, end). Insets will offset the node from its containing block.

@@ -146,6 +146,40 @@

Declaration

+
+
    +
  • +
    + + + + static + +
    +
    +
    +
    +
    +
    +

    Positioned like relative but ignores insets and will not form a containing block.

    + +
    +
    +

    Declaration

    +
    +

    Swift

    +
    case static
    + +
    +
    + +
    +
    +
  • +
+
@@ -139,7 +139,7 @@

Declaration

@@ -173,7 +173,7 @@

Declaration

From 50866f10735b7b95409b45f42658e64c3bfa9037 Mon Sep 17 00:00:00 2001 From: heoblitz Date: Sun, 16 Jun 2024 22:22:35 +0900 Subject: [PATCH 10/11] Update Podfile.lock --- Podfile.lock | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Podfile.lock b/Podfile.lock index 2f41f9d7..c3edb0ad 100644 --- a/Podfile.lock +++ b/Podfile.lock @@ -1,5 +1,5 @@ PODS: - - FlexLayout (2.0.7) + - FlexLayout (2.0.8) - PinLayout (1.10.5) - SwiftLint (0.55.1) @@ -18,7 +18,7 @@ EXTERNAL SOURCES: :path: "./" SPEC CHECKSUMS: - FlexLayout: fcb9aaa754029afff0cb99e9cdfe10c68d70b6ac + FlexLayout: 74c80db7698ea6e0d11e00ba012c0b9f3252938a PinLayout: f6c2b63a5a5b24864064e1d15c67de41b4e74748 SwiftLint: 3fe909719babe5537c552ee8181c0031392be933 From b52c200eba59a1989e238cc40541b2c1cea10f09 Mon Sep 17 00:00:00 2001 From: heoblitz Date: Sun, 16 Jun 2024 23:06:31 +0900 Subject: [PATCH 11/11] Fix test case typo --- Tests/FlexLayoutTests/InsetTests.swift | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Tests/FlexLayoutTests/InsetTests.swift b/Tests/FlexLayoutTests/InsetTests.swift index 55b79d7b..07591e32 100644 --- a/Tests/FlexLayoutTests/InsetTests.swift +++ b/Tests/FlexLayoutTests/InsetTests.swift @@ -88,7 +88,7 @@ final class InsetTests: XCTestCase { XCTAssertEqual(aView.frame, CGRect(x: 10.0, y: 0.0, width: 300.0, height: 200.0)) } - func test_adjust_the_aView_size_absolute_position_with_right() { + func test_adjust_the_aView_size_absolute_position_with_right_and_reset_left_later() { rootFlexContainer.flex.define { flex in flex.addItem(aView).position(.absolute).left(10).right(10).width(300).height(200) } @@ -108,7 +108,7 @@ final class InsetTests: XCTestCase { XCTAssertEqual(aView.frame, CGRect(x: 15.0, y: 20.0, width: 370.0, height: 360.0)) } - func test_adjust_the_aView_size_absolute_position_with_horizontally_all() { + func test_adjust_the_aView_size_absolute_position_with_all() { rootFlexContainer.flex.define { flex in flex.addItem(aView).position(.absolute).all(45) }