Skip to content

Commit

Permalink
Select.getItemText support React.element, #51
Browse files Browse the repository at this point in the history
  • Loading branch information
rilyu committed Sep 3, 2017
1 parent e1c42a1 commit 8c10f86
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 17 deletions.
9 changes: 7 additions & 2 deletions components/Select/Select.js
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ export default class Select extends Component {
}
}
}
return text ? `${text}` : text;
return (!text || React.isValidElement(text)) ? text : `${text}`;
}

buildProps() {
Expand Down Expand Up @@ -141,7 +141,12 @@ export default class Select extends Component {
valueStyle = valueStyle.concat({color: placeholderTextColor});
valueElement = <Text style={valueStyle} numberOfLines={1} allowFontScaling={false}>{placeholder}</Text>;
} else {
valueElement = <Text style={valueStyle} numberOfLines={1} allowFontScaling={false}>{this.valueText}</Text>;
let valueText = this.valueText;
if (React.isValidElement(valueText)) {
valueElement = valueText;
} else {
valueElement = <Text style={valueStyle} numberOfLines={1} allowFontScaling={false}>{valueText}</Text>;
}
}

//iconTintColor
Expand Down
21 changes: 11 additions & 10 deletions components/TransformView/TransformView.js
Original file line number Diff line number Diff line change
Expand Up @@ -208,8 +208,8 @@ export default class TransformView extends Component {
scaleRate = maxScale / scale._value;
}

let scalePointX = (prevTouches[1].pageX + prevTouches[0].pageX) / 2;
let scalePointY = (prevTouches[1].pageY + prevTouches[0].pageY) / 2;
let scalePointX = (prevTouches[1].locationX + prevTouches[0].locationX) / 2;
let scalePointY = (prevTouches[1].locationY + prevTouches[0].locationY) / 2;
let {x, y, width, height} = this.contentLayout;
//view center point position
let viewCenterX = x + width / 2;
Expand Down Expand Up @@ -241,19 +241,20 @@ export default class TransformView extends Component {
} else {
if (width < this.viewLayout.width) {
newX = 0;
} else if (x > this.viewLayout.x) {
newX = translateX._value - (x - this.viewLayout.x);
} else if ((x + width) < (this.viewLayout.x + this.viewLayout.width)) {
newX = translateX._value + ((this.viewLayout.x + this.viewLayout.width) - (x + width));
} else if (x > 0) {
newX = translateX._value - x;
} else if ((x + width) < this.viewLayout.width) {
newX = translateX._value + (this.viewLayout.width - (x + width));
}
if (height < this.viewLayout.height) {
newY = 0;
} else if (y > this.viewLayout.y) {
newY = translateY._value - (y - this.viewLayout.y);
} else if ((y + height) < (this.viewLayout.y + this.viewLayout.height)) {
newY = translateY._value + ((this.viewLayout.y + this.viewLayout.height) - (y + height));
} else if (y > 0) {
newY = translateY._value - y;
} else if ((y + height) < this.viewLayout.height) {
newY = translateY._value + (this.viewLayout.height - (y + height));
}
}

}
if (newScale === null) {
if (scale._value > maxScale) newScale = maxScale;
Expand Down
11 changes: 7 additions & 4 deletions example/views/SelectExample.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
'use strict';

import React, {Component} from 'react';
import {View, Text, ScrollView} from 'react-native';
import {View, Text, Image, ScrollView} from 'react-native';

import {NavigationPage, ListRow, Select, Label} from 'teaset';

Expand Down Expand Up @@ -32,11 +32,13 @@ export default class SelectExample extends NavigationPage {
{
text: 'Long long long long long long long',
value: 1,
},
{
}, {
text: 'Short',
value: 2,
}
}, {
text: <Image style={{width: 40, height: 40}} source={require('../images/teaset1_s.jpg')} />,
value: 3,
},
];
Object.assign(this.state, {
valueSM: null,
Expand Down Expand Up @@ -166,6 +168,7 @@ export default class SelectExample extends NavigationPage {
detail={
<Select
style={{width: 200, backgroundColor: '#rgba(238, 169, 91, 0.1)', borderColor: '#8a6d3b'}}
size='lg'
value={valueCustom}
valueStyle={{flex: 1, color: '#8a6d3b', textAlign: 'right'}}
items={this.customItems}
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "teaset",
"version": "0.3.2",
"version": "0.3.3",
"description": "A UI library for react native.",
"main": "index.js",
"scripts": {
Expand Down

0 comments on commit 8c10f86

Please sign in to comment.