Search code examples
androidreact-nativewebviewhybrid-mobile-app

Disable download in React native WebView


I am using a React Native WebViw in my app. I want to disable download of files. Mostly just documents. I cant disable storage permissions as certain features in the app need this feature.


Solution

  • You can achieve this by injecting a javascript, with the help of controlsList="nodownload" property check below reference code for video file:

    <WebView
        style={{
          height: this.props.videoPlayerHeight,
          width: this.props.videoPlayerWidth,
          backgroundColor: 'black',
        }}
        allowsFullscreenVideo={true}
        allowFileAccess={false}
        mixedContentMode="always"
        mediaPlaybackRequiresUserAction={true}
        injectedJavaScript={`document.getElementsByTagName("video")[0].controlsList="nodownload";`}
        source={{uri: `${this.props.videoLink}#t=0.01`}}
        startInLoadingState={true}
        renderLoading={this.renderLoading}
      />