Authored by 于良

Merge branch 'guang' into 5.4

import React from 'react';
import ReactNative from 'react-native';
import {Platform} from 'react-native';
const {
Component,
} = React;
const {
NativeModules,
} = ReactNative;
const YH_ImageView = ReactNative.requireNativeComponent('YH_ImageView', null);
var UIManager = require('UIManager');
export default class YH_Image extends Component {
constructor(props) {
super (props);
}
render() {
return (
<YH_ImageView
{...this.props}
/>
);
}
}
... ...
'use strict';
import ReactNative, {Platform, Dimensions} from 'react-native';
import CONFIG from '../config/config';
import DeviceInfo from 'react-native-device-info';
import queryString from 'query-string';
import md5 from 'md5';
import timeoutPromise from '../utils/timeoutPromise';
import trimObject from '../utils/trimObject';
import RNNativeConfig from './RNNativeConfig';
export default class NativeRequest {
constructor(baseURL, timeout) {
if (baseURL) {
this.baseUrl = baseURL;
}
if (timeout) {
this.timeout = timeout;
}
}
/**
* GET
*
* @param {[object]} opts
*
* {
* url: '/operations/api/v6/category/getCategory', //接口地址
* timeout: 30, //毫秒
* }
*
* @return {[promise]}
*/
async get(opts) {
try {
let host = this.baseUrl;
let url = opts && opts.url ? opts.url : '';
let body = opts && opts.body ? opts.body : {};
let timeout = this.timeout;
if (!timeout) {
timeout = opts && opts.timeout ? opts.timeout : 0;
}
let params = {
host,
timeout,
url,
body,
};
let response = await ReactNative.NativeModules.YH_CouponHelper.get(params);
let data = await this._parseResponse(response);
return data;
} catch(error) {
throw(error);
}
}
/**
* POST
*
* @param {[object]} opts
*
* {
* url: '/operations/api/v6/category/getCategory', //接口地址
* body: {
* user: 'Lily',
* password: '111111',
* },
* timeout: 30, //毫秒
* }
*
* @return {[promise]}
*/
async post(opts) {
try {
let host = this.baseUrl;
let url = opts && opts.url ? opts.url : '';
let body = opts && opts.body ? opts.body : {};
let timeout = this.timeout;
if (!timeout) {
timeout = opts && opts.timeout ? opts.timeout : 0;
}
let params = {
host,
timeout,
url,
body,
};
let response = await ReactNative.NativeModules.YH_CouponHelper.post(params);
let data = await this._parseResponse(response);
return data;
} catch(error) {
throw(error);
}
}
async _parseResponse(response) {
let code = response && response.code ? response.code : 0;
if (code == 200) {
return response.data;
} else {
let message = response && response.message ? response.message : '';
throw({code, message});
}
}
}
... ...
... ... @@ -156,6 +156,7 @@ export default class Detail extends Component {
<View style={styles.container}>
{!isFetching?<ListView
ref={(ref)=>this.listView=ref}
initialListSize={1}
contentContainerStyle={styles.contentContainer}
enableEmptySections={true}
showsVerticalScrollIndicator={false}
... ... @@ -176,10 +177,9 @@ let {width, height} = Dimensions.get('window');
let styles = StyleSheet.create({
container: {
flex: 1,
backgroundColor: '#f0f0f0',
},
contentContainer:{
backgroundColor: 'white',
},
GoodsGroupHeader: {
flex: 1,
... ...
... ... @@ -37,24 +37,40 @@ export default class SingleImage extends React.Component {
let {resource} = this.props;
let template_name = resource.get('data');
let src = template_name.get('src');
Image.getSize(src, (width, height) => {
if (this.imageView) {
this.setState({width, height});
}
});
let imageHeight = template_name.get('height');
let imageWidth = template_name.get('width');
if (!imageHeight || !imageWidth) {
Image.getSize(src, (width, height) => {
if (this.imageView) {
this.setState({width, height});
}
});
}
}
render() {
let {resource} = this.props;
let template_name = resource.get('data');
let src = template_name.get('src');
return (
<Image
ref={(ref)=>this.imageView=ref}
source={{uri: src}}
style={{width: screenWidth,height: (this.state.height/this.state.width)*screenWidth}}
/>
);
let imageHeight = template_name.get('height');
let imageWidth = template_name.get('width');
if (imageHeight && imageWidth) {
return (
<Image
source={{uri: src}}
style={{width: screenWidth,height: (imageHeight/imageWidth)*screenWidth}}
/>
);
}else {
return (
<Image
ref={(ref)=>this.imageView=ref}
source={{uri: src}}
style={{width: screenWidth,height: (this.state.height/this.state.width)*screenWidth}}
/>
);
}
}
};
... ...
... ... @@ -22,22 +22,26 @@ export default class SmallPic extends React.Component {
this.state = {
width0: 1,
width1: 1,
height0: 1,
height1: 1,
height0: 0,
height1: 0,
};
}
componentDidMount() {
let {resource} = this.props;
let data = resource.get('data')?resource.get('data').toJS():null;
let url1 = data?data[0].src:null;
let url2 = data?data[1].src:null;
Image.getSize(url1, (width, height) => {
this.setState({width0 : width, height0 : height});
});
Image.getSize(url2, (width, height) => {
this.setState({width1 : width, height1 : height});
});
let imageHeight = data?data[0].height:null;
let imageWidth = data?data[0].width:null;
if (!imageHeight || !imageWidth) {
let url1 = data?data[0].src:null;
let url2 = data?data[1].src:null;
Image.getSize(url1, (width, height) => {
this.setState({width0 : width, height0 : height});
});
Image.getSize(url2, (width, height) => {
this.setState({width1 : width, height1 : height});
});
}
}
render() {
... ... @@ -48,12 +52,26 @@ export default class SmallPic extends React.Component {
if (!url1 || !url2) {
return null;
}
return (
<View style={styles.Small_pic}>
<Image source={{uri: url1}} style={{width: width/2,height: (width/2)*(this.state.height0/this.state.width0)}} ></Image>
<Image source={{uri: url2}} style={{width: width/2,height: (width/2)*(this.state.height1/this.state.width1)}} ></Image>
</View>
);
let imageHeight0 = data?data[0].height:null;
let imageWidth0 = data?data[0].width:null;
let imageHeight1 = data?data[1].height:null;
let imageWidth1 = data?data[1].width:null;
if (imageHeight0 && imageWidth0 && imageHeight1 && imageWidth1) {
return (
<View style={styles.Small_pic}>
<Image source={{uri: url1}} style={{width: width/2,height: (width/2)*(imageHeight0/imageWidth0)}} ></Image>
<Image source={{uri: url2}} style={{width: width/2,height: (width/2)*(imageHeight1/imageWidth1)}} ></Image>
</View>
);
}else {
return (
<View style={styles.Small_pic}>
<Image source={{uri: url1}} style={{width: width/2,height: (width/2)*(this.state.height0/this.state.width0)}} ></Image>
<Image source={{uri: url2}} style={{width: width/2,height: (width/2)*(this.state.height1/this.state.width1)}} ></Image>
</View>
);
}
}
};
... ...