Files
react-native-svg/lib/extract/extractTextContent.js
2016-08-30 09:37:38 +08:00

27 lines
577 B
JavaScript

import React, {
Children
} from 'react';
import TSpan from '../../elements/TSpan';
const newLine = /\n/g;
export default function(children) {
let spans = [];
Children.forEach(children, function (child = '') {
let span;
if (typeof child === 'string') {
span = <TSpan>{child.replace(newLine, ' ')}</TSpan>;
} else if (child.type === TSpan) {
span = child;
} else {
// give warning about the illegal child type
return;
}
spans.push(span);
});
return spans;
}