How to use Spotlight inside NestedScrollView
mehrdaddolatkhah opened this issue · 0 comments
mehrdaddolatkhah commented
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)
}