From 8c10f86c61d0aa24d3d3e74e40ef6875e0310980 Mon Sep 17 00:00:00 2001 From: Liangyu Date: Sun, 3 Sep 2017 11:50:59 +0800 Subject: [PATCH] Select.getItemText support React.element, #51 --- components/Select/Select.js | 9 +++++++-- components/TransformView/TransformView.js | 21 +++++++++++---------- example/views/SelectExample.js | 11 +++++++---- package.json | 2 +- 4 files changed, 26 insertions(+), 17 deletions(-) diff --git a/components/Select/Select.js b/components/Select/Select.js index 639df07..b68ecc2 100644 --- a/components/Select/Select.js +++ b/components/Select/Select.js @@ -76,7 +76,7 @@ export default class Select extends Component { } } } - return text ? `${text}` : text; + return (!text || React.isValidElement(text)) ? text : `${text}`; } buildProps() { @@ -141,7 +141,12 @@ export default class Select extends Component { valueStyle = valueStyle.concat({color: placeholderTextColor}); valueElement = {placeholder}; } else { - valueElement = {this.valueText}; + let valueText = this.valueText; + if (React.isValidElement(valueText)) { + valueElement = valueText; + } else { + valueElement = {valueText}; + } } //iconTintColor diff --git a/components/TransformView/TransformView.js b/components/TransformView/TransformView.js index 6b16707..c93fcd5 100644 --- a/components/TransformView/TransformView.js +++ b/components/TransformView/TransformView.js @@ -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; @@ -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; diff --git a/example/views/SelectExample.js b/example/views/SelectExample.js index 7484342..a418a3c 100644 --- a/example/views/SelectExample.js +++ b/example/views/SelectExample.js @@ -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'; @@ -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: , + value: 3, + }, ]; Object.assign(this.state, { valueSM: null, @@ -166,6 +168,7 @@ export default class SelectExample extends NavigationPage { detail={