You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
<ViewonStartShouldSetResponder={()=>{// not work by child onStartShouldSetResponder true}}onResponderEnd={()=>{// not work by child onStartShouldSetResponder true}}onTouchEnd={()=>{// still works}}><ViewonStartShouldSetResponder={()=>true}/></View>
child onPress
<ViewonStartShouldSetResponder={()=>true}onResponderEnd={()=>{// not work by child stopPropagation}}><ButtononPress={(e)=>{e.stopPropagation()}}title="btn"/></View>
onTouchEnd 对应 onTouchEnd
<ViewonTouchEnd={()=>{// not work by stopPropagation}}><ViewonTouchEnd={(e)=>{e.stopPropagation()}}/></View>
onStartShouldSetResponder={()=>true}
只有
onStartShouldSetResponder
返回为true,才会触发onResponderXXX
事件,否则不会触发;缺点是会导致 child 如果不也开启
onStartShouldSetResponder={()=>true}
就不能被响应任何事件,包括onScroll
。onTouchXXX
事件没有这个限制,但是必须是移动端模式,PC模式需要借助hammer-touchemulator
npm包模拟触发。事件冒泡
停止冒泡事件类型是一一对应的,事件类型不一致时无法阻止。
child
onStartShouldSetResponder
&onPress
对应 parentonStartShouldSetResponder
&onResponderXXX
child
onPress
onTouchEnd
对应onTouchEnd
事件捕获
默认事件冒泡响应顺序是从上到下的,即从target到root的
因此要想先执行root的,可以借助xxxCapture事件捕获
当root的
onStartShouldSetResponderCapture
返回为true时,child将不响应任何onResponderXXX
同理,当root的
onTouchEndCapture
执行preventDefault时,child将不响应onTouchEnd
The text was updated successfully, but these errors were encountered: