Giter VIP home page Giter VIP logo

maherksantina / mspeekcollectionviewdelegateimplementation Goto Github PK

View Code? Open in Web Editor NEW
354.0 6.0 32.0 241 KB

A custom paging behavior that peeks the previous and next items in a collection view

Home Page: https://medium.com/@maher.santina90/how-to-create-cells-that-peek-on-the-sides-like-ios-11-app-store-ef4bb54c0c7d

License: MIT License

Swift 93.40% Ruby 6.60%
ios swift collectionview collectionviewlayout peek delegate implementation cell

mspeekcollectionviewdelegateimplementation's People

Contributors

alexookah avatar caiosanchez avatar digitaljerry avatar maherksantina avatar miklashevsky avatar om-ha avatar tomasandrle avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar

mspeekcollectionviewdelegateimplementation's Issues

MSPeekImplementationDelegate returning nil

I want to get the active index i implemented MSPeekImplementationDelegate the implementation is correct I already double checked everything The
func peekImplementation(_ peekImplementation: MSPeekCollectionViewDelegateImplementation, didChangeActiveIndexTo activeIndex: Int) is not being called.
This is my implemetation:

peekImplementation = MSPeekCollectionViewDelegateImplementation()
       collectionView.configureForPeekingDelegate()
       peekImplementation.delegate = self
       peekImplementation = MSPeekCollectionViewDelegateImplementation(cellSpacing: 0, cellPeekWidth: 0, scrollThreshold: 1, maximumItemsToScroll: 5, numberOfItemsToShow: 1)
       collectionView.delegate = peekImplementation
       collectionView.dataSource = self

Collection view item is getting cut off

Hi there!

I'm coming across an issue where my item gets cut off before showing it's full contents. I've attached a video of me using it.

RPReplay_Final1612853381.MP4

Scrolling with 0 velocity will not land on the correct page

If we drag a bit backwards to the previous page and remove our finger, the paging will always go to the previous page. The expected behavior should be to stay on the current page if the threshold is low

Same goes to when scrolling to the next page with no velocity, no matter how much we scroll, we'll always end up on the current page. The expected behavior is to go to the next page if the scroll is greater than the threshold

Does it support multiple sections?

Works fine with one section in collection view, but I don't know if it could with multiple sections? I find that it has larger space between sections than cells. and could be problem with scrolling.

Issue when implementing didSelectItem protocol

I've implemented my collection views this way :

mapCollectionView.configureForPeekingDelegate()
      delegate = MSPeekCollectionViewDelegateImplementation()
      delegate = MSPeekCollectionViewDelegateImplementation(cellSpacing: 5)
      delegate = MSPeekCollectionViewDelegateImplementation(numberOfItemsToShow: 3)
      delegate = MSPeekCollectionViewDelegateImplementation(cellPeekWidth: 5)
      mapCollectionView.delegate = delegate
      mapCollectionView.dataSource = self
      
      
      shortcutCollectionView.configureForPeekingDelegate()
      shortcutDelegate = MSPeekCollectionViewDelegateImplementation()
      shortcutDelegate = MSPeekCollectionViewDelegateImplementation(numberOfItemsToShow: 4)
      shortcutCollectionView.delegate = shortcutDelegate
      shortcutCollectionView.dataSource = self
      shortcutCollectionView.backgroundColor = .clear

and when calling func peekImplementation(_ peekImplementation: MSPeekCollectionViewDelegateImplementation, didSelectItemAt indexPath: IndexPath)
it seems like the function doesn't detect any of the collection vies that are implemented, swift doesn't seem to go through the function.. .

If you guys have any tips i'll be greatufull :)

Top and Bottom spacing of UICollectionViewCell cut

First, thanks for your framework it has helped a lot!

I have an issue: My custom UICollectionViewCell has a shadow at the bottom, but MSPeekCollectionViewDelegateImplementation is cutting the shadow. Is there a way to add extra spacing to top and bottom between the UICollectionViewCell and collectionView height so the shadow appears?

