react-native-webview.git

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. /**
  2. * Copyright (c) Facebook, Inc. and its affiliates.
  3. *
  4. * This source code is licensed under the MIT license found in the
  5. * LICENSE file in the root directory of this source tree.
  6. *
  7. * @format
  8. * @flow
  9. */
  10. import React, {Component} from 'react';
  11. import {Text, View} from 'react-native';
  12. import WebView from 'react-native-webview';
  13. const HTML = `
  14. <!DOCTYPE html>\n
  15. <html>
  16. <head>
  17. <title>Hello World</title>
  18. <meta http-equiv="content-type" content="text/html; charset=utf-8">
  19. <meta name="viewport" content="width=320, user-scalable=no">
  20. <style type="text/css">
  21. body {
  22. margin: 0;
  23. padding: 0;
  24. font: 62.5% arial, sans-serif;
  25. background: transparent;
  26. }
  27. </style>
  28. </head>
  29. <body>
  30. <p>HTML content in transparent body.</p>
  31. </body>
  32. </html>
  33. `;
  34. type Props = {};
  35. type State = {
  36. backgroundColor: string,
  37. };
  38. export default class Background extends Component<Props, State> {
  39. state = {
  40. backgroundColor: '#FF00FF00'
  41. };
  42. render() {
  43. return (
  44. <View>
  45. <View style={{backgroundColor:'red'}}>
  46. <View style={{ height: 120 }}>
  47. <WebView
  48. source={{html: HTML}}
  49. automaticallyAdjustContentInsets={false}
  50. style={{backgroundColor:'#00000000'}}
  51. />
  52. </View>
  53. </View>
  54. <Text>WebView is transparent contained in a View with a red backgroundColor</Text>
  55. </View>
  56. );
  57. }
  58. }