question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Add option for "dead space"

See original GitHub issue

I am using both react-swipeable-views and react-sidebar in a project. There is an issue where swiping open the sidebar also swipes the views. I am not sure what the best solution would be in this case, but I was thinking it would be nice with there was an option for left, right, top, and bottom “dead space” in react-swipeable-views. This way react-sidebar’s touch would occupy the disabled space the two wouldn’t interfere.

I am open for suggestions if there is a better way of going about this. Thanks!

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Comments:10 (3 by maintainers)

github_iconTop GitHub Comments

2reactions
tuoxianspcommented, Aug 2, 2021

Met the same problem: react-swipeable-views + react-slider.

Because these two libs all need to ensure keep on swiping/sliding while user’s finger/mouse left target element, so they all used document.addEventListener('touchmove', handler) rather than onTouchMove.

Attemping to stop bubbling between swipeable view and slider will break both of them.

My solution was forking react-slider and modify the add event method with useCapture: true:

addEventListener('touchmove', handler, true) //use capture

This will ensure the slider could receive touch events.

Then create a ‘DeadSpace’ component to stop bubbling events:

const DeadSpace: FC = ({ children }) => {
  const ref = useRef<HTMLDivElement>(null);
  useLayoutEffect(() => {
    const stopBubble = (e) => e.stopPropagation();
    ref.current?.addEventListener("touchmove", stopBubble);

    return () => {
      ref.current?.removeEventListener("touchmove", stopBubble);
    };
  }, []);

  return <div ref={ref}>{children}</div>;
};

And use it to wrap slider like this:

<SwipeableView>
  <DeadSpace>
    <Slider />
  </DeadSpace>
</SwipeableView>
0reactions
henryhs97commented, Apr 25, 2021

Was someone able to figure this out? I’m trying to also make some ‘dead space’ within a SwipeableViews component because I’m adding a MaterialUI slider (and dragging the slider causes the whole view to be swiped instead).

This is what I have:

<Box display="flex" justifyContent="center" alignItems="center" minHeight="15vh" id={'sliderBox'}>
						<Slider
								defaultValue={7}
								valueLabelDisplay="auto"
								step={1}
								marks
								min={1}
								max={10}
						/>
</Box>

A level above it, I have the SwipeableViews, so I want to be able to move the slider without moving the swipeable views. I added this according to @oliviertassinari 's suggestion in componentDidMount:

		document.getElementById('sliderBox').addEventListener('mousemove',function(e){
			// e.preventDefault(); // Cancel the native event
			e.stopPropagation();// Don't bubble/capture the event any further
		});
		document.getElementById('sliderBox').addEventListener('touchend',function(e){
			// e.preventDefault(); // Cancel the native event
			e.stopPropagation();// Don't bubble/capture the event any further
		});

which does disable the swipeable views but it also disables the slider… (of course since it’s not propagating the events to the slider now)

Any ideas?

Read more comments on GitHub >

github_iconTop Results From Across the Web

Dead Space - PCGamingWiki PCGW - bugs, fixes, crashes ...
Download and install Widescreen Fixer. · Run the program · Select the 'Main' tab, and select 'Dead Space' from the dropdown menu ·...
Read more >
Dead Space 3 - PC Graphics Settings and Options ... - YouTube
Subscribe: http://bit.ly/NEZWwUThanks for every time you "LIKE" a video. It really helps my channel to grow! Thanks so much!
Read more >
Dead Space™ – EA Official Site
The sci-fi survival horror classic Dead Space™ returns January 27, 2023, completely rebuilt to offer an even more immersive experience – including visual, ......
Read more >
How to add or replace a subtitle in dead space 1 ? | Fandom
Hi all. I want to translate Dead space but i need to extract the subtitle from the game and add mine. anyone know...
Read more >
dead-space-3-manuals_PC.pdf - Akamaihd.net
Press E to add the revealed item to your inventory. Press I to open the inventory display and view your items, consume Med...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found