Geen omschrijving

Downloads.tsx 1.2KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. import React, {Component} from 'react';
  2. import {Alert, Platform, View} from 'react-native';
  3. import WebView, {FileDownload} from 'react-native-webview';
  4. const HTML = `
  5. <!DOCTYPE html>\n
  6. <html>
  7. <head>
  8. <title>Downloads</title>
  9. <meta http-equiv="content-type" content="text/html; charset=utf-8">
  10. <meta name="viewport" content="width=320, user-scalable=no">
  11. <style type="text/css">
  12. body {
  13. margin: 0;
  14. padding: 0;
  15. font: 62.5% arial, sans-serif;
  16. background: #ccc;
  17. }
  18. </style>
  19. </head>
  20. <body>
  21. <a href="https://www.7-zip.org/a/7za920.zip">Example zip file download</a>
  22. </body>
  23. </html>
  24. `;
  25. type Props = {};
  26. type State = {};
  27. export default class Downloads extends Component<Props, State> {
  28. state = {};
  29. onFileDownload = ({ nativeEvent }: { nativeEvent: FileDownload } ) => {
  30. Alert.alert("File download detected", nativeEvent.downloadUrl);
  31. };
  32. render() {
  33. const platformProps = Platform.select({
  34. ios: {
  35. onFileDownload: this.onFileDownload,
  36. },
  37. });
  38. return (
  39. <View style={{ height: 120 }}>
  40. <WebView
  41. source={{html: HTML}}
  42. automaticallyAdjustContentInsets={false}
  43. {...platformProps}
  44. />
  45. </View>
  46. );
  47. }
  48. }