Comments (12)
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.
@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.
@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.
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.
Taken from Apple documentation:
Optional values of non-Objective-C types aren't bridged into Objective-C.
from centeredcollectionview.
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.
@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.
Well, I can try. What do you suggest as a starting point regarding the Swifts version of currentCenteredPage
?
from centeredcollectionview.
@duraki still interested in doing this?
from centeredcollectionview.
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.
To access the current centered page from ObjC, this is probably all you need:
@objc var currentCenteredPageNumber: NSNumber? {
currentCenteredPage as NSNumber?
}
from centeredcollectionview.
This issue has gone a long time without activity, so I will mark it as stale!
from centeredcollectionview.
Related Issues (20)
- Crash on : collectionView.indexPathForItem(at: currentCenteredPoint)?.row HOT 1
- Is it possible to start the collectionView first cell at the beginning of the list and not centred ? HOT 3
- missing step from tutorial HOT 5
- how to centered collectionview with loadmore HOT 1
- currentCenteredPage change event HOT 2
- With Custome Cell we try to add more lable but its not visiable added label HOT 2
- Issue with more than 4 cells- actions affect every fourth cell. HOT 1
- First cell not centered before touch (iOS 13) HOT 13
- Support iOS 13 HOT 6
- Swipe one by one cell HOT 1
- Support Swift Package Manager HOT 3
- Corner radius is not working in iPhone 6,7,8 and x but it's working fine in xr and plus models HOT 1
- cell's position is not correct when after collectionview reloading HOT 1
- Why is this line needed? HOT 4
- Change item size which is not centered. HOT 1
- Not able to center the current cell in UITableviewCell. HOT 2
- Landscape support (in Demo app) HOT 1
- Celebrate 1K stars HOT 3
- Slide off of last page HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from centeredcollectionview.