Authored by 孙凯

add webView text 控件 review by yuliang

@@ -4,6 +4,8 @@ import React, {Component} from 'react'; @@ -4,6 +4,8 @@ import React, {Component} from 'react';
4 import Immutable, {Map} from 'immutable'; 4 import Immutable, {Map} from 'immutable';
5 import DetailBrand from './DetailBrand'; 5 import DetailBrand from './DetailBrand';
6 import OtherArticle from './OtherArticle'; 6 import OtherArticle from './OtherArticle';
  7 +import SingleImage from './SingleImage';
  8 +import DetailText from './DetailText';
7 9
8 import ReactNative, { 10 import ReactNative, {
9 View, 11 View,
@@ -43,9 +45,33 @@ export default class Detail extends Component { @@ -43,9 +45,33 @@ export default class Detail extends Component {
43 renderRow(rowData,sectionID,rowID,highlightRow) { 45 renderRow(rowData,sectionID,rowID,highlightRow) {
44 46
45 if (sectionID == 'detailList') { 47 if (sectionID == 'detailList') {
  48 + let template_name = rowData.get('template_name');
  49 + if (template_name == 'text') {
46 return ( 50 return (
47 - <Text>aaaaaa</Text> 51 + <DetailText resource={rowData}/>
48 ); 52 );
  53 + }else if (template_name == 'single_image') {
  54 + return (
  55 + <SingleImage resource={rowData}/>
  56 + );
  57 + }else if (template_name == 'small_image') {
  58 + return (
  59 + <Text>small_image</Text>
  60 + );
  61 + }else if (template_name == 'weixinPublic') {
  62 + return (
  63 + <Text>weixinPublic</Text>
  64 + );
  65 + }else if (template_name == 'collocation') {
  66 + return (
  67 + <Text>collocation</Text>
  68 + );
  69 + }else if (template_name == 'moreLink') {
  70 + return (
  71 + <Text>moreLink</Text>
  72 + );
  73 + }
  74 +
49 }else if (sectionID == 'detailBrand') { 75 }else if (sectionID == 'detailBrand') {
50 return ( 76 return (
51 <DetailBrand resource={rowData}/> 77 <DetailBrand resource={rowData}/>
  1 +'use strict';
  2 +
  3 +import React from 'react';
  4 +import ReactNative from 'react-native';
  5 +import Immutable, {Map} from 'immutable';
  6 +
  7 +const {
  8 + AppRegistry,
  9 + StyleSheet,
  10 + View,
  11 + Dimensions,
  12 + TouchableOpacity,
  13 + WebView,
  14 +} = ReactNative;
  15 +
  16 +
  17 +export default class DetailText extends React.Component {
  18 + constructor(props) {
  19 + super(props);
  20 + }
  21 +
  22 + shouldComponentUpdate(nextProps){
  23 + if (Immutable.is(nextProps.resource, this.props.resource)) {
  24 + return false;
  25 + } else {
  26 + return true;
  27 + }
  28 + }
  29 +
  30 +
  31 + render() {
  32 + let {resource} = this.props;
  33 + let template_name = resource.get('data');
  34 + let text = template_name.get('text');
  35 +
  36 + return (
  37 + <View style={{flex:1}}>
  38 + <WebView style={styles.webview_style}
  39 + source= {{html: text}}
  40 + scrollEnabled={false}
  41 + >
  42 + </WebView>
  43 + </View>
  44 + );
  45 + return null;
  46 + }
  47 +};
  48 +
  49 +
  50 +let {width, height} = Dimensions.get('window');
  51 +
  52 +let styles = StyleSheet.create({
  53 + webview_style: {
  54 + backgroundColor: 'red',
  55 + height: 100,
  56 + },
  57 +});
  1 +'use strict';
  2 +
  3 +import React from 'react';
  4 +import ReactNative from 'react-native';
  5 +import Immutable, {Map} from 'immutable';
  6 +
  7 +const {
  8 + AppRegistry,
  9 + StyleSheet,
  10 + Text,
  11 + View,
  12 + Image,
  13 + ListView,
  14 + Dimensions,
  15 + TouchableOpacity,
  16 +} = ReactNative;
  17 +
  18 +
  19 +export default class SingleImage extends React.Component {
  20 + constructor(props) {
  21 + super(props);
  22 + this.state = {
  23 + width: Dimensions.get('window').width,
  24 + height: 0,
  25 + };
  26 + }
  27 +
  28 + shouldComponentUpdate(nextProps){
  29 + if (Immutable.is(nextProps.resource, this.props.resource && this.state.height != 0)) {
  30 + return false;
  31 + } else {
  32 + return true;
  33 + }
  34 + }
  35 +
  36 + componentDidMount() {
  37 + let {resource} = this.props;
  38 + let template_name = resource.get('data');
  39 + let src = template_name.get('src');
  40 + Image.getSize(src, (width, height) => {
  41 + this.setState({width, height});
  42 + });
  43 + }
  44 +
  45 + render() {
  46 + let {resource} = this.props;
  47 + let template_name = resource.get('data');
  48 + let src = template_name.get('src');
  49 + return (
  50 + <View style={{width: Dimensions.get('window').width,height: (this.state.height/this.state.width)*Dimensions.get('window').width}}>
  51 + <Image
  52 + source={{uri: src}}
  53 + style={{width: Dimensions.get('window').width,height: (this.state.height/this.state.width)*Dimensions.get('window').width}}
  54 + >
  55 + </Image>
  56 + </View>
  57 + );
  58 + return null;
  59 + }
  60 +};
  61 +
  62 +
  63 +let styles = StyleSheet.create({
  64 +
  65 +});