Skip to content

Commit

Permalink
bring back D61474707
Browse files Browse the repository at this point in the history
Summary:
D61474707 removes touch handling from `HostRenderUnit`

Repeating the summary below:

----
> The HostRenderUnit's touch handling can interfere with touch handling by other binders attached to it (e.g from Bloks extensions).

> Specifically, it clobbers touch listeners that may have been set on the view by these other binders.

> Looking into this more, I do not see any usage of these touch handling capabilities on the HostRenderUnit.  Given that this is only used in Bloks and Bloks uses touch & gesture extensions, we should probably just remove it from here.

Reviewed By: rooju

Differential Revision: D63074402

fbshipit-source-id: ced7b777e85029c7bce12ae6a68dffda947db24f
  • Loading branch information
Daniel Famakin authored and facebook-github-bot committed Sep 26, 2024
1 parent e8e8c42 commit fd7f3a9
Show file tree
Hide file tree
Showing 2 changed files with 0 additions and 36 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,9 @@ import android.content.Context
import android.graphics.drawable.Drawable
import android.view.View
import android.view.View.OnFocusChangeListener
import android.view.View.OnLongClickListener
import android.view.View.OnTouchListener
import androidx.annotation.IntDef
import com.facebook.rendercore.ContentAllocator
import com.facebook.rendercore.HostView
import com.facebook.rendercore.InterceptTouchHandler
import com.facebook.rendercore.RenderUnit
import com.facebook.rendercore.RenderUnit.DelegateBinder.Companion.createDelegateBinder

Expand All @@ -48,10 +45,7 @@ open class HostRenderUnit(override val id: Long) :
var isFocusable: Boolean = false
var isFocusableInTouchMode: Boolean = false
var onFocusChangeListener: OnFocusChangeListener? = null
var onInterceptTouchEvent: InterceptTouchHandler? = null
var onLongClickListener: OnLongClickListener? = null
var onClickListener: View.OnClickListener? = null
var onTouchListener: OnTouchListener? = null

override fun createContent(context: Context): HostView {
return HostView(context)
Expand Down Expand Up @@ -199,16 +193,10 @@ open class HostRenderUnit(override val id: Long) :
hostRenderUnit: HostRenderUnit,
layoutData: Any?
): Any? {
hostView.setOnTouchListener(hostRenderUnit.onTouchListener)
hostView.setInterceptTouchEventHandler(hostRenderUnit.onInterceptTouchEvent)
val onClickListener = hostRenderUnit.onClickListener
if (onClickListener != null) {
hostView.setOnClickListener(onClickListener)
}
val onLongClickListener = hostRenderUnit.onLongClickListener
if (onLongClickListener != null) {
hostView.setOnLongClickListener(onLongClickListener)
}
val onFocusChangeListener = hostRenderUnit.onFocusChangeListener
hostView.onFocusChangeListener = onFocusChangeListener
hostView.isFocusable = hostRenderUnit.isFocusable
Expand All @@ -228,12 +216,8 @@ open class HostRenderUnit(override val id: Long) :
layoutData: Any?,
bindData: Any?
) {
hostView.setOnTouchListener(null)
hostView.setInterceptTouchEventHandler(null)
hostView.setOnClickListener(null)
hostView.isClickable = false
hostView.setOnLongClickListener(null)
hostView.isLongClickable = false
hostView.onFocusChangeListener = null
hostView.isFocusable = false
hostView.isFocusableInTouchMode = false
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@ import android.view.View.OnTouchListener
import android.widget.TextView
import androidx.test.core.app.ApplicationProvider
import com.facebook.rendercore.RenderUnit.RenderType
import com.facebook.rendercore.renderunits.HostRenderUnit
import com.facebook.rendercore.testing.DrawableWrapperUnit
import com.facebook.rendercore.testing.LayoutResultWrappingNode
import com.facebook.rendercore.testing.RenderCoreTestRule
Expand Down Expand Up @@ -211,25 +210,6 @@ class HostViewTest {
Java6Assertions.assertThat(point.y).describedAs("touch y is").isEqualTo(10)
}

@Test
fun onHostRenderUnitWithTouchListener_shouldHandleTouchEvent() {
val unit = HostRenderUnit(1)
val point = Point(0, 0)
unit.onTouchListener = OnTouchListener { v, event ->
point.x = event.x.toInt()
point.y = event.y.toInt()
true
}
val root: LayoutResult =
SimpleLayoutResult.create().renderUnit(unit).width(100).height(100).build()
renderCoreTestRule.useRootNode(LayoutResultWrappingNode(root)).render()
val host = (renderCoreTestRule.rootHost as HostView).getChildAt(0) as HostView
val event = MotionEvent.obtain(200, 300, MotionEvent.ACTION_BUTTON_PRESS, 10.0f, 10.0f, 0)
host.dispatchTouchEvent(event)
Java6Assertions.assertThat(point.x).describedAs("touch x is").isEqualTo(10)
Java6Assertions.assertThat(point.y).describedAs("touch y is").isEqualTo(10)
}

private class TestRenderUnit(renderType: RenderType) :
RenderUnit<Any>(renderType), ContentAllocator<Any> {

Expand Down

0 comments on commit fd7f3a9

Please sign in to comment.