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

Start with specific snap #50

Closed pcentieiro closed 5 years ago

pcentieiro commented 5 years ago

Hello!

Thanks for this library which I found it very robust and complete. While it supports to go to a specific story, how can I go to a specific snap before launching the story?

I tried to set lastPlayedSnapIndex before opening the story, but it gets confused and seems that all the progress bars start playing after that index.

Thanks!

boominadhaprakash commented 5 years ago

Hi @pcentieiro

Give us sometime, we will test it and let you know.

pcentieiro commented 5 years ago

Thanks! I saw your edited posts. This is what I'm trying to achieve:

If I was not cleared enough, I can post a video if you want, but it is very similar to "Previews" in Netflix app :)

I was thinking in loading the story and then make "fake" clicks on the screen to go to the snap I want, but I wouldn't go forward without your feedback, because I don't know the impact on the rest of the code...

Tbh, I don't want to use another InstagramStories library, because from what I found, yours is the most complete in github. Is there anything where I can help?

PS: I don't have a problem with the previous snaps being filled (before lastPlayedSnapIndex). That's the intended behaviour really! The problem is the ones after it :)

boominadhaprakash commented 5 years ago

Hi @pcentieiro

I have modified our Instagram Stories code to support your requirement.

Please download the check the code from this branch: Boomi/lastplayedsnapissue

Now you can blindly set snapIndex value in IGStoryPreviewController, WillDisplayCell method.

Sample code for you.

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: 2)
            return
        }
        if indexPath.item == nStoryIndex {
            let s = stories.stories[nStoryIndex+handPickedStoryIndex]
            cell.willDisplayCell(with: s.lastPlayedSnapIndex)
        }
    }

If you face any issues, please feel free to raise issues.

pcentieiro commented 5 years ago

Works flawlessly 👌

Thanks a lot man!!

boominadhaprakash commented 5 years ago

Welcome @pcentieiro

sourish commented 4 years ago

HI @boominadhaprakash / @pcentieiro , Could you please tell me how can i open a particular snap with snapIndex. Could you please brief me about this