Skip to content

New method sizeToFit(:FitType) & fitSize() is now deprecated - #101

Merged
lucdion merged 8 commits into
masterfrom
add_fitWidth_fitHeight
Nov 20, 2017
Merged

lucdion merged 8 commits into
masterfrom
add_fitWidth_fitHeight

Conversation

@lucdion

@lucdion lucdion commented Nov 19, 2017 •

Copy link
Copy Markdown
Member

Changes:

  • fitSize() is now deprecated. The new sizeToFit(:FitType) should be used instead.

  • New method sizeToFit(_ fitType: FitType)
    The method adjust the view's size based on the view's sizeThatFits() method result.
    PinLayout will adjust either the view's width or height based on the fitType parameter value.

    Notes:

    • If margin rules apply, margins will be applied when determining the reference dimension (width/height).
    • The resulting size will always respect minWidth / maxWidth / minHeight / maxHeight.

Parameter fitType: Identify the reference dimension (width / height) that will be used
to adjust the view's size:

  • .width: The method adjust the view's size based on the reference width.
    * If properties related to the width have been pinned (e.g: width, left & right, margins, ...),
    the reference width will be determined by these properties, else the current view's width
    will be used.
    * The resulting width will always match the reference width.

  • .height: The method adjust the view's size based on the reference height.
    * If properties related to the height have been pinned (e.g: height, top & bottom, margins, ...),
    the reference height will be determined by these properties, else the current view's height
    will be used.
    * The resulting height will always match the reference height.

  • .widthFlexible: Similar to .width, except that PinLayout won't constrain the resulting width to
    match the reference width. The resulting width may be smaller of bigger depending on the view's
    sizeThatFits(..) method result. For example a single line UILabel may returns a smaller width if its
    string is smaller than the reference width.

  • .heightFlexible: Similar to .height, except that PinLayout won't constrain the resulting height to
    match the reference height. The resulting height may be smaller of bigger depending on the view's
    sizeThatFits(..) method result.

    Examples:

         // Adjust the view's size based on a width of 100 pixels.
         // The resulting width will always match the pinned property `width(100)`.
         view.pin.width(100).sizeToFit(.width)

         // Adjust the view's size based on view's current width.
         // The resulting width will always match the view's original width.
         // The resulting height will never be bigger than the specified `maxHeight`.
         view.pin.sizeToFit(.width).maxHeight(100)

         // Adjust the view's size based on 100% of the superview's height.
         // The resulting height will always match the pinned property `height(100%)`.
         view.pin.height(100%).sizeToFit(.height)

        // Adjust the view's size based on view's current height.
        // The resulting width will always match the view's original height.
        view.pin.sizeToFit(.height)

        // Since `.widthFlexible` has been specified, its possible that the resulting
        // width will be smaller or bigger than 100 pixels, based of the label's sizeThatFits()
        // method result.
        label.pin.width(100).sizeToFit(.widthFlexible)

Luc Dion added 6 commits November 15, 2017 19:31
… fitSizeHard()

* **`fitWidth()`**
The method **adjust the view's height** based on either the **current view's width** or the **width determined by PinLayout**. The method compute the height based on the result of the view's `sizeThatFits(: CGSize)` method.

	Notes:
     * The resulting width will never be bigger than the reference width, but could be smaller.
     * The resulting size will always respect minWidth/maxWidth/minHeight/maxHeight.
     * If margin rules applies, margins will be applied when determining the reference width.

* **`fitWidthHard()`**
Similar to `fitWidth()`, except that the resulting width will **always match the reference width**.

* **`fitHeight()`**
The method **adjust the view's width** based on either the **current view's height** or the **height determined by PinLayout**. The method compute the width based on the result of the view's `sizeThatFits(: CGSize)` method.

	Notes:
     * The resulting height will always match the reference height.
     * The resulting size will always respect minWidth/maxWidth/minHeight/maxHeight.
     * If margin rules applies, margins will be applied when determining the reference height.
* **`fitHeightHard()`**
Similar to `fitHeight()`, except that the resulting height will **always match the reference width**.
* **`fitSize()`**
The method **adjust the view's width and height** based on either the **pinned height** or **pinned width**. The method compute the width and height based on the result of the view's `sizeThatFits(: CGSize)` method.
If the **width** has been pinned => the method **adjust the view's height** based on this width.
If the **height** has been pinned => the method **adjust the view's width** based on this height.
If the **width and the height** have been pinned => the method **adjust the view's size** based on both values.

     Notes:
     * The resulting width/height will never be bigger than the pinnded width/height, but could be smaller.
     * The resulting size will always respect minWidth/maxWidth/minHeight/maxHeight.
     * If margin rules applies, margins will be applied when determining the reference width/height.

