Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to use Spotlight inside NestedScrollView #114

Open
mehrdaddolatkhah opened this issue Feb 2, 2021 · 0 comments
Open

How to use Spotlight inside NestedScrollView #114

mehrdaddolatkhah opened this issue Feb 2, 2021 · 0 comments

Comments

@mehrdaddolatkhah
Copy link

Hey guys,
when I try to use Spotlight inside a NestedScrollView in the first target everything is fine. and after I scroll to the component that I need spotlight will light that component, then I need to scroll to the next component and use the spotlight. next() on that, somewhere else will light, I think the previous place for the second component, I just pass layout inflater to spotlight function one time, and I think maybe view after the second scroll won't update. may please guide me I must fix this issue?

here is my function for handle spotlight:

fun startFundSpotlight(
    layoutInflater: LayoutInflater,
    activity: Activity,
    viewModel: FundOverviewViewModel
) {

    val targets = ArrayList<Target>()
    var spot: Spotlight? = null

    val fundDetailsRoot = FrameLayout(activity.applicationContext)
    val fundDetails =
        layoutInflater.inflate(R.layout.layout_fund_otp_user_walkthrough, fundDetailsRoot)


    val fundTarget = activity.findViewById<Button>(R.id.btn_fund_start)?.let {
        Target.Builder()
            .setAnchor(it)
            .setShape(RoundedRectangle(it.height.toFloat(), it.width.toFloat(), 65f, 200))
            .setOverlay(fundDetails)
            .setOnTargetListener(object : OnTargetListener {
                override fun onStarted() {

                    val viewPager = activity.findViewById<ViewPager>(R.id.pagerFundWalkthrough)
                    val indicator = activity.findViewById<PagerIndicator>(R.id.pagerFundIndicator)

                    viewPager.adapter =
                        OtpUserFundOverviewWalkthroughPagerAdapter(
                            activity.applicationContext
                        )

                    var current = 0

                    viewPager.addOnPageChangeListener(object : ViewPager.OnPageChangeListener {
                        override fun onPageScrolled(
                            position: Int,
                            positionOffset: Float,
                            positionOffsetPixels: Int
                        ) {
                        }

                        override fun onPageSelected(position: Int) {

                            indicator.current = position

                            if (position in (current + 1)..1) {
                                viewModel.isFundSpotlightPresented.postValue(true)

                                fundDetails.refreshDrawableState()
                                fundDetails.invalidate()
                                spot?.next()

                            } else if (current > position && position <= 1) {
                                spot?.previous()
                                viewModel.isFundSpotlightViewPagerMovePrevious.postValue(true)
                            }

                            current = position
                        }

                        override fun onPageScrollStateChanged(state: Int) {}
                    })
                }

                override fun onEnded() {
                }
            })
            .build()
    }

    if (fundTarget != null) {
        targets.add(fundTarget)
    }


    val fundChartTarget = activity.findViewById<FrameLayout>(R.id.fundChart)?.let {
        Target.Builder()
            .setAnchor(it)
            .setShape(RoundedRectangle(it.height.toFloat(), it.width.toFloat(), 5f, 200))
            .setOverlay(fundDetails)
            .build()
    }

    if (fundChartTarget != null) {
        targets.add(fundChartTarget)
    }

    spot = Spotlight.Builder(activity)
        .setTargets(targets)
        .setBackgroundColorRes(R.color.spotlightBackground)
        .setDuration(200L)
        .setAnimation(DecelerateInterpolator(2f))
        .build()

    spot.start()

    val closeWalkthrough = View.OnClickListener {
        spot.finish()
    }

    fundDetails.findViewById<View>(R.id.txt_fund_walkthrough_quick_help_stop)
        .setOnClickListener(closeWalkthrough)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant