Authored by chenl

增加我的个人中心资源位。review by liben。

  1 +'use strict';
  2 +
  3 +import React from 'react';
  4 +import ReactNative from 'react-native';
  5 +import Swiper from 'react-native-swiper';
  6 +import YH_Image from '../../../common/components/YH_Image';
  7 +import Immutable, {Map} from 'immutable';
  8 +import RecyclerSwiper from '../../../common/recycler-swiper/recyclerswiper'
  9 +
  10 +const {
  11 + View,
  12 + Image,
  13 + TouchableOpacity,
  14 + StyleSheet,
  15 + Dimensions,
  16 + Platform,
  17 +} = ReactNative;
  18 +
  19 +const YH_Swiper = (Platform.OS === 'ios') ? Swiper : RecyclerSwiper;
  20 +
  21 +
  22 +export default class ImageSlider extends React.Component {
  23 +
  24 + constructor(props) {
  25 + super (props);
  26 +
  27 + this.dot = <View
  28 + style={{
  29 + backgroundColor:'rgba(237, 237, 237, 0.5)',
  30 + width: 6,
  31 + height: 6,
  32 + borderRadius: 3,
  33 + marginLeft: 3,
  34 + marginRight: 3,
  35 + marginTop: 3,
  36 + marginBottom: 0,
  37 + }}
  38 + />;
  39 + this.activeDot = <View
  40 + style={{
  41 + backgroundColor:'white',
  42 + width: 6,
  43 + height: 6,
  44 + borderRadius: 3,
  45 + marginLeft: 3,
  46 + marginRight: 3,
  47 + marginTop: 3,
  48 + marginBottom: 0,
  49 + }}
  50 + />;
  51 + }
  52 +
  53 + shouldComponentUpdate(nextProps){
  54 + if (Immutable.is(nextProps.resource, this.props.resource)
  55 + && nextProps.sliderWidth == this.props.sliderWidth
  56 + && nextProps.sliderHeight == this.props.sliderHeight) {
  57 + return false;
  58 + } else {
  59 + return true;
  60 + }
  61 + }
  62 +
  63 + render() {
  64 +
  65 + let {resource, sliderWidth, sliderHeight} = this.props;
  66 + if (!resource || resource.size == 0) {
  67 + return null;
  68 + }
  69 +
  70 + let data = this.props.resource.toJS();
  71 + if (data.length == 1) {
  72 + let imageUrl = YH_Image.getSlicedUrl(data[0].src, sliderWidth, sliderHeight, 2);
  73 + return (
  74 + <TouchableOpacity
  75 + activeOpacity={1}
  76 + style={{width: sliderWidth, height: sliderHeight}}
  77 + onPress={() => {
  78 + this.props.onPressSlideItem && this.props.onPressSlideItem(data[0].url, imageUrl, 0);
  79 + }}
  80 + >
  81 + <YH_Image
  82 + url={imageUrl}
  83 + style={{ width: sliderWidth, height: sliderHeight}}
  84 + />
  85 + </TouchableOpacity>
  86 + );
  87 + } else {
  88 + return (
  89 + <YH_Swiper
  90 + showsButtons={false}
  91 + loop={true}
  92 + autoplay={true}
  93 + autoplayTimeout={3}
  94 + dot={this.dot}
  95 + activeDot={(Platform.OS === 'ios') ? this.activeDot : null}
  96 + width={sliderWidth}
  97 + height={sliderHeight}
  98 + paginationStyle={{
  99 + backgroundColor: 'rgba(68, 68, 68, 0.2)',
  100 + bottom: 10,
  101 + height: 10,
  102 + width: data.length * 12,
  103 + borderRadius: 5,
  104 + marginLeft: (sliderWidth - data.length * 12)/2,
  105 + paddingBottom: 3,
  106 + }}
  107 + >
  108 + {data.map((item, i) => {
  109 + let imageUrl = YH_Image.getSlicedUrl(item.src, sliderWidth, sliderHeight, 2);
  110 + return (
  111 + <TouchableOpacity
  112 + key={i}
  113 + activeOpacity={1}
  114 + yh_exposureData={item.yh_exposureData}
  115 + onPress={() => {
  116 + this.props.onPressSlideItem && this.props.onPressSlideItem(item.url, imageUrl,i);
  117 + }}
  118 + onPressIn={() => {
  119 + this.props.onChildScrollToPreventRefresh && this.props.onChildScrollToPreventRefresh();
  120 + }}
  121 + >
  122 + <YH_Image
  123 + url={imageUrl}
  124 + style={{width: sliderWidth, height: sliderHeight}}
  125 + />
  126 + </TouchableOpacity>
  127 + );
  128 + })}
  129 + </YH_Swiper>
  130 + );
  131 + }
  132 + }
  133 +}
  1 +'use strict';
  2 +
  3 +import React, {Component} from 'react';
  4 +import Immutable, {Map} from 'immutable';
  5 +
  6 +import SlicedImage from '../../../common/components/SlicedImage';
  7 +import YH_Image from '../../../common/components/YH_Image';
  8 +
  9 +
  10 +import ReactNative, {
  11 + View,
  12 + StyleSheet,
  13 + Dimensions,
  14 +} from 'react-native';
  15 +
  16 +/**
  17 + * 分割线楼层
  18 + **/
  19 +export default class DivideImage extends Component{
  20 +
  21 +
  22 + constructor(props) {
  23 + super(props);
  24 + }
  25 +
  26 +
  27 + render(){
  28 + let data = this.props.data;
  29 + let url = data && data.get(0,{}).get("src",'');
  30 +
  31 + let imageUrl = SlicedImage.getSlicedUrl(url, width, height, 2);
  32 +
  33 + return(
  34 + <View style={styles.container}>
  35 + <YH_Image style={styles.immage} url={imageUrl} />
  36 + </View>
  37 + );
  38 + }
  39 +
  40 +};
  41 +
  42 +let {width} = Dimensions.get('window');
  43 +let height = 10;
  44 +
  45 +let styles = StyleSheet.create({
  46 +
  47 + container: {
  48 + width: width,
  49 + height: height,
  50 + backgroundColor: "#f0f0f0",
  51 + },
  52 +
  53 + immage: {
  54 + width: width,
  55 + height: height,
  56 + },
  57 +
  58 +});
  1 +'use strict';
  2 +
  3 +import React from 'react';
  4 +import ReactNative from 'react-native';
  5 +import ImageSlider from '../cell/ImageSlider';
  6 +import Immutable, {Map} from 'immutable';
  7 +
  8 +const {
  9 + View,
  10 + Image,
  11 + TouchableOpacity,
  12 + StyleSheet,
  13 + Dimensions,
  14 + Platform,
  15 +} = ReactNative;
  16 +
  17 +
  18 +export default class SingleImage extends React.Component {
  19 +
  20 + constructor(props) {
  21 + super (props);
  22 +
  23 + }
  24 +
  25 + shouldComponentUpdate(nextProps){
  26 + if (Immutable.is(nextProps.data, this.props.data)) {
  27 + return false;
  28 + } else {
  29 + return true;
  30 + }
  31 + }
  32 +
  33 + render() {
  34 + return (
  35 + <ImageSlider
  36 + resource={this.props.data}
  37 + sliderWidth={width}
  38 + sliderHeight={sliderHeight}
  39 + onPressSlideItem={this.props.onPressSlideItem}
  40 + />
  41 + );
  42 + }
  43 +}
  44 +
  45 +let {width, height} = Dimensions.get('window');
  46 +let sliderHeight = Math.ceil(width * 234 / 750);
  1 +'use strict';
  2 +
  3 +import React from 'react';
  4 +import ReactNative from 'react-native';
  5 +import YH_Image from '../../../common/components/YH_Image';
  6 +import Immutable, {Map} from 'immutable';
  7 +
  8 +const {
  9 + View,
  10 + TouchableOpacity,
  11 + StyleSheet,
  12 + Dimensions,
  13 + Platform,
  14 +} = ReactNative;
  15 +
  16 +export default class SmallPic extends React.Component {
  17 +
  18 + constructor(props) {
  19 + super (props);
  20 +
  21 + }
  22 +
  23 + shouldComponentUpdate(nextProps){
  24 + if (Immutable.is(nextProps.data, this.props.data)) {
  25 + return false;
  26 + } else {
  27 + return true;
  28 + }
  29 + }
  30 +
  31 + render() {
  32 + let {data} = this.props;
  33 +
  34 + if (!data || data.size == 0) {
  35 + return null;
  36 + }
  37 +
  38 + let url1 = YH_Image.getSlicedUrl(data.get(0).get('src'), imageWidth, imageHeight, 2);
  39 + let url2 = YH_Image.getSlicedUrl(data.get(1).get('src'), imageWidth, imageHeight, 2);
  40 +
  41 + return (
  42 + <View style={styles.container}>
  43 + <TouchableOpacity
  44 + activeOpacity={1}
  45 + onPress={() => {
  46 + this.props.onPressPicItem && this.props.onPressPicItem(data.get(0).get('url'), url1, 0);
  47 + }}
  48 + >
  49 + <YH_Image
  50 + url={url1}
  51 + masksToBounds={true}
  52 + radius={{'topLeft':'3','topRight':'3','bottomRight':'3','bottomLeft':'3'}}
  53 + style={[styles.image, styles.left]}
  54 + />
  55 + </TouchableOpacity>
  56 + <TouchableOpacity
  57 + activeOpacity={1}
  58 + onPress={() => {
  59 + this.props.onPressPicItem && this.props.onPressPicItem(data.get(1).get('url'), url2, 1);
  60 + }}
  61 + >
  62 + <YH_Image
  63 + url={url2}
  64 + masksToBounds={true}
  65 + radius={{'topLeft':'3','topRight':'3','bottomRight':'3','bottomLeft':'3'}}
  66 + style={[styles.image, styles.right]}
  67 + />
  68 + </TouchableOpacity>
  69 + </View>
  70 + );
  71 + }
  72 +}
  73 +
  74 +let {width, height} = Dimensions.get('window');
  75 +
  76 +const DEVICE_WIDTH_RATIO = width / 320;
  77 +let containerHeight = Math.ceil(80 * (width - 45) / 2 / 137.5);
  78 +let imageWidth = Math.ceil((width - 45) / 2);
  79 +let imageHeight = Math.ceil(80 * (imageWidth / 137.5));
  80 +
  81 +let styles = StyleSheet.create({
  82 + container: {
  83 + width: width,
  84 + height: containerHeight,
  85 + flexDirection: 'row',
  86 + backgroundColor: '#f0f0f0',
  87 + },
  88 + image: {
  89 + width: imageWidth,
  90 + height: imageHeight,
  91 + borderRadius: 3,
  92 + backgroundColor: 'white',
  93 + marginLeft: 15,
  94 + },
  95 + left: {
  96 +
  97 + },
  98 + right: {
  99 +
  100 + },
  101 +});
