-
Notifications
You must be signed in to change notification settings - Fork 810
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
IMPORTANT: Here are some of the changes in version 7+. It will cause some code breaks. #553
Comments
For what it's worth, I personally like to create my own |
@ahmed-sal thanks for the input. I put it up here so that people can let me know if they are using the I am removing it because of synchronization issues. in some edge cases. |
I would rather keep it clean and always use You're doing a great job at building the |
another vote for ♥︎ cellState.isSelected and ditto on the great job. |
@patchthecode I was just noting that, regarding the first problem, in most cases it is not really necessary to create the Thanks again for the library and your awesome support. |
@boborbt you know.. that's actually a good idea haha. I wasnt thinking that route, but yes, this will be cleaner. |
Version 7.1 released. closing this issue |
@patchthecode - thanks for this update, spent a few hours trying to figure out what was going wrong in my code, but this solved everything. I have a question though, why can't you use dequeueReusableCell in the willDisplay function? This was causing me an error as an unselected cell would appear to be selected, but I don't understand why this is the case. Thank you 💯 |
@arjunmadgavkar This lib is built from a UICollectionView. It behaves the same way. |
@PrincessKimchi theres a sample project attached to this repository. |
willDisplayCell does not get called for me. Delegate and data source are both connected, and the dequeue-function works and is called as it should. willDisplayCell is simply ignored. Any idea why? |
willDisplay gets called. |
I think the root of the issue is updating the appearance of the cell within the controller violates MVC. The The What I typically do is update the appearance in the view itself: override var isSelected: Bool {
didSet {
updateCellAppearance()
}
}
updateCellAppearance() {
if isSelected {
// ...
} else {
// ...
}
}
updateCell(info) {
// ...
updateCellAppearance()
} That way it doesn't matter if the cell gets updated from The way I see it |
@lukescott
|
@patchthecode Sorry! I'll see if I can be clearer. The way CellState is designed it mixes concerns. A cell is part of the UI. A date is part of the model (state). It should be "DateState" or "DateInfo". CellState also can return cell. It should have indexPath on it instead. The problem with "CellState", and having to update the appearance in"willDisplay" and "cellForItemAt" has to do with mixing concerns in MVC. You have view code in the controller, and in the case of CellState, binding the view to the model. If "CellState" was "DateState" or "DateInfo" and had indexPath on it you could lookup the cell in the controller using indexPath (if you needed it). Fixing the willDisplay problem doesn't require any code changes. It's just a documentation / education thing. Update appearance code in the cell view class. Anyone can do that today. The "CellState" thing is not related. Just wanted to point out that the model is being tightly coupled to the view layer. I'm not really a fan of MVC, but Apple uses it, so I have to follow it. I prefer Component based architecture as I find it easier to understand. |
Thank you for this fix, it helped a lot. To hopefully save someone else the confusion that I went through with the above code snippet provided in the original post: testCalender is actually just an instance of Calendar.current, and red is UIColor.red (and the white). |
please note, that configure is invoked in two places for a reason, at least according to the [docs](https://patchthecode.com/jtapplecalendar-home/calendar-from-scratch/): > These 2 functions should contain the same code, therefore it is wise > to have a shared function to reduce code duplication. The only > difference between these two functions should be the first line of code > (the dequeuing code). Reasons for the 2 functions having the same code > are found [here under problem#1](patchthecode/JTAppleCalendar#553).
TLDR
willDisplayCell
function as stated below.cell.isSelected
I will be removing it. Instead usecellState.isSelected
.
Problem 1: UICollectionView cell pre-fetching enables your calendar to scroll smoothly. But some problems arise.
A case can arise where a cell is already pre-fetched, but is still not yet visible on the screen.
In a case like this, lets say a user selects the
Feb1
outDate.Then the Feb1st
inDate
on the other month has to also be updated to show a selection.Now If the cell is already prefetched, but still invisible, there is no way for JTAppleCalendar library to send you an instance of the already prefetched cell so that it can be updated.
The way I handled this in version 7.0.6 was to call reloadIndexPaths, but this invalidates the layout. In order to save the layout much code was done which caused subtle bugs to form.
According to Apple documentation ,
Therefore, in the 7.1.0 version of JTAppleCalendar, i'll be forcing you developers to implement this
willDisplay
function sadly. I did not want to do this because I think implementing 2 functions with the same code is silly, but it seems that I was coding against the grain. The contents of this function will be exactly the same as the code located in thecellForItemAtIndex
function (except the cell dequeuing part). Therefore in order to avoid code duplication, you can create a common function that is run by both those functions.If a developer can show me how to invalidate an already prefetched, but still hidden cell in a UICollectionView, then we would not have to do this.
Here is an example of what you developers should do when implementing this with a shared function to reduce code:
OR as developer @boborbt mentioned below, you can just do all you setup inside the
willDisplayCell
function. And for yourcellForIndexPath
function, simply do thisProblem 2: UICollectionViewCell.isSelected may be out of sync.
I am thinking on removing the property of
isSelected
on a cell as it can incorrect.In the library if the calendar is in single selection mode, if a user selects say
Feb1
, then I also cause its outDate counter part to be selected.Here 2 cells will be "selected" even though it is on single selection. I track this magic with the CellState struct. Therefore
cellState.isSelected
will always give you a correct value. But developers are used to using theCell.isSelected
property. And this causes confusion when a cell that is supposed to be selected gives an incorrect value.Therefore I am going to make the Cell.isSelected property unavailable unless a developer can come up with a good alternative solution. Else, Users should only use the cellState inorder to determine if a cell is selected or not.
The text was updated successfully, but these errors were encountered: