-
Notifications
You must be signed in to change notification settings - Fork 921
/
Copy pathText.js
55 lines (45 loc) · 1.36 KB
/
Text.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
'use strict';
var createComponent = require('./createComponent');
var LayerMixin = require('./LayerMixin');
var Text = createComponent('Text', LayerMixin, {
applyTextProps: function (prevProps, props) {
var style = (props && props.style) ? props.style : {};
var layer = this.node;
layer.type = 'text';
layer.text = childrenAsString(props.children);
layer.color = style.color;
layer.fontFace = style.fontFace;
layer.fontSize = style.fontSize;
layer.lineHeight = style.lineHeight;
layer.textAlign = style.textAlign;
layer.hyphens = style.hyphens;
},
mountComponent: function (rootID, transaction, context) {
var props = this._currentElement.props;
var layer = this.node;
this.applyLayerProps({}, props);
this.applyTextProps({}, props);
return layer;
},
receiveComponent: function (nextComponent, transaction, context) {
var props = nextComponent.props;
var prevProps = this._currentElement.props;
this.applyLayerProps(prevProps, props);
this.applyTextProps(prevProps, props);
this._currentElement = nextComponent;
this.node.invalidateLayout();
}
});
function childrenAsString(children) {
if (!children) {
return '';
}
if (typeof children === 'string') {
return children;
}
if (children.length) {
return children.join('\n');
}
return '';
}
module.exports = Text;