Details.js 2.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798
  1. import React, { Component } from 'react'
  2. import {
  3. StyleSheet,
  4. View,
  5. Dimensions,
  6. Platform,
  7. ScrollView,
  8. } from 'react-native'
  9. import {WebView} from 'react-native-webview';
  10. import { connect } from 'react-redux'
  11. import { ImageBaseUrl } from '../../../utils/fetch/Fetchx'
  12. const { width, height } = Dimensions.get('window')
  13. @connect(({ detail }) => ({ ...detail }))
  14. class Details extends Component {
  15. gotoDetail = () => {
  16. this.props.dispatch(NavigationActions.navigate({ routeName: 'Detail' }))
  17. }
  18. constructor() {
  19. super()
  20. this.state = {
  21. WebViewHeight: 0,
  22. }
  23. }
  24. render() {
  25. const { detailDatas } = this.props
  26. let html = detailDatas.description
  27. html = html
  28. ? html.replace(
  29. /src=\"\/g1\//g,
  30. `style="max-width:${width - 20}px; max-height:${height -
  31. 100}px;" src="${ImageBaseUrl}/g1/`
  32. )
  33. : ''
  34. let html5 = `<!DOCTYPE html> <meta name="viewport" content="initial-scale=1, maximum-scale=3, minimum-scale=1, user-scalable=no"><html><head><meta charset="utf-8"></head><body>${html}</body></html>`
  35. return (
  36. <View style={{ flex: 1, padding: 10 }}>
  37. {/* <View style={styles.card}> */}
  38. <WebView
  39. domStorageEnabled={true}
  40. javaScriptEnabled={true}
  41. automaticallyAdjustContentInsets={true}
  42. mediaPlaybackRequiresUserAction={true}
  43. bounces={false}
  44. style={{
  45. width: width - 20,
  46. marginTop: 10,
  47. }}
  48. source={{ html: html5, baseUrl: '' }}
  49. scalesPageToFit={Platform.OS === 'ios' ? true : false}
  50. saveFormDataDisabled={true}
  51. contentInset={{ top: 0, left: 0, right: 0, bottom: 0 }}
  52. onNavigationStateChange={info => {
  53. this.setState({
  54. WebViewHeight: info.url.replace('about:blank%23', '') / 1,
  55. })
  56. }}
  57. />
  58. {/* </View> */}
  59. </View>
  60. )
  61. }
  62. }
  63. const styles = StyleSheet.create({
  64. container: {
  65. flex: 1,
  66. },
  67. headerFont: {
  68. fontSize: 14,
  69. color: '#333',
  70. lineHeight: 20,
  71. },
  72. icon: {
  73. width: 32,
  74. height: 32,
  75. },
  76. tabView: {
  77. flex: 1,
  78. // padding: 15,
  79. backgroundColor: 'rgba(0,0,0,0.01)',
  80. },
  81. card: {
  82. borderWidth: 1,
  83. backgroundColor: '#fff',
  84. borderColor: 'rgba(0,0,0,0.1)',
  85. margin: 5,
  86. // height: 150,
  87. padding: 15,
  88. shadowColor: '#ccc',
  89. shadowOffset: { width: 2, height: 2 },
  90. shadowOpacity: 0.5,
  91. shadowRadius: 3,
  92. },
  93. })
  94. export default Details