I had the same problem, in particular, that the Hammer nested component was not properly stopping the distribution. In my case, I wanted to use a modal container (which was the parent component of the highest level, full screen with an opaque black background) to handle the click event, which closed the entire modal. Children's components contain content, and I wanted to cancel distribution with these children. In other words, the desired behavior: clicking inside the modal does nothing, but clicking outside the modality closes the modal.
This is further complicated by the react-hammerjs , which adds an extra layer of abstraction, including potential error reports that indicate the wrong event propagation.
No matter what I did, I could not get stopPropagation() to work. Even with options.domEvents set to true. I also tried falling into event.srcEvent.stopPropagation() (and options) without success.
I found that using stopImmediatePropagation() works as intended, regardless of the domEvents parameter. I understand that stopImmediatePropagation() may be more extreme, but I have no side effects. Click handlers inside child elements (e.g. buttons) still work fine, and I can cancel the modal file by clicking on the container.
Here is my last snippet that works great:
const myComponent = (props) => ( <Hammer onTap={() => { ... cancel modal ... }} > <div className={'modal-container'} > <Hammer onTap={(e) => e.srcEvent.stopImmediatePropagation()}> <div className={'modal-content'}> ... modal content <Hammer onTap={() => { ... button handler ... }}> <button>Take Action</button> </Hammer> </div> </Hammer> </div> </Hammer> )
source share