convert span frames into Span components

This commit is contained in:
Horcrux
2016-09-17 00:20:18 +08:00
parent ad196a7071
commit 09c5b10f02
4 changed files with 30 additions and 14 deletions

View File

@@ -28,7 +28,8 @@ class Span extends Shape {
render() { render() {
let props = this.props; let props = this.props;
return <RNSVGLine return null;
return <RNSVGSpan
ref={ele => {this.root = ele;}} ref={ele => {this.root = ele;}}
{...this.extractProps(props)} {...this.extractProps(props)}
x1={props.x1.toString()} x1={props.x1.toString()}

View File

@@ -19,10 +19,6 @@ class TSpan extends Component {
font: PropTypes.object font: PropTypes.object
}; };
setNativeProps = (...args) => {
};
render() { render() {
return null; return null;
} }

View File

@@ -22,7 +22,7 @@ class Text extends Shape {
render() { render() {
let props = this.props; let props = this.props;
console.log(extractText(props));
return <RNSVGText return <RNSVGText
ref={ele => {this.root = ele;}} ref={ele => {this.root = ele;}}
{...this.extractProps({ {...this.extractProps({

View File

@@ -1,7 +1,8 @@
import SerializablePath from '../SerializablePath'; import SerializablePath from '../SerializablePath';
import _ from 'lodash'; import _ from 'lodash';
import {Children} from 'react'; import React, {Children} from 'react';
import {fontAndRenderPropsKeys} from '../props'; import {fontAndRenderPropsKeys} from '../props';
import Span from '../../elements/Span';
const fontRegExp = /^\s*((?:(?:normal|bold|italic)\s+)*)(?:(\d+(?:\.\d+)?)[ptexm%]*(?:\s*\/.*?)?\s+)?\s*"?([^"]*)/i; const fontRegExp = /^\s*((?:(?:normal|bold|italic)\s+)*)(?:(\d+(?:\.\d+)?)[ptexm%]*(?:\s*\/.*?)?\s+)?\s*"?([^"]*)/i;
const fontFamilyPrefix = /^[\s"']*/; const fontFamilyPrefix = /^[\s"']*/;
@@ -162,11 +163,11 @@ function parseDelta(delta) {
} }
export default function(props) { export default function(props) {
let frame = parseText(props); let frames = parseText(props);
let alignment; let alignment;
if (frame[0]) { if (frames[0]) {
let firstSpan = frame[0]; let firstSpan = frames[0];
if (firstSpan.positionX === null && props.hasOwnProperty('x')) { if (firstSpan.positionX === null && props.hasOwnProperty('x')) {
firstSpan.positionX = props.x; firstSpan.positionX = props.x;
@@ -187,14 +188,32 @@ export default function(props) {
} }
} }
return { let font = {
alignment,
frame,
children : null,
fontFamily: 'Helvetica Neue', fontFamily: 'Helvetica Neue',
fontSize: 12, fontSize: 12,
fontStyle: 'normal', fontStyle: 'normal',
fontWeight: 'normal', fontWeight: 'normal',
...extractFont(props) ...extractFont(props)
} }
let children = frames.map(frame => {
let spanProps = {
content: frame.content,
dx: frame.deltaX,
dy: frame.deltaY,
px: frame.positionX,
py: frame.positionY,
font: {
...font,
...extractFont(frame.props)
}
};
return <Span {...spanProps} />
})
// TODO: format children
return {
alignment,
children
}
} }