drawRect / Instagram_Stories

Inspired by Instagram Stories functionality. This source is similar to Instagram Stories, which is having both image and video support.
MIT License
415 stars 76 forks source link

Show stories with specific snap #93

Closed vBoykoGit closed 4 years ago

vBoykoGit commented 4 years ago

I want to start IGStoryPreviewCell from specific start index, myStartIndex for example:

  func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell {
        guard let cell = collectionView.dequeueReusableCell(withReuseIdentifier: IGStoryPreviewCell.reuseIdentifier, for: indexPath) as? IGStoryPreviewCell else {
            fatalError()
        }
        let story = viewModel?.cellForItemAtIndexPath(indexPath)
        cell.story = story
        cell.delegate = self
       cell.STARTINDEX = myStartIndex // how can i do that?
        nStoryIndex = indexPath.item
        return cell
    }
boominadhaprakash commented 4 years ago

Hi @vBoykoGit

Thanks for raising the issue. I think we have addressed this issue already. Please refer the below link.

https://github.com/drawRect/Instagram_Stories/issues/50

vBoykoGit commented 4 years ago

I have read this issue but still don't understand what property I must set to change start index

boominadhaprakash commented 4 years ago

Hi @vBoykoGit.

Go to IGStoryPreviewController, willDisplayCell method, you can find the below code,

func collectionView(_ collectionView: UICollectionView, willDisplay cell: UICollectionViewCell, forItemAt indexPath: IndexPath) {
        guard let cell = cell as? IGStoryPreviewCell else {
            return
        }

        //Taking Previous(Visible) cell to store previous story
        let visibleCells = collectionView.visibleCells.sortedArrayByPosition()
        let visibleCell = visibleCells.first as? IGStoryPreviewCell
        if let vCell = visibleCell {
            vCell.story?.isCompletelyVisible = false
            vCell.pauseSnapProgressors(with: (vCell.story?.lastPlayedSnapIndex)!)
            story_copy = vCell.story
        }
        //Prepare the setup for first time story launch
        if story_copy == nil {
            cell.willDisplayCellForZerothIndex(with: cell.story?.lastPlayedSnapIndex ?? 0)
            return
        }
        if indexPath.item == nStoryIndex {
            let s = stories.stories[nStoryIndex+handPickedStoryIndex]
            cell.willDisplayCell(with: s.lastPlayedSnapIndex)
        }
    }

In that, in the below line instead of cell.story?.lastPlayedSnapIndex in cell.willDisplayCellForZerothIndex(with: cell.story?.lastPlayedSnapIndex ?? 0), you can pass your own index like cell.willDisplayCellForZerothIndex(with: 2) or cell.willDisplayCellForZerothIndex(with: 3) like this.

if story_copy == nil {
            cell.willDisplayCellForZerothIndex(with: cell.story?.lastPlayedSnapIndex ?? 0)
            return
        }

Let us know, if you are still unable to fix the issue.

vBoykoGit commented 4 years ago

Thanks for your answer. I have changed willDisplay method as following:

if story_copy == nil {
            cell.willDisplayCellForZerothIndex(with: 1)
            return
 }

And now I'm getting this bug:

Снимок экрана 2020-04-13 в 11 56 33
boominadhaprakash commented 4 years ago

Hi @vBoykoGit

Can you please tell us, on what scenario you want to open like this?

vBoykoGit commented 4 years ago

I want to open each story separately like following:

Снимок экрана 2020-04-13 в 13 35 46

So, when I press on the story IGStoryPreviewController should show it.

boominadhaprakash commented 4 years ago

Hi @vBoykoGit

If you are opening each story separately, once that story over, should it move to next story or it should dismiss?

vBoykoGit commented 4 years ago

It should move to the next story

boominadhaprakash commented 4 years ago

Hi @vBoykoGit

I have implemented the functionality. Please refer the below issue, you will get some idea. Let us know if you have any doubt on that.

https://github.com/drawRect/Instagram_Stories/issues/98

boominadhaprakash commented 4 years ago

HI @vBoykoGit

Please check issue #98 as per my previous comment. If you have any doubts ask us. Even after apply that fix, if your issue not getting solved, please reopen this issue. I am closing it for now.

Duplicate of #98