drawRect/Instagram_Stories

creating a variable to start a story from specific snap

UtkuDalmaz opened this issue ยท 17 comments

Hi there

I am trying to add a variable to start a story from specific snap in IGStoryPreviewController

init(layout:IGLayoutType = .cubic,stories: IGStories,handPickedStoryIndex: Int) {
        self.layoutType = layout
        self.stories = stories
        self.handPickedStoryIndex = handPickedStoryIndex
        super.init(nibName: nil, bundle: nil)
    }

here I want to add something like handPickedSnapIndex so I can do sth like

let storyPreviewScene = IGStoryPreviewController.init(stories: stories_copy, handPickedStoryIndex: indexPath.row-1, handPickedSnapIndex: 6)

Can you help me with this?

Hi @UtkuDalmaz

Will check and let you know.

@boominadhaprakash

Thank you. Is it possible if you checked?

@UtkuDalmaz

Some challenges are there. We are looking into it.

Hi @UtkuDalmaz

I have implemented the requirement what you are expecting. Please take the source code from this branch Boomi/issues98 and let me know is it working fine or not.

I have modified code in IGStoryPreviewController and IGStoryPreviewCell.

In IGHomeController, as per your requirement, you can pass it like this.

let storyPreviewScene = IGStoryPreviewController.init(stories: stories_copy, handPickedStoryIndex: indexPath.row-1, handPickedSnapIndex: 2)

If you are not passing any handPickedSnapIndex, it will consider the default value as 0.

Works perfectly man Thanks!

I guess there is a little bug here, lastPlayedSnapIndex is not correct when init with handPickedSnapIndex. Can you check it @boominadhaprakash ?

When handPickedSnapIndex is 2
snapIndex in IGStoryPreviewCell is 0

@UtkuDalmaz

The handpicked snap index only applicable for handpicked story index. Rest of the stories starts with index 0 only.

I am talking about the same story.
For example in a story if I set handpicked snap to 2, it should be snapIndex = 2 in also IGStoryPreviewCell
That way I can set story?.snaps[snapIndex] and send data to server

One more thing, snapIndex starts from 0. If you set to 2 means, it will start from the 3rd snap.

But which ever snapIndex you are setting, it will start from that only for that story. It will not start from 0.

I know it.
I added some code to switch direction { case .forward: in IGStoryPreviewCell and send request to server to mark it SEEN
So If I set handpicked snap to 2 (it will start from 3. snap) I also need to get snapIndex as 2 to send correct data to server but currently it starts from 0 and send wrong data to server.

If I manually backward to previous snap, it gets correct index

oh okay. May be in IGStoryPreviewController cellForRowAtIndexPath, I am resetting the handPickedSnapIndex to 0 again. Because once that corresponding story completes, the next story should start from 0 right.

If you want, you can store that handPickedSnapIndex to some other local variable to monitor that.

See, we need to start the snapIndex from 0 only, even if you set the handPickedSnapIndex to some other value. Because we need to pre-populate the snaps and Progressors until that handPickedSnapIndex.

This functionality is your own requirement. We can't do nothing with our library code. If you want, you can customise the IGStoryPreviewCell and IGStoryPreviewController as per your wish.

Thanks for the info but it happens before the story completes. I need to get correct index as soon as snap starts. If you have an idea to fix it please share.

We need to see your code, from where you are reading the snapIndex and sending it to server and all. Then only we can guide you.

Got it. How can I access handpicked snap index in IGStoryPreviewCell?

In IGStoryPreviewCell, already handPickedSnapIndex variable is there. We are passing the handPickedSnapIndex from Controller to Cell and assigning it to that variable.

public func willDisplayCellForZerothIndex(with sIndex: Int, handpickedSnapIndex: Int) {
     self.handpickedSnapIndex = handpickedSnapIndex
     story?.isCompletelyVisible = true
     willDisplayCell(with: handpickedSnapIndex)
 }

And once that snap completes, we are resetting that self.handpickedSnapIndex to 0. So, you can create one dummy variable in IGStoryPreviewCell and store that value.

Ok Great I fixed it using handpickedSnapIndex. Thanks