11/* @flow */
22'use strict' ;
33
4- import React from 'react-native' ;
4+ import React , { Image } from 'react-native' ;
55import NativeBaseComponent from '../Base/NativeBaseComponent' ;
66import _ from 'lodash' ;
77import computeProps from '../../Utils/computeProps' ;
88import Icon from './Icon' ;
99import Text from './Text' ;
1010import View from './View' ;
1111import Button from './Button' ;
12+ import Thumbnail from './Thumbnail' ;
1213
1314export default class ListItemNB extends NativeBaseComponent {
1415
@@ -21,7 +22,8 @@ export default class ListItemNB extends NativeBaseComponent {
2122 paddingLeft : 10 ,
2223 flex : 1 ,
2324 flexDirection : 'row' ,
24- justifyContent : 'space-between'
25+ justifyContent : 'space-between' ,
26+ alignItems : 'center'
2527 } ,
2628 listItemDivider : {
2729 borderBottomWidth : 1 ,
@@ -50,31 +52,83 @@ export default class ListItemNB extends NativeBaseComponent {
5052 flex : 1 ,
5153 textAlign : 'right' ,
5254
55+ } ,
56+ itemSubNote : {
57+ fontSize : 15 ,
58+ color : '#999'
59+ } ,
60+ thumbnail : {
61+
62+ } ,
63+ fullImage : {
64+ width : 300 ,
65+ height : 300
5366 }
5467 }
5568 }
5669
70+ isThumbnail ( ) {
71+ var thumbnailComponentPresent = false ;
72+ React . Children . forEach ( this . props . children , function ( child ) {
73+ if ( child . type == Thumbnail )
74+ thumbnailComponentPresent = true ;
75+ } )
76+
77+ return thumbnailComponentPresent ;
78+ }
79+
5780 getChildStyle ( child ) {
5881 var mergedStyle = { } ;
5982 if ( child . type == Icon ) {
6083 return _ . merge ( mergedStyle , this . getInitialStyle ( ) . itemIcon , child . props . style ) ;
6184 }
6285
6386 else if ( child . type == Text ) {
64- if ( child . props . note )
87+ if ( child . props . note && this . isThumbnail ( ) )
88+ return _ . merge ( mergedStyle , this . getInitialStyle ( ) . itemSubNote , child . props . style ) ;
89+ else if ( child . props . note )
6590 return _ . merge ( mergedStyle , this . getInitialStyle ( ) . itemNote , child . props . style ) ;
66- else
91+ else
6792 return _ . merge ( mergedStyle , this . getInitialStyle ( ) . itemText , child . props . style ) ;
6893 }
6994
7095 else if ( child . type == Button ) {
7196 return _ . merge ( mergedStyle , this . getInitialStyle ( ) . itemButton , child . props . style ) ;
7297 }
7398
99+ else if ( child . type == Thumbnail ) {
100+ return _ . merge ( mergedStyle , this . getInitialStyle ( ) . thumbnail , child . props . style ) ;
101+ }
102+
103+ else if ( child . type == Image && ! Array . isArray ( this . props . children ) )
104+ return _ . merge ( mergedStyle , this . getInitialStyle ( ) . fullImage , child . props . style ) ;
74105 else
75106 return child . props . style ;
76107 }
77108
109+ getChildProps ( child ) {
110+ var defaultProps = { } ;
111+ if ( child . type == Image && ! Array . isArray ( this . props . children ) ) {
112+ defaultProps = {
113+ resizeMode : 'stretch' ,
114+ style : this . getChildStyle ( child )
115+ }
116+ }
117+ else if ( child . type == Button ) {
118+ defaultProps = {
119+ small : true ,
120+ style : this . getChildStyle ( child )
121+ }
122+ }
123+ else {
124+ defaultProps = {
125+ style : this . getChildStyle ( child )
126+ }
127+ }
128+
129+ return computeProps ( child . props , defaultProps ) ;
130+ }
131+
78132 prepareRootProps ( ) {
79133 if ( this . props . itemDivider )
80134 var defaultProps = {
@@ -93,7 +147,7 @@ export default class ListItemNB extends NativeBaseComponent {
93147
94148 renderChildren ( ) {
95149 var newChildren = React . Children . map ( this . props . children , ( child ) => {
96- return React . cloneElement ( child , { style : this . getChildStyle ( child ) } )
150+ return React . cloneElement ( child , this . getChildProps ( child ) ) ;
97151 } ) ;
98152
99153 console . log ( newChildren ) ;
0 commit comments