Thanks!

iOS 9.3 support

Hello, thanks for this nice implementation, but why did you drop support of iOS 9.3 starting from v. 1.2.0? It works perfectly on iOS 9 and no need for additional legacy code.

Consider velocity while EndDragging.

Act more like isPagingEnabled.

If the velocity of EndDragging is zero, use "if scrollDistance more than half the page width" to decide destinationIndex, instead of "scrollThreshold". #52 #

extra space !?

    behavior = MSCollectionViewPeekingBehavior(cellSpacing: 0)
    behavior = MSCollectionViewPeekingBehavior(cellPeekWidth: 0)
    behavior = MSCollectionViewPeekingBehavior(minimumItemsToScroll: 1)
    behavior = MSCollectionViewPeekingBehavior(maximumItemsToScroll: 1)
    behavior = MSCollectionViewPeekingBehavior(numberOfItemsToShow: 1)
    leagueCollectionView.configureForPeekingBehavior(behavior: behavior)

why this extra space !!?

Simulator Screen Shot - iPhone SE - 2020-05-24 at 15 55 51

cell

Screen Shot 2020-05-24 at 3 56 31 PM

Support for more than one item in the cross-axis

Currently, this lib forces the cross axis size of a cell to match that of the collection view. The App Store has another type of horizontally peeking collection view where multiple cells are displayed vertically in each page. The lib could allow specifying the number of cross-axis items to show, then use that value to calculate the appropriate item size in the collectionView:layout:sizeForItemAt: delegate func.

Screenshot of the UI I'm referring to
img_0906

Issue when switching orientation

Hey, there's an issue when switching orientation.
When I tried to select programmatically a cell, the selected cell is scrolled weirdly
Here is my codes:
var selectedItemIndex = 0

func selectAnItem(){
        let itemContentOffset = peekImplementation.scrollView(collectionView, contentOffsetForItemAtIndex: selectedItemIndex)
        collectionView.setContentOffset(CGPoint(x: itemContentOffset, y: 0), animated: false)
    }

override func viewWillLayoutSubviews() {
        selectAnItem()
    }

func peekImplementation(_ peekImplementation: MSPeekCollectionViewDelegateImplementation, didChangeActiveIndexTo activeIndex: Int) {
    print("Changed active index to \(activeIndex)")
    selectedItemIndex = activeIndex
}

func peekImplementation(_ peekImplementation: MSPeekCollectionViewDelegateImplementation, didSelectItemAt indexPath: IndexPath) {
    print("Selected item at \(indexPath)")
}

a Gif:
ezgif-5-098a5e011014

For users having this issue, you can do this:

override func draw(_ rect: CGRect) {
        super.draw(rect)
        self.collectionView.collectionViewLayout.invalidateLayout()
        self.selectAnItem()
    }

RxCollectionView only shows one cell always

Good morning Maher! again thanks for your work.

I'm having a doubt, I'm using RxCollectionView and in that case the dataSource it's
fileprivate func dataSource() -> RxCollectionViewSectionedReloadDataSource
and MSPeek collectionView it's only showing one cell in all cases...

Do you have any idea, what can I do?

Thanks!

Use of undeclared type 'MSCollectionViewPeekingBehavior'

After installing the pod pod 'MSPeekCollectionViewDelegateImplementation' and using it in a ViewController. I get this error on declaration of behaviour variable

var behavior: MSCollectionViewPeekingBehavior!

Error: Use of undeclared type 'MSCollectionViewPeekingBehavior'

Clip last item

Simulator Screen Shot - iPhone 11 - 2019-11-06 at 15 51 32

I've followed instruction but when render, I got the last item clipped.

Active cell support

I want to congratulate you for this lib, it's very cool. However, I think one key feature is missing and it is an active cell support. Is there a way to easily understand (from the controller) which cell is active?

