This commit is contained in:
Horcrux
2017-01-16 21:01:12 +08:00
parent 5625f56d19
commit 43e45b95c5
3 changed files with 39 additions and 5 deletions

View File

@@ -17,6 +17,22 @@ class TSpan extends Shape {
textAnchor: PropTypes.oneOf(['start', 'middle', 'end']) textAnchor: PropTypes.oneOf(['start', 'middle', 'end'])
}; };
static childContextTypes = {
isInAParentText: React.PropTypes.bool
};
getChildContext() {
return {
isInAParentText: true
};
};
getContextTypes() {
return {
isInAParentText: React.PropTypes.bool
};
};
setNativeProps = (...args) => { setNativeProps = (...args) => {
this.root.setNativeProps(...args); this.root.setNativeProps(...args);
}; };

View File

@@ -17,6 +17,22 @@ class Text extends Shape {
textAnchor: PropTypes.oneOf(['start', 'middle', 'end']) textAnchor: PropTypes.oneOf(['start', 'middle', 'end'])
}; };
static childContextTypes = {
isInAParentText: React.PropTypes.bool
};
getChildContext() {
return {
isInAParentText: true
};
};
getContextTypes() {
return {
isInAParentText: React.PropTypes.bool
};
};
setNativeProps = (...args) => { setNativeProps = (...args) => {
this.root.setNativeProps(...args); this.root.setNativeProps(...args);
}; };

View File

@@ -96,11 +96,13 @@ export default function(props, container) {
let { children } = props; let { children } = props;
let content = null; let content = null;
if (typeof children === 'string') {
if (typeof children === 'string' || typeof children === 'number') {
const childrenString = children.toString();
if (container) { if (container) {
children = <TSpan>{children}</TSpan>; children = <TSpan>{childrenString}</TSpan>;
} else { } else {
content = children; content = childrenString;
children = null; children = null;
} }
} else if (Children.count(children) > 1) { } else if (Children.count(children) > 1) {
@@ -121,7 +123,7 @@ export default function(props, container) {
deltaX, deltaX,
deltaY, deltaY,
startOffset: (startOffset || 0).toString(), startOffset: (startOffset || 0).toString(),
positionX: _.isNil(x) ? null : x, positionX: _.isNil(x) ? null : x.toString(),
positionY: _.isNil(y) ? null : y positionY: _.isNil(y) ? null : y.toString()
} }
} }