Skip to content

Conversation

Lcarvajal-zz
Copy link

The logic for horizontal scrolling moved inside switch statements for scrollDirection.

I added three cases for .vertical scrolling:

  • .top
  • .center
  • .bottom

The cells of a collectionView snap to the top, center, or bottom when the scrollDirection is set to vertical.

@Lcarvajal-zz
Copy link
Author

Lcarvajal-zz commented May 12, 2021

I just learned to code with Mimo and I'd appreciate any pointers on improving my code ❤️😄

Comment on lines +38 to +39
switch scrollDirection {
case .horizontal:
Copy link
Collaborator

Choose a reason for hiding this comment

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

Instead of chaining 2 switch statements inside another switch, you can do it like this:

Suggested change
switch scrollDirection {
case .horizontal:
switch (scrollDirection, snapPosition) {
case (.horizontal, .left):
case (.horizontal, .center):
case (.horizontal, .right):
case (.vertical, .center):
case (.vertical, .top):
case (.vertical, .bottom):
case (.horizontal, .top), (.horizontal, .bottom), (.vertical, .left), (.vertical, .right):

Comment on lines +75 to +82
switch scrollDirection {
case .horizontal:
let itemHorizontalPosition: CGFloat

switch snapPosition {
case .left:
itemHorizontalPosition = layoutAttributes.frame.minX - collectionView.contentInset.left
case .center:
Copy link
Collaborator

Choose a reason for hiding this comment

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

Same here.

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.

3 participants