How to disable only long press on youtube video in react-native-youtube-iframe

Viewed 696

I have used react-native-youtube-iframe to play youtube videos in my react native app. I want to disable long-press on youtube videos.

1 Answers

From GitHub documentation, I solved by using.

Removing context menu on long-press:

Wrap the YoutubePlayer in a View that has pointerEvents="none" to disable app touch-events to the player.

Then react-native's Pressable API or any of the touchables to intercept presses.

    <Pressable
      onPress={() => {
        // handle or ignore
      }}
      onLongPress={() => {
        // handle or ignore
      }}>
    
      <View pointerEvents="none">
        <YoutubePlayer (...) />
      </View>
    
    </Pressable>

Source: https://lonelycpp.github.io/react-native-youtube-iframe/remove-context-share

Another Way is using onContextMenu={(e) => e.preventDefault():

<div onContextMenu={(e) => e.preventDefault()}>

    <YoutubePlayer (...) />

</div>
Related