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

MBP-4700 Pagination 트리거 인터페이스를 변경 및 개선해요. (BreakingChanges) #44

Merged
merged 11 commits into from
Jul 2, 2024

Conversation

ppth0608
Copy link
Contributor

@ppth0608 ppth0608 commented Jul 2, 2024

배경

  • 기존 KarrotListKit의 Pagination 처리 방식은 UICollectionViewDelegatewillDisplayItem:at 함수를 이용하여 마지막 아이템의 index보다 threshold 만큼의 차이가 나는 아이템이 노출되었을때 NextBatchTrigger 이벤트를 콜백하는 방식으로 구현되어 있어요.
  • 위 방식은 Cell의 height에 따라 Trigger 시점이 달라질 수 있기 때문에 의도하지 않는 시점에 다음 페이지를 요청하는 문제가 존재해요.
  • 이를 개선하여, 노출된 아이템의 index 기반이 아닌 ContentOffset 기반으로 리스트의 끝 위치로부터 설정한 위치만큼 도달하게되면 트리거 이벤트를 콜백하는 방식으로 수정하였어요.

변경사항

  • KarrotListKit 은 다음 페이지 중복 호출에 대한 책임을 갖지 않고, 트리거 조건에 해당하면 무조건 트리거 해주는 심플한 인터페이스로 변경해요.
List(sections: [])
  .onReachedBottom(
    offset: .absolute(100.0),
    perform: { _ in
      // Closure Trigger when reached bottom of list.
    }
  )
  • onReachedBottom modifier의 트리거 조건은 사용처에서 2가지 방식으로 구성할 수 있어요.
    • case multipleHeight(CGFloat): 스크롤 위치가 리스트 뷰 높이의 N배 이내에 있는 경우.
    • case absolute(CGFloat): 스크롤 위치가 리스트의 끝에서부터 절대적인 포인트 값 내에 있는 경우.
  • 기본값은 .multipleHeight(2.0)으로 설정되어 있으며, 스크롤 위치가 리스트 뷰 높이의 두 배 이내에 있는 경우 이벤트가 트리거됩니다.

리뷰노트

  • 코드 리뷰는 커밋 단위로 보는 것이 편해요.

@OhKanghoon
Copy link
Member

오 드디어 올라왔군요

public struct EventContext {}

/// Defines the offset from the bottom of the list view that will trigger the event.
public enum OffsetFromBottom {
Copy link
Contributor

@GeekTree0101 GeekTree0101 Jul 2, 2024

Choose a reason for hiding this comment

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

Optional

Vertical 일때만 유효한 네이밍인거 같아요. 네이밍에서 Horizonal scroll 까지 커버할 필요는 없을까요?

Copy link
Contributor

Choose a reason for hiding this comment

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

행복하세요 벤 🥴❤️

Copy link
Member

Choose a reason for hiding this comment

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

데-하

Copy link
Contributor Author

Choose a reason for hiding this comment

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

데-하~ 👋 역시 데이빗 좋은 리뷰를 남겨주셨군여 ㅋㅋ
Bottom을 전체적으로 Edge로 변경하면 어떨까요?

사용하는쪽에서 아래와 같이 될 것 같은데 어떻게 느껴지시나요?ㅎㅎ

List {}
  .onReachedEdge { }

Bottom이 Horizontal에선 맞지 않긴하지만 대부분 UICollectionView의 메인 축을 Verticle을 사용하는 것이 대부분 일반적여서
Bottom suffix가 익숙한 느낌이긴 하네요 😹

Copy link
Contributor

Choose a reason for hiding this comment

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

onReachedEnd 도 생각나네요 ㅎㅎㅎ scroll direction에 의존해서 vertical은 bottom, horizontal은 right가 될꺼같고 반대 방향은 inversion 고려해라고 독려해볼 수 있을꺼같아요

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@jaxtynSong @stleamist @OhKanghoon 인터페이스를 함께 고민해주신 분들 의견은 어떠세요?~

edge보다는 end가 더 익숙하는 느낌이긴하네요 저한테는 ㅎㅎ

  1. .onReachedEnd { }
  2. .onReachedEdge { }

언젠가 inversion을 고려해야한다면 End를 사용하고 Start와 pair를 맞추는 것도 괜찮아보이네요!

Copy link
Member

Choose a reason for hiding this comment

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

edge는 상하좌우 모서리를 포함하는 개념이라, 저도 end에 한 표 던집니다! ㅎㅎ

Copy link
Contributor

Choose a reason for hiding this comment

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

저도 onReachedEnd 좋아보여요 ㅎㅎ

Copy link
Contributor Author

Choose a reason for hiding this comment

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

다들 의견 감사해요 🙏

onReachedEnd로 가볼께요~

Copy link
Contributor Author

Choose a reason for hiding this comment

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

4d8cf54에서 반영했어요~

/// Defines the offset from the bottom of the list view that will trigger the event.
public enum OffsetFromBottom {
/// Triggers the event when the user scrolls within a multiple of the height of the content view.
case multipleHeight(CGFloat)
Copy link
Member

Choose a reason for hiding this comment

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

relativeHeight(multiplier: CGFloat) 이나 heightMultiplier(CGFloat) 이 되면 어떨까 생각이 들어요

Copy link
Contributor

Choose a reason for hiding this comment

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

horizontal까지 고려한다면 case multiple(CGFloat) 도 와드박아봅니다

Copy link
Contributor Author

Choose a reason for hiding this comment

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

multiple(CGFloat) 요 네이밍은 고민해봤었는데, 일감으로 이해하기 어렵다고 생각했어요 ㅠ

