Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixed a mask layout when the cells is centered and overlay menu style. #124

Merged
merged 1 commit into from
Jun 2, 2020
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions Sources/Menu Cells/Overlay/OverlayMenuCell.swift
Original file line number Diff line number Diff line change
@@ -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 {
19 changes: 15 additions & 4 deletions Sources/PagingMenuView.swift
Original file line number Diff line number Diff line change
@@ -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
}