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

creating a variable to start a story from specific snap #98

Closed UtkuDalmaz closed 4 years ago

UtkuDalmaz commented 4 years ago

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?

boominadhaprakash commented 4 years ago

Hi @UtkuDalmaz

Will check and let you know.

UtkuDalmaz commented 4 years ago

@boominadhaprakash

Thank you. Is it possible if you checked?

boominadhaprakash commented 4 years ago

@UtkuDalmaz

Some challenges are there. We are looking into it.

UtkuDalmaz commented 4 years ago

Any news? @boominadhaprakash

boominadhaprakash commented 4 years ago

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.

UtkuDalmaz commented 4 years ago

Works perfectly man Thanks!

UtkuDalmaz commented 4 years ago

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

boominadhaprakash commented 4 years ago

@UtkuDalmaz

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

UtkuDalmaz commented 4 years ago

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

boominadhaprakash commented 4 years ago

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.

UtkuDalmaz commented 4 years ago

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

boominadhaprakash commented 4 years ago

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.

UtkuDalmaz commented 4 years ago

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.

boominadhaprakash commented 4 years ago

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.

UtkuDalmaz commented 4 years ago

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

boominadhaprakash commented 4 years ago

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.

UtkuDalmaz commented 4 years ago

Ok Great I fixed it using handpickedSnapIndex. Thanks