Details.js 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102
  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. let source = {html: html5}
  36. if(Platform.OS !== 'ios'){
  37. source.baseUrl = ''
  38. }
  39. return (
  40. <View style={{ flex: 1, padding: 10 }}>
  41. {/* <View style={styles.card}> */}
  42. <WebView
  43. domStorageEnabled={true}
  44. javaScriptEnabled={true}
  45. automaticallyAdjustContentInsets={true}
  46. mediaPlaybackRequiresUserAction={true}
  47. bounces={false}
  48. style={{
  49. width: width - 20,
  50. marginTop: 10,
  51. }}
  52. source={source}
  53. scalesPageToFit={Platform.OS === 'ios' ? true : false}
  54. saveFormDataDisabled={true}
  55. contentInset={{ top: 0, left: 0, right: 0, bottom: 0 }}
  56. onNavigationStateChange={info => {
  57. this.setState({
  58. WebViewHeight: info.url.replace('about:blank%23', '') / 1,
  59. })
  60. }}
  61. />
  62. {/* </View> */}
  63. </View>
  64. )
  65. }
  66. }
  67. const styles = StyleSheet.create({
  68. container: {
  69. flex: 1,
  70. },
  71. headerFont: {
  72. fontSize: 14,
  73. color: '#333',
  74. lineHeight: 20,
  75. },
  76. icon: {
  77. width: 32,
  78. height: 32,
  79. },
  80. tabView: {
  81. flex: 1,
  82. // padding: 15,
  83. backgroundColor: 'rgba(0,0,0,0.01)',
  84. },
  85. card: {
  86. borderWidth: 1,
  87. backgroundColor: '#fff',
  88. borderColor: 'rgba(0,0,0,0.1)',
  89. margin: 5,
  90. // height: 150,
  91. padding: 15,
  92. shadowColor: '#ccc',
  93. shadowOffset: { width: 2, height: 2 },
  94. shadowOpacity: 0.5,
  95. shadowRadius: 3,
  96. },
  97. })
  98. export default Details