Skip to content
This repository has been archived by the owner on Jun 17, 2018. It is now read-only.

Fix weird behavior on moving through pages #291 #322

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
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: 2 additions & 2 deletions Example/Podfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,11 @@ DEPENDENCIES:

EXTERNAL SOURCES:
PagingMenuController:
:path: "../"
:path: ../

SPEC CHECKSUMS:
PagingMenuController: 60602bfb5421d6536c1e3097baeed601dec1d85b

PODFILE CHECKSUM: ad8a39de8cc58c1b803b2e2b316ca0de8adca12c

COCOAPODS: 1.1.0.rc.2
COCOAPODS: 1.1.1
18 changes: 15 additions & 3 deletions Pod/Classes/MenuView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@

import UIKit

internal let MenuViewItemsMarginRigth: CGFloat = 20
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you explain why we have static right margin?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi Kitasuke. First of all thanks for your framework.

So I declared it that way so it could be easy to change later if the right margin was not the desired. Because of some constants like MinimumSupportedViewCount, in that moment I thought it will make sense. Honestly looking at it right now probably will be better to just have a constant inside the same function contentOffsetXForCurrentPage.
Let me know what you think.

Thanks !

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I understand that it makes easier, but I actually prefer not to have static value. Anyway I'll wait for this answer to understand what the case is at first.

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for you answer. Then this static margin wouldn't be appropriate way, because this change is supposed to be for dynamic change of the number of items. In addition, I'm not sure this approach would be suitable for other cases as well.

Ideally there should be method which can change it's option, but it's still in progress...
Well, let me think different approach.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Awesome, let me know if I can help you.


open class MenuView: UIScrollView {
public fileprivate(set) var currentMenuItemView: MenuItemView!

Expand Down Expand Up @@ -65,9 +67,19 @@ open class MenuView: UIScrollView {
return menuItemViews[currentPage].frame.midX - screenWidth / 2
}
fileprivate var contentOffsetXForCurrentPage: CGFloat {
guard menuItemCount > MinimumSupportedViewCount else { return 0.0 }
let ratio = CGFloat(currentPage) / CGFloat(menuItemCount - 1)
return (contentSize.width - frame.width) * ratio
// Get the content offset X for the current element so the next one will be visible.
let currentElementFrame = menuItemViews[currentPage].frame
let deviceWidth = (UIApplication.shared.keyWindow!.bounds.width)

if (currentPage == menuItemViews.count - 1) {
// Current element is the last element.
let leadingValue = deviceWidth - (currentElementFrame.size.width + MenuViewItemsMarginRigth)
return max(currentElementFrame.origin.x - leadingValue, 0)
}
// There is a nextElement we should care about.
let nextElement = menuItemViews[currentPage + 1]
let leadingValue = deviceWidth - (currentElementFrame.size.width + nextElement.frame.size.width / 2 + MenuViewItemsMarginRigth)
return max(currentElementFrame.origin.x - leadingValue, 0)
}
fileprivate var currentIndex: Int = 0

Expand Down