Alignment horizontal scroll collection view

Hey,

any idea hot to align horizontal collection view items to left when it is first item then after that could work normally with centered item. Like AppStore product carousel ...

Use of undeclared type 'MSCollectionViewPeekingBehavior'

After installing the pod pod 'MSPeekCollectionViewDelegateImplementation' and using it in a ViewController. I get this error on declaration of behaviour variable

var behavior: MSCollectionViewPeekingBehavior!

Error: Use of undeclared type 'MSCollectionViewPeekingBehavior'

MSPeekImplementationDelegate returns under/over index in race conditions

MSPeekImplementationDelegate method:

func peekImplementation(_ peekImplementation: MSPeekCollectionViewDelegateImplementation,
                            didChangeActiveIndexTo activeIndex: Int)   

Returns -1 if continuous fast swipe attempts made to go below the first cell...
or returns dataSource.count if trying to swipe beyond max cell.

This only happens when I really push it and swipe super fast.

Device: iPhone SE running 13.3.1
Xcode 11.3.1
Installed via cocoapods

pod 'MSPeekCollectionViewDelegateImplementation', '~> 2.0.0'

Screen Shot 2563-06-26 at 20 33 21

Support safe area insets where appropriate

Currently, the safe area is ignored. If a collection view is rendered on an iPhone X in landscape, the cells under run the safe area. A workaround is to add the left or right safe area inset to the cellPeekWidth and reconfigure the delegate implementation when the view transitions sizes. Easy enough, but feels like it should be handled automatically or as another configuration argument.

Support Dynamic Width?

Great Thanks to your repo , do you have plan to support dynamic cell width please? thanks again

Crash on behavior.scrollViewWillEndDragging call in v3.1.1

After updating to v3.1.1 the app crashes when releasing finger after a swipe. It works without any change with the 2 previous versions.

  • The crash happens on the behavior.scrollViewWillEndDragging call
  • behavior is not nil
func scrollViewWillEndDragging(_ scrollView: UIScrollView, withVelocity velocity: CGPoint, targetContentOffset: UnsafeMutablePointer<CGPoint>) {
        behavior.scrollViewWillEndDragging(scrollView, withVelocity: velocity, targetContentOffset: targetContentOffset)
}

Didn't see anything in the changelogs that would explain this sudden crash.

Any ideas why this is happening ?

Selection not working.

@objc optional func peekImplementation(_ peekImplementation: MSPeekCollectionViewDelegateImplementation, didSelectItemAt indexPath: IndexPath) doesn't work and not even appears on the autocomplete in Xcode.

Checking MSPeekCollectionViewDelegateImplementation from the Pod project it seems it is not in the MSPeekImplementationDelegate. Only the following is shown:

public protocol MSPeekImplementationDelegate: AnyObject {
    func peekImplementation(_ peekImplementation: MSPeekCollectionViewDelegateImplementation, didChangeActiveIndexTo activeIndex: Int)
}

func peekImplementation(_ peekImplementation: MSPeekCollectionViewDelegateImplementation, didChangeActiveIndexTo activeIndex: Int) seems to be working fine.

And my current implementation is as below:

let peekImplementation = MSPeekCollectionViewDelegateImplementation(cellSpacing: 16.0, cellPeekWidth: 16.0)

collectionView?.dataSource = self
collectionView?.configureForPeekingDelegate()
collectionView?.delegate = peekImplementation
peekImplementation.delegate = self

Am I missing something?

sizeForItem delegate function is not called when peek behavior is configured

Hi there,

I noticed that when I have MSPeekCollectionViewDelegateImplementation implemented, that my collectionView's sizeForItem delegate function is not called. I'm not sure why though. Is this expected or perhaps I have a bug in my code? sizeForItem is called as expected when the peeking behavior is not configured.

I need to be able to configure my item's size while also implementing peek behavior. Does anybody have any advice?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.