  • Verticle 스크롤: ContentSize.Height의 배수
  • Horizontal 스크롤: ContentSize.Width의 배수

요렇게 될텐데, 조금 길긴하지만 relativeContentSize(multiplier: CGFloat) 요건 어떨까요?~

Cc. @jaxtynSong @stleamist

Copy link
Member

@OhKanghoon OhKanghoon Jul 2, 2024

Choose a reason for hiding this comment

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

저는 relativeContentSize 좋아요~

Copy link
Contributor Author

Choose a reason for hiding this comment

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

relativeContentSize도 인터페이스 고민시 유사하게 나왔던 네이밍이라 해당 네이밍으로 진행해볼께요!!

Copy link
Member

@stleamist stleamist Jul 2, 2024

Choose a reason for hiding this comment

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

contentSize는 스크롤뷰 콘텐트의 전체 크기를 지칭하는 네이밍이기도 해서, 다른 네이밍을 고려해보는 것도 좋을 것 같아요! ㅎㅎ

저는 아래 두 가지 이름을 생각해 봤는데 어떠신가요?

  1. fractional(_:): 동일한 계산식을 사용하는 UICollectionViewCompositionalLayoutfractionalWidth(_:), fractionalHeight(_:)에 얼라인을 맞춘 네이밍
  2. relativeToContainerSize(multiplier:): 콜렉션뷰의 프레임을 지칭하는 NSCollectionLayoutEnvironment.container를 사용한 네이밍

Copy link
Contributor Author

Choose a reason for hiding this comment

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

fractional(_:) 요 네이밍을 고려했었는데, UICollectionViewCompositionalLayout에서는 최댓값이 1.0이더라구요
저희의 케이스의 경우 1.0 이상으로 설정할 수 있어서 자칫 오해가 생기지 않을까 우려가 되었어요..!

Copy link
Contributor Author

Choose a reason for hiding this comment

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

레이의 의견과 맥스의 의견을 조합하여 2번 relativeToContainerSize(multiplier:)으로 진행해보겠습니닷

Copy link
Member

Choose a reason for hiding this comment

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

고고고!

Copy link
Contributor Author

Choose a reason for hiding this comment

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

6f1bb2c 에서 반영했어요~

public struct EventContext {}

/// Defines the offset from the bottom of the list view that will trigger the event.
public enum OffsetFromBottom {
Copy link
Member

Choose a reason for hiding this comment

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

데-하

@ppth0608 ppth0608 force-pushed the feature/ben/MBP-4700-next-batch-trigger-2 branch from 6f1bb2c to c51243c Compare July 2, 2024 07:38
README.md Outdated Show resolved Hide resolved
Co-authored-by: Ray (Kanghoon Oh) <[email protected]>
README.md Outdated Show resolved Hide resolved
Co-authored-by: Dongkyu Kim (Max.kim) <[email protected]>
README.md Outdated Show resolved Hide resolved
Copy link
Contributor

@jaxtynSong jaxtynSong left a comment

Choose a reason for hiding this comment

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

고생 많으셨어요!!!

extension CollectionViewAdapter {

private var scrollDirection: UICollectionView.ScrollDirection {
let layout = collectionView?.collectionViewLayout as? UICollectionViewCompositionalLayout
Copy link
Member

Choose a reason for hiding this comment

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

TODO: 특정 레이아웃에 종속되지 않게 변경할 때 챙기기

Copy link
Contributor Author

Choose a reason for hiding this comment

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

요거 코멘트 추가해둘까요?~

Copy link
Member

Choose a reason for hiding this comment

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

Issue 만들어서 기록하려고 해서
코멘트는 따로 안달아주셔도 괜찮아요!

Copy link
Member

@OhKanghoon OhKanghoon left a comment

Choose a reason for hiding this comment

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

고생하셨어요 👍 👍 👍

Copy link
Member

@stleamist stleamist left a comment

Choose a reason for hiding this comment

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

고생하셨어요! 👍🏻

@ppth0608
Copy link
Contributor Author

ppth0608 commented Jul 2, 2024

리뷰해주신 @OhKanghoon @jaxtynSong @stleamist @GeekTree0101 감사합니다 🙏

Copy link
Contributor

@GeekTree0101 GeekTree0101 left a comment

Choose a reason for hiding this comment

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

LGTM

@ppth0608 ppth0608 merged commit 0e80b84 into main Jul 2, 2024
1 check passed
@ppth0608 ppth0608 deleted the feature/ben/MBP-4700-next-batch-trigger-2 branch July 2, 2024 09:37
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants