Authored by 孙凯

add webView text 控件 review by yuliang

... ... @@ -4,6 +4,8 @@ import React, {Component} from 'react';
import Immutable, {Map} from 'immutable';
import DetailBrand from './DetailBrand';
import OtherArticle from './OtherArticle';
import SingleImage from './SingleImage';
import DetailText from './DetailText';
import ReactNative, {
View,
... ... @@ -43,9 +45,33 @@ export default class Detail extends Component {
renderRow(rowData,sectionID,rowID,highlightRow) {
if (sectionID == 'detailList') {
let template_name = rowData.get('template_name');
if (template_name == 'text') {
return (
<Text>aaaaaa</Text>
<DetailText resource={rowData}/>
);
}else if (template_name == 'single_image') {
return (
<SingleImage resource={rowData}/>
);
}else if (template_name == 'small_image') {
return (
<Text>small_image</Text>
);
}else if (template_name == 'weixinPublic') {
return (
<Text>weixinPublic</Text>
);
}else if (template_name == 'collocation') {
return (
<Text>collocation</Text>
);
}else if (template_name == 'moreLink') {
return (
<Text>moreLink</Text>
);
}
}else if (sectionID == 'detailBrand') {
return (
<DetailBrand resource={rowData}/>
... ...
'use strict';
import React from 'react';
import ReactNative from 'react-native';
import Immutable, {Map} from 'immutable';
const {
AppRegistry,
StyleSheet,
View,
Dimensions,
TouchableOpacity,
WebView,
} = ReactNative;
export default class DetailText extends React.Component {
constructor(props) {
super(props);
}
shouldComponentUpdate(nextProps){
if (Immutable.is(nextProps.resource, this.props.resource)) {
return false;
} else {
return true;
}
}
render() {
let {resource} = this.props;
let template_name = resource.get('data');
let text = template_name.get('text');
return (
<View style={{flex:1}}>
<WebView style={styles.webview_style}
source= {{html: text}}
scrollEnabled={false}
>
</WebView>
</View>
);
return null;
}
};
let {width, height} = Dimensions.get('window');
let styles = StyleSheet.create({
webview_style: {
backgroundColor: 'red',
height: 100,
},
});
... ...
'use strict';
import React from 'react';
import ReactNative from 'react-native';
import Immutable, {Map} from 'immutable';
const {
AppRegistry,
StyleSheet,
Text,
View,
Image,
ListView,
Dimensions,
TouchableOpacity,
} = ReactNative;
export default class SingleImage extends React.Component {
constructor(props) {
super(props);
this.state = {
width: Dimensions.get('window').width,
height: 0,
};
}
shouldComponentUpdate(nextProps){
if (Immutable.is(nextProps.resource, this.props.resource && this.state.height != 0)) {
return false;
} else {
return true;
}
}
componentDidMount() {
let {resource} = this.props;
let template_name = resource.get('data');
let src = template_name.get('src');
Image.getSize(src, (width, height) => {
this.setState({width, height});
});
}
render() {
let {resource} = this.props;
let template_name = resource.get('data');
let src = template_name.get('src');
return (
<View style={{width: Dimensions.get('window').width,height: (this.state.height/this.state.width)*Dimensions.get('window').width}}>
<Image
source={{uri: src}}
style={{width: Dimensions.get('window').width,height: (this.state.height/this.state.width)*Dimensions.get('window').width}}
>
</Image>
</View>
);
return null;
}
};
let styles = StyleSheet.create({
});
... ...