drawRect/Instagram_Stories

[question] How to reload collectionView or Cell ??

punitsilversky opened this issue ยท 23 comments

Hi @boominadhaprakash,

I added delete snap functionality in MyApp

When I delete particular snap and i reload the collection view at that time it crashs and it shows snapIndex out of range.

I want to achieve delete snap feature like instagram.

I'm stuck in reload collectionView
So, how to reload cell or collectionView??

Hi @punitsilversky

Please share your delete snap functionality code and tell me where you are trying to reload the collectionView?

I added one delete button in IGStoryPreviewHeaderView and i call its action on IGStoryPreviewController like you called for close button

Here is delete button action code

func didTapDeleteButton(snapObj: IGSnap)
{
        if let snapIndex = self.stories.stories[0].snaps.firstIndex(where: {$0.internalIdentifier == 
               snapObj.internalIdentifier})
                    {
                        self.stories.stories[0].snaps.remove(at: snapIndex)
                        self.stories.stories[0].snapsCount -= 1
                        guard let vCell = _view.snapsCollectionView.visibleCells.first as? IGStoryPreviewCell else {return}
                        vCell.stopSnapProgressors(with: (vCell.story?.lastPlayedSnapIndex)!)
                        if self.stories.stories[0].snapsCount == 0
                        {
                            self.stories.count = 0
                            self.dismiss(animated: true, completion: nil)
                        }
                        else
                        {
                            
                            if self.stories.stories[0].lastPlayedSnapIndex > self.stories.stories[0].snapsCount
                            {
                                //                                    vCell.willDisplayCellForZerothIndex(with: 0)
                                ////                                    vCell.snapIndex = 0
                                self.stories.stories[0].lastPlayedSnapIndex = 0
                            }
                            else
                            {
                                //                                    vCell.willDisplayCell(with: snapIndex)
                                ////                                    vCell.snapIndex = snapIndex
                                self.stories.stories[0].lastPlayedSnapIndex = snapIndex
                            }
                            let indexes = (0..<self.stories.count).map { IndexPath(row: $0, section: 0) }
                            self._view.snapsCollectionView.reloadItems(at: indexes)
                        }
                    }
}

Hi @punitsilversky

We are loading the items in sections not in row. So, when you reload the collection view, update the section values. I am just giving you the idea.

let indexes = (0..<self.stories.count).map { IndexPath(row: 0, section: $0) }
self._view.snapsCollectionView.reloadItems(at: indexes)

Hi @boominadhaprakash,

Thanks for Update Section values solutions, this solution work for me..

But, If i have 3 snaps and i'm deleting 2 snap after that i want to reload progressors for snap and move to third snap like instagram

So, How reload snap progressors and move to next snap if available otherwise if i deleting last snap then move to first snap

Please, See Instagram snap delete functionality, If you can see

Pls Help Me!

Thanks in Advanced

Hi @punitsilversky

The functionality which you are trying, we have already tried and it is available in Boomi/snapdelete branch. Please checkout the code from that branch and try it.

We have added the delete functionality in action sheet, it is only available for "Your Story" cell. Click Your Story and do swipe up gesture from bottom. You can see the action sheet with delete functionality.

In IGStoryPreviewController, you can find the below method.

private func deleteSnap() {
        guard let indexPath = currentIndexPath else {
            debugPrint("Current IndexPath is nil")
            return
        }
        let cell = _view.snapsCollectionView.cellForItem(at: indexPath) as? IGStoryPreviewCell
        cell?.deleteSnap()
    }

Thanks! @boominadhaprakash

This is what i looked for, it is working

I think you need to merge this Boomi/snapdelete branch to master.

If any one need it, they can try it

Hi @punitsilversky

Glad to hear that your issue resolved. We will merge it with master.

Hi @punitsilversky

We have merged the Boomi/snapdelete branch with master. Also tweaked some code related to snap delete. So take the updated source code from master branch.

Hi @boominadhaprakash

I have checked delete snap code from master branch, And One issue was there in delete snap

When snap type was video and i delete that snap at that time Progressor was stuck for next snap.

I tried it but i'm unable to find out this issue

So, Please Check this issue

Hi @punitsilversky

Okay. I will check and let you know.

Hi @punitsilversky

I have fixed the issue what you have mentioned and pushed the changes in Boomi/snapdelete branch. Checkout the code from that branch and test the delete functionality.

Let me know, if the issue is fixed or not. Once you confirmed will merge the code with master.

Hi @boominadhaprakash

I have checked Boomi/snapdelete branch code.

When snap type was video and i delete that snap after that all work good

But When I delete First image snap after that the next snap was video snap at that time progressor was stucked in video snap

I Think need to start progressor or something else After delete snap if the next snap was video

Hi @punitsilversky

Sorry, I have missed that scenario. I have fixed and updated the code in that same branch. Please check it and let me know.

Hi @boominadhaprakash

Thanks for your effort, I appreciated that

Last issue was solved, But I Found another issue

So, Please see this Zip File I've attached video in zip..

IMG_0252.TRIM.MOV.zip

Hi @punitsilversky

I will check it. Thank you.

Hi @punitsilversky

I have fixed and updated the changes in Boomi/snapdelete branch. Please checkout the latest code and let me know if you get any other issues.

Hi @boominadhaprakash

Thanks for your effort and valuable time, I appreciated that

I have checked Boomi/snapdelete branch code and I Found another issue.
Sometimes progressor stops after snap delete, But When I tap next after that it works fine

So, Please see this Zip File I've attached video in zip..

IMG_0257.MOV.zip

Okay @punitsilversky. I will check it.

Hi @punitsilversky

I have fixed those issues. Please checkout the latest changes from Boomi/snapdelete branch and check it.

Thank! @boominadhaprakash, You're Great!

I Checked it, All Issues have been solved and It Works good.

Thank you @punitsilversky for your confirmation and keeps on checking the status here.

Hi @punitsilversky

Glad to hear that issue got fixed.

Hey @punitsilversky you did very brilliant work as
this was very needed feature and you not only raised the issue but also help in testing
That is one of the unique thing i have seen.
Great going