ephread / Instructions

Create walkthroughs and guided tours (coach marks) in a simple way, with Swift.
MIT License
5.16k stars 491 forks source link

Scroll to a certain cell on collection view before presenting the next CoachMarkView #249

Closed lmbcosta closed 4 years ago

lmbcosta commented 4 years ago

Question

After reading the documentation and make some tests on a sample project, I wasn't able to solve this situation:

This only works if I pass animated argument as false: collectionView.scrollToItem(at: .init(row: 3, section: 0), at: .centeredVertically, animated: false) It will give me the previous position of the cell before the scroll, otherwise

I also tried scroll on other delegate functions like:

func coachMarksController(_ coachMarksController: CoachMarksController,
                              didHide coachMark: CoachMark,
                              at index: Int) {
        if index == 0 {
            childViewController.collectionView.scrollToItem(at: .init(row: 3, section: 0), at: .centeredVertically, animated: true)
        }
    }

and then update on delegate function

func coachMarksController(_ coachMarksController: CoachMarksController,
                              willShow coachMark: inout CoachMark,
                              beforeChanging change: ConfigurationChange,
                              at index: Int) {
        if index == 1 {
            let markView = collectionView.cellForItem(at: .init(row: 3, section: 0))
            coachMark = coachMarksController.helper.makeCoachMark(for: markView, cutoutPathMaker: { UIBezierPath(roundedRect: $0, cornerRadius: coachMarkView.frame.height / 2) })
        }

    }

and still not work.

Is there a way to handle this situation? The worst scenario: if collection view didn't dequeue a cell for certain indexPath. But let focus on the example

Thank you

ephread commented 4 years ago

Hey @lmbcosta, so Instructions is always a bit tacky when used will collections.

But what you can do is look into pausing and resuming the flow (also, have a look at this example)

You should be able to achieve what you want by pausing the flow in willShow, scrolling to the appropriate item and resuming the flow after the scroll completed.

lmbcosta commented 4 years ago

Hello, @ephread. Thank you for the reply. I was testing and, yes, I was able to make it work using pause/resume strategy. Consider this issue closed

ephread commented 4 years ago

I'm glad to hear that!