Skip to content

Commit

Permalink
Merge pull request #124 from kazuhiro4949/feature/fix_overlay
Browse files Browse the repository at this point in the history
Fixed a mask layout when the cells is centered and overlay menu style.
  • Loading branch information
kazuhiro4949 authored Jun 2, 2020
2 parents f210e58 + ba263b1 commit c47f486
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 4 deletions.
4 changes: 4 additions & 0 deletions Sources/Menu Cells/Overlay/OverlayMenuCell.swift
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,10 @@ public class OverlayMenuCell: PagingMenuViewCell {

func setFrame(_ menuView: PagingMenuView, maskFrame: CGRect, animated: Bool) {
textMaskView.frame = menuView.convert(maskFrame, to: highlightLabel).inset(by: maskInsets)

if let expectedOriginX = menuView.getExpectedAlignmentPositionXIfNeeded() {
textMaskView.frame.origin.x += expectedOriginX
}
}

public func calculateWidth(from height: CGFloat, title: String) -> CGFloat {
Expand Down
19 changes: 15 additions & 4 deletions Sources/PagingMenuView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -652,12 +652,23 @@ open class PagingMenuView: UIScrollView {

/// If contentSize.width is not over safe area, paging menu view applys cellAlignment to each the cells.
private func alignContainerViewIfNeeded() {
let expectedOriginX = cellAlignment.calculateOriginX(from: maxSafedOffset)
guard !hasScrollableArea && expectedOriginX != containerView.frame.origin.x else {
guard let expectedOriginX = getExpectedAlignmentPositionXIfNeeded() else {
return
}

containerView.frame.origin.x = expectedOriginX

if expectedOriginX != containerView.frame.origin.x {
containerView.frame.origin.x = expectedOriginX
}
}


/// get correct origin X of menu view's container view, If menu view is scrollable.
func getExpectedAlignmentPositionXIfNeeded() -> CGFloat? {
let expectedOriginX = cellAlignment.calculateOriginX(from: maxSafedOffset)
guard !hasScrollableArea else {
return nil
}
return expectedOriginX
}


Expand Down

0 comments on commit c47f486

Please sign in to comment.