Giter Site home page Giter Site logo

Comments (12)

BenEmdon avatar BenEmdon commented on August 17, 2024 1

Instead of modifying the swift implementation of currentCenteredPage, you could write a new calculated variable and implement it exactly like so #38 (comment).

Deciding the name of such a variable is the hard part 😅 Here are some name ideas:

  • currentCenteredPageOBJC
  • currentCenteredIndex

from centeredcollectionview.

BenEmdon avatar BenEmdon commented on August 17, 2024 1

@duraki Take care of yourself 💖I totally feel you and I have also had less bandwidth during this time.

I'll add the help wanted label in case anyone else wants to pick this up 👋

from centeredcollectionview.

BenEmdon avatar BenEmdon commented on August 17, 2024

@farazhaider88 I think the best place to get an answer to this question is to look at Apple's documentation. https://developer.apple.com/documentation/swift/imported_c_and_objective-c_apis/importing_swift_into_objective-c

I am not sure this package will work out of the box with Objective-C (as I have not tried). If you find a way to make this work please report/contribute back!

from centeredcollectionview.

duraki avatar duraki commented on August 17, 2024

I don't want to open new issue but I've tried this extension with Objective-C and it works very well. The only problem is we can't observe the currentCenteredPage.

NSInteger *currentIndex = self.centeredCollectionViewFlowLayout.currentCenteredPage;

Throws error Property 'currentCenteredPage' not found on object of type 'CenteredCollectionViewFlowLayout *'. I'm guessing it's because of Int? but I'm not proficient with Swift enough. Any input is highly appreciated.

Thanks!

from centeredcollectionview.

duraki avatar duraki commented on August 17, 2024

Taken from Apple documentation:

Optional values of non-Objective-C types aren't bridged into Objective-C.

@BenEmdon

from centeredcollectionview.

duraki avatar duraki commented on August 17, 2024

This is how I did it (hotfix, not sure how smart it is):

    /// Calculates the current centered page.
    @objc public var currentCenteredPage: Int {
        guard let collectionView = collectionView else { return -1 }
        let currentCenteredPoint = CGPoint(x: collectionView.contentOffset.x + collectionView.bounds.width/2, y: collectionView.contentOffset.y + collectionView.bounds.height/2)
        
        return collectionView.indexPathForItem(at: currentCenteredPoint)?.row ?? -1
    }

Returns -1 if no cell is at centered point.

from centeredcollectionview.

BenEmdon avatar BenEmdon commented on August 17, 2024

@duraki this seems like a reasonable change, but it would break the API. If you would like an API to observe currentCenteredPage we could instead create a new API. If you submit a PR, I will definitely review it 😉

from centeredcollectionview.

duraki avatar duraki commented on August 17, 2024

Well, I can try. What do you suggest as a starting point regarding the Swifts version of currentCenteredPage?

from centeredcollectionview.

BenEmdon avatar BenEmdon commented on August 17, 2024

@duraki still interested in doing this?

from centeredcollectionview.

duraki avatar duraki commented on August 17, 2024

Sure, although a bit busy right now with the case of pandemic. If anyone is able to tackle it down I'm more then available to help.

from centeredcollectionview.

wassup- avatar wassup- commented on August 17, 2024

To access the current centered page from ObjC, this is probably all you need:

@objc var currentCenteredPageNumber: NSNumber? {
    currentCenteredPage as NSNumber?
}

from centeredcollectionview.

github-actions avatar github-actions commented on August 17, 2024

This issue has gone a long time without activity, so I will mark it as stale!

from centeredcollectionview.

Related Issues (20)

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.