* **`fitSizeHard()`**
Similar to `fitSize()`, except that the resulting width/height will **always match the pinned width/height**..
* `fitSize()` is now deprecated. The new `sizeToFit(:FitType)` should be used instead.

**`sizeToFit(_ fitType: FitType)`**
The method adjust the view's size based on the view's `sizeThatFits()` method result.
     PinLayout will adjust either the view's width or height based on the `fitType` parameter value.

     Notes:
     * If margin rules apply, margins will be applied when determining the reference dimension (width/height).
     * The resulting size will always respect `minWidth` / `maxWidth` / `minHeight` / `maxHeight`.

     - Parameter fitType: Identify the reference dimension (width / height) that will be used
     to adjust the view's size:

     .width: The method adjust the view's size based on the **reference width**.
        * If properties related to the width have been pinned (e.g: width, left & right, margins, ...),
            the **reference width will be determined by these properties**, else the **current view's width**
            will be used.
        * The resulting width will always **match the reference width**.

     .height: The method adjust the view's size based on the **reference height**.
         * If properties related to the height have been pinned (e.g: height, top & bottom, margins, ...),
         the **reference height will be determined by these properties**, else the **current view's height**
         will be used.
         * The resulting height will always **match the reference height**.

     .widthFlexible: Similar to `.width`, except that PinLayout won't constrain the resulting width to
        match the reference width. The resulting width may be smaller of bigger depending on the view's
        sizeThatFits(..) method result. For example a single line UILabel may returns a smaller width if its
        string is smaller than the reference width.

     .heightFlexible: Similar to `.height`, except that PinLayout won't constrain the resulting height to
        match the reference height. The resulting height may be smaller of bigger depending on the view's
        sizeThatFits(..) method result.

     Examples:

         ```
         // Adjust the view's size based on a width of 100 pixels.
         // The resulting width will always match the pinned property `width(100)`.
         view.pin.width(100).sizeToFit(.width)

         // Adjust the view's size based on view's current width.
         // The resulting width will always match the view's original width.
         // The resulting height will never be bigger than the specified `maxHeight`.
         view.pin.sizeToFit(.width).maxHeight(100)

         // Adjust the view's size based on 100% of the superview's height.
         // The resulting height will always match the pinned property `height(100%)`.
         view.pin.height(100%).sizeToFit(.height)

        // Adjust the view's size based on view's current height.
        // The resulting width will always match the view's original height.
        view.pin.sizeToFit(.height)

        // Since `.widthFlexible` has been specified, its possible that the resulting
        // width will be smaller or bigger than 100 pixels, based of the label's sizeThatFits()
        // method result.
        label.pin.width(100).sizeToFit(.widthFlexible)
     ```
@codecov-io

codecov-io commented Nov 19, 2017 •

Copy link
Copy Markdown

Codecov Report

Merging #101 into master will increase coverage by 0.44%.
The diff coverage is 96.07%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master     #101      +/-   ##
==========================================
+ Coverage   89.51%   89.96%   +0.44%     
==========================================
  Files          31       30       -1     
  Lines        5810     6067     +257     
==========================================
+ Hits         5201     5458     +257     
  Misses        609      609
Impacted Files Coverage Δ
Sources/ObjectiveC/PinLayoutObjC.swift 0% <ø> (ø) ⬆️
Sources/PinLayout.swift 100% <ø> (ø) ⬆️
Sources/ObjectiveC/PinLayoutObjCImpl.swift 0% <0%> (ø) ⬆️
Tests/AdjustSizeSpec.swift 100% <100%> (ø) ⬆️
Tests/AspectRatioTests.swift 100% <100%> (ø) ⬆️
Tests/BasicView.swift 80% <100%> (ø) ⬆️
Tests/MinMaxWidthHeightSpec.swift 100% <100%> (ø) ⬆️
Sources/TypesImpl.swift 92.59% <75%> (-1.93%) ⬇️
Sources/PinLayoutImpl.swift 85.08% <97.05%> (+0.92%) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 4987499...2577938. Read the comment docs.

@lucdion
lucdion merged commit b4105d3 into master Nov 20, 2017
@lucdion
lucdion deleted the add_fitWidth_fitHeight branch November 20, 2017 12:55
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants