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
414 stars 76 forks source link

Need pause and resume when redirect to another controller on click button action and pop to story module. #103

Closed ramanocs1145 closed 4 years ago

ramanocs1145 commented 4 years ago

Describe the bug In my requirement I have implemented Tag button for knowing another product details by redirecting with another controller. The Tag button creation process on this method success case private func startRequest(snapView: UIImageView, with url: String, placeholderImage: UIImage? = nil, aSnapInfo: Snap)

Here If a story have couple of image type stories. when I click on tag button at second index story image and button action fired redirection process at this time you can see the corresponding story pause with 0th index image instead of 1st one. I have checked lot how it could be changed? but I can't trace where it's happening.

Kindly check the attached video.

To Reproduce Steps to reproduce the behavior:

  1. Go to 'Story Module'
  2. Click on 'Tag button which is representing on image story'
  3. See error - Pause and Resume will not working with corresponding Story snap index

Expected behavior If I open a story > Click on a tag product > Open product detailed view > Go back to story, most of the time it's just like if the story time still went on while I was checking the other product. As a result usually I am when going back directly moved to a new Story. It should sort of "pause" the story and when going back I should start over.

Recorded Video PauseAndResumeIssuewithCorrespondingSnapIndex.mov.zip

Kindly check the attached video and suggest me how to achieve pause the current snap and start resume will come back from redirect controller?

I know already you have achieved entire snap pause and resume process when long press. But that's not working for my requirement. Please it's bit urgent. I'm excepting your kind help cause I have tried couple of days to achieve this feature.

boominadhaprakash commented 4 years ago

Hi @ramanocs1145

Actually when you click tag button, it will pause on the second snap only. But the problem is occurring, when you are clicking back button. Check is there any collection view or cell related method calling by putting breakpoint when you are clicking back button. If collection view methods are calling means, you can manage with bool variable. When you tap tag button, you can make it true/false. When you click back button, so that methods will not call. Again you revert that bool value.

Pause and Resume will work for long press for sure. We don't know the UI of your button occupies how much area of your screen. Your button tap gesture should not collide with long press gesture.

ramanocs1145 commented 4 years ago

Hi @boominadhaprakash ,

Thanks for your quick reply.

Could you see the tag button click on that recorded video? you should see first index story image when click tag icon at during second index.

Regarding your point - But the problem is occurring, when you are clicking back button. - Let me check with break point and update you asap.

boominadhaprakash commented 4 years ago

Hi @ramanocs1145

Yes, I replied you after saw that video only.

ramanocs1145 commented 4 years ago

Hi @ramanocs1145

Yes, I replied you after saw that video only.

Could you see it again please? cause on that video the current story having couple of image type stories. so I have clicked tag icon at second index story. so you can see the first index story image during the redirection push.

And FYI: I have added that tag button subview and bringSubviewToFront of contentView

Like below,

contentView.addSubview(aTagButton)
contentView.bringSubviewToFront(aTagButton)
boominadhaprakash commented 4 years ago

Hi @ramanocs1145

Can you paste the tag button action code? Is that tag button is assigned to each snap, or is it common for entire story?

ramanocs1145 commented 4 years ago

Hi @boominadhaprakash ,

I have implemented that tag action like on your demo source which is downloaded from here. Please check IGStoryPreviewCell class private func startRequest(snapView: UIImageView, with url: String) for added the tag button indicate with background color.

I hope now you can see the issue. Please try with Lara user cause she have all image type stories and make button action after 2nd or 3rd image process.

Instagram_Stories-master.zip

boominadhaprakash commented 4 years ago

Hi @ramanocs1145

I will check and let you know.

ramanocs1145 commented 4 years ago

Hi @boominadhaprakash ,

Any idea? Seems scrollview content offset automatically set with zero. how to prevent this?

ramanocs1145 commented 4 years ago

Hi @boominadhaprakash ,

I think I have fixed this issue - scrollview content offset automatically set with zero by storing scrollViewContentOffset values on separate variable willMoveToPreviousOrNextSnap && didCompleteProgress.

And then I have updated that contentOffset variable to scrollView content offset on UIScrollViewDelegate scrollViewDidScroll like,

extension IGStoryPreviewCell: UIScrollViewDelegate {
    func scrollViewDidScroll(_ scrollView: UIScrollView) {
        if scrollView.contentOffset.x == 0 {
            self.makeUpdateCurrentScrollContentOffset()
        }
    }
}

And also called self.makeUpdateCurrentScrollContentOffset from IGStoryPreViewViewController viewWillDisappear as well as resume the current snap like below,

    public func resumeCurrentSnap() {

        self.aExistedProgressView?.resume()

        if let aStory = self.story {
            let n = aStory.lastPlayedSnapIndex
            clearLastPlayedSnaps(n)
            stopSnapProgressors(with: n)

            direction = .backward

            resetSnapProgressors(with: n)
            willMoveToPreviousOrNextSnap(n: n)
        }
        self.isCalledTagButtonAction = false
    }

    public func makeUpdateCurrentScrollContentOffset() {
        let xValue = snapIndex.toFloat * scrollview.frame.width
        scrollview.setContentOffset(self.recentContentOffset ?? CGPoint(x: xValue, y: 0), animated: false)
    }

Seems working smooth. Here after it will cause any major issues, I will let you know asap. Thanks for your valuable support!!!

boominadhaprakash commented 4 years ago

@ramanocs1145 Good to hear!!