mirror of
https://github.com/zoriya/react-native-svg.git
synced 2025-12-20 22:05:14 +00:00
first step of TSpan
This commit is contained in:
26
lib/extract/extractTextContent.js
Normal file
26
lib/extract/extractTextContent.js
Normal file
@@ -0,0 +1,26 @@
|
||||
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;
|
||||
}
|
||||
Reference in New Issue
Block a user