protectedval firstTouchTarget: Field by lazy(LazyThreadSafetyMode.NONE) { val f = ViewGroup::class.java.getDeclaredField("mFirstTouchTarget") f.isAccessible = true f }
protectedval touchTargetChild: Field by lazy(LazyThreadSafetyMode.NONE) { val cls = Class.forName("android.view.ViewGroup\$TouchTarget") val f = cls.getDeclaredField("child") f.isAccessible = true f }
/** * 1. Try to get the [view]'s 'mFirstTouchTarget' field * 2. If fail, use [findTouchTargetByEvent] instead */ protectedopenfunfindFirstTouchTarget(view: View?, touchEvent: MotionEvent): View? { if (view is ViewGroup) { returntry { val touchTarget = firstTouchTarget.get(view) if (touchTarget != null) { touchTargetChild.get(touchTarget) as? View } else { findTouchTargetByEvent(view, touchEvent) } } catch (e: Throwable) { Log.e(LibName, e.toString()) findTouchTargetByEvent(view, touchEvent) } } returnnull }