@@ -81,6 +81,7 @@ export default class MineList extends React.Component { @@ -81,6 +81,7 @@ export default class MineList extends React.Component {
81 iconAll={this.props.iconAll} 81 iconAll={this.props.iconAll}
82 instalmentStatus={this.props.instalmentStatus} 82 instalmentStatus={this.props.instalmentStatus}
83 mineResource={this.props.mineResource} 83 mineResource={this.props.mineResource}
  84 + onPressFloorItem={this.props.onPressFloorItem}
84 /> 85 />
85 ); 86 );
86 } 87 }
@@ -14,6 +14,7 @@ import ReactNative, { @@ -14,6 +14,7 @@ import ReactNative, {
14 14
15 import Immutable, {Map} from 'immutable'; 15 import Immutable, {Map} from 'immutable';
16 import Announcement from './Announcement'; 16 import Announcement from './Announcement';
  17 +import MineResourceList from './MineResourceList';
17 import YH_Image from '../../../common/components/YH_Image'; 18 import YH_Image from '../../../common/components/YH_Image';
18 19
19 export default class MineListHeader extends React.Component { 20 export default class MineListHeader extends React.Component {
@@ -23,6 +24,8 @@ export default class MineListHeader extends React.Component { @@ -23,6 +24,8 @@ export default class MineListHeader extends React.Component {
23 this._renderMinePropertyNumberPoint = this._renderMinePropertyNumberPoint.bind(this); 24 this._renderMinePropertyNumberPoint = this._renderMinePropertyNumberPoint.bind(this);
24 this._renderVip = this._renderVip.bind(this); 25 this._renderVip = this._renderVip.bind(this);
25 this._renderBannerResource = this._renderBannerResource.bind(this); 26 this._renderBannerResource = this._renderBannerResource.bind(this);
  27 + this._calculateBannerResourceHeight = this._calculateBannerResourceHeight.bind(this);
  28 +
26 } 29 }
27 30
28 /** 31 /**
@@ -111,20 +114,54 @@ export default class MineListHeader extends React.Component { @@ -111,20 +114,54 @@ export default class MineListHeader extends React.Component {
111 ); 114 );
112 } 115 }
113 116
  117 + //渲染资源位
114 _renderBannerResource(){ 118 _renderBannerResource(){
115 - let mineResource = this.props.mineResource;  
116 -  
117 - if(!mineResource)  
118 - return;  
119 119
120 - //  
121 return( 120 return(
122 -  
123 - <View style={{width:width,height:25, backgroundColor:'red'}}>  
124 -  
125 - </View> 121 + <MineResourceList
  122 + style={{width:width,height:500}}
  123 + mineResource={this.props.mineResource}
  124 + onPressFloorItem={this.props.onPressFloorItem}>
  125 + </MineResourceList>
126 ); 126 );
  127 + }
127 128
  129 + //计算资源位高度
  130 + _calculateBannerResourceHeight(){
  131 + let {mineResource} = this.props;
  132 + let resourceList = mineResource ? mineResource.toJS() : [];
  133 + let floorHeight = 0;
  134 + let i = 0;
  135 + let count = resourceList.length;
  136 + for(i; i < count; i++) {
  137 + let item = resourceList[i];
  138 + if (!item) {
  139 + continue;
  140 + }
  141 +
  142 + let templateName = item.template_name;
  143 + let data = item.data;
  144 + if (!templateName || !data) {
  145 + continue;
  146 + }
  147 +
  148 + switch(templateName) {
  149 + case 'single_image': {
  150 + floorHeight = floorHeight + Math.ceil(width * 234 / 750);
  151 + break;
  152 + }
  153 + case 'small_pic': {
  154 + floorHeight = floorHeight + Math.ceil(80 * (width - 45) / 2 / 137.5);
  155 + break;
  156 + }
  157 + case 'divideImage': {
  158 + floorHeight = floorHeight + 10;
  159 + break;
  160 + }
  161 + }
  162 + }
  163 +
  164 + return floorHeight;
128 } 165 }
129 166
130 167
@@ -166,6 +203,13 @@ export default class MineListHeader extends React.Component { @@ -166,6 +203,13 @@ export default class MineListHeader extends React.Component {
166 if (this.props.activityListInfo && this.props.activityListInfo.list && this.props.activityListInfo.list.size > 0) { 203 if (this.props.activityListInfo && this.props.activityListInfo.list && this.props.activityListInfo.list.size > 0) {
167 oHigh = oHigh + rowheight * this.props.activityListInfo.list.size; 204 oHigh = oHigh + rowheight * this.props.activityListInfo.list.size;
168 } 205 }
  206 +
  207 + //资源位高度
  208 + if (this.props.mineResource) {
  209 + let floorHeight = this._calculateBannerResourceHeight();
  210 + oHigh = oHigh + floorHeight;
  211 + }
  212 +
169 oHigh = topHeight + oHigh; 213 oHigh = topHeight + oHigh;
170 let bgImage = Platform.OS === 'ios' ? require('../../image/mine_top_boy.png') : require('../../image/mine_banner_boy.jpg'); 214 let bgImage = Platform.OS === 'ios' ? require('../../image/mine_top_boy.png') : require('../../image/mine_banner_boy.jpg');
171 let bgHeight = Platform.OS === 'ios' ? 284 : 175; 215 let bgHeight = Platform.OS === 'ios' ? 284 : 175;
@@ -675,7 +719,9 @@ export default class MineListHeader extends React.Component { @@ -675,7 +719,9 @@ export default class MineListHeader extends React.Component {
675 <Image style={styles.arrow} source={require('../../image/arrow_gray.png')}/> 719 <Image style={styles.arrow} source={require('../../image/arrow_gray.png')}/>
676 </View> 720 </View>
677 </TouchableOpacity> 721 </TouchableOpacity>
  722 +
678 {this._renderBannerResource()} 723 {this._renderBannerResource()}
  724 +
679 <View style={{ 725 <View style={{
680 width: width, 726 width: width,
681 height: 10, 727 height: 10,
  1 +'use strict';
  2 +import React from 'react';
  3 +
  4 +import ReactNative, {
  5 + View,
  6 + Text,
  7 + Image,
  8 + ListView,
  9 + StyleSheet,
  10 + Dimensions,
  11 + TouchableOpacity,
  12 + Platform,
  13 + PixelRatio,
  14 +} from 'react-native';
  15 +
  16 +import Immutable, {Map} from 'immutable';
  17 +import SingleImage from '../floor/SingleImage';
  18 +import DivideImage from '../floor/DivideImage';
  19 +import SmallPic from '../floor/SmallPic';
  20 +
  21 +
  22 +
  23 +export default class MineResourceList extends React.Component {
  24 + constructor(props) {
  25 + super(props);
  26 +
  27 + this._renderRow = this._renderRow.bind(this);
  28 +
  29 + this.dataSource = new ListView.DataSource({
  30 + rowHasChanged: (r1, r2) => !Immutable.is(r1, r2),
  31 + });
  32 + }
  33 +
  34 + _renderRow(rowData, sectionID, rowID, highlightRow) {
  35 +
  36 + if(!rowData || !rowData.get('data')){
  37 + return null;
  38 + }
  39 +
  40 + let template_name = rowData.get('template_name');
  41 + switch (template_name) {
  42 + case 'single_image': {
  43 + return (
  44 + <SingleImage
  45 + data={rowData.get('data')}
  46 + onPressSlideItem={(jumpUrl, imageUrl, index) =>{
  47 + this.props.onPressFloorItem&&this.props.onPressFloorItem(jumpUrl, imageUrl, index, rowData, rowID);
  48 + }}
  49 + />
  50 + );
  51 + }
  52 + case 'small_pic': {
  53 + return (
  54 + <SmallPic
  55 + data={rowData.get('data')}
  56 + onPressPicItem={(jumpUrl, imageUrl, index) =>{
  57 + this.props.onPressFloorItem&&this.props.onPressFloorItem(jumpUrl, imageUrl, index, rowData, rowID);
  58 + }}
  59 + />
  60 + );
  61 + }
  62 + case 'divideImage': {
  63 + return (
  64 + <DivideImage data={rowData.get('data')}/>
  65 + );
  66 + }
  67 + default:
  68 + return null;
  69 + }
  70 + }
  71 +
  72 +
  73 + render() {
  74 + let mineResource = this.props.mineResource;
  75 +
  76 + if(!mineResource)
  77 + return;
  78 +
  79 + let dataSource = mineResource.toArray();
  80 +
  81 + return (
  82 + <View style={styles.container}>
  83 + <ListView
  84 + contentContainerStyle={styles.contentContainer}
  85 + enableEmptySections={true}
  86 + dataSource={this.dataSource.cloneWithRows(dataSource)}
  87 + renderRow={this._renderRow}
  88 + />
  89 + </View>
  90 + );
  91 + }
  92 +};
  93 +
  94 +let {width, height} = Dimensions.get('window');
  95 +let styles = StyleSheet.create({
  96 + container: {
  97 + width: width,
  98 + },
  99 +
  100 + contentContainer: {
  101 + flex: 1,
  102 + },
  103 +
  104 +});
@@ -45,6 +45,9 @@ class MineContainer extends Component { @@ -45,6 +45,9 @@ class MineContainer extends Component {
45 this._onLongPressProduct = this._onLongPressProduct.bind(this); 45 this._onLongPressProduct = this._onLongPressProduct.bind(this);
46 this._onPressFindSimilar = this._onPressFindSimilar.bind(this); 46 this._onPressFindSimilar = this._onPressFindSimilar.bind(this);
47 47
  48 + //资源位点击楼层
  49 + this._onPressFloorItem = this._onPressFloorItem.bind(this);
  50 +
48 this.subscription1 = NativeAppEventEmitter.addListener( 51 this.subscription1 = NativeAppEventEmitter.addListener(
49 'UserDidLoginEvent', 52 'UserDidLoginEvent',
50 (reminder) => { 53 (reminder) => {
@@ -88,7 +91,7 @@ class MineContainer extends Component { @@ -88,7 +91,7 @@ class MineContainer extends Component {
88 this.props.actions.onMineCenterRefresh(); 91 this.props.actions.onMineCenterRefresh();
89 this.props.actions.getMineAllIcon(); 92 this.props.actions.getMineAllIcon();
90 this.props.actions.setShowSimilarGuider(true); 93 this.props.actions.setShowSimilarGuider(true);
91 - //this.props.actions.getMineResource(); 94 + this.props.actions.getMineResource();
92 } 95 }
93 96
94 componentWillUnmount() { 97 componentWillUnmount() {
@@ -290,6 +293,25 @@ class MineContainer extends Component { @@ -290,6 +293,25 @@ class MineContainer extends Component {
290 }); 293 });
291 } 294 }
292 295
  296 + //点击资源位楼层数据
  297 + _onPressFloorItem(jumpUrl, imageUrl, index, floorData, floorIndex) {
  298 + if (!jumpUrl) {
  299 + return;
  300 + }
  301 + ReactNative.NativeModules.YH_CommonHelper.jumpWithUrl(jumpUrl);
  302 +
  303 + let floorID = floorData.get('template_id','');
  304 + let floorName = floorData.get('template_name','');
  305 + let param = {
  306 + 'F_ID': floorID,
  307 + 'F_NAME': floorName,
  308 + 'F_URL': jumpUrl,
  309 + 'F_INDEX': parseInt(floorIndex) + 1 + "",
  310 + 'I_INDEX': parseInt(index) + 1 + "",
  311 + };
  312 + NativeModules.YH_CommonHelper.logEvent('YB_MY_BANNER_C', param);
  313 + }
  314 +
293 render() { 315 render() {
294 let { 316 let {
295 isFetching, 317 isFetching,
@@ -335,6 +357,7 @@ class MineContainer extends Component { @@ -335,6 +357,7 @@ class MineContainer extends Component {
335 onMineCenterRefresh={this._onMineCenterRefresh} 357 onMineCenterRefresh={this._onMineCenterRefresh}
336 onLongPressProduct={this._onLongPressProduct} 358 onLongPressProduct={this._onLongPressProduct}
337 onPressFindSimilar={this._onPressFindSimilar} 359 onPressFindSimilar={this._onPressFindSimilar}
  360 + onPressFloorItem={this._onPressFloorItem}
338 showSimilarGuider={showSimilarGuider} 361 showSimilarGuider={showSimilarGuider}
339 /> 362 />
340 ); 363 );