Skip to content

Commit

Permalink
fix text with multiple br
Browse files Browse the repository at this point in the history
  • Loading branch information
makamekm committed Feb 29, 2020
1 parent f71d79b commit d01e93d
Showing 1 changed file with 20 additions and 23 deletions.
43 changes: 20 additions & 23 deletions style.plugins.js
Original file line number Diff line number Diff line change
Expand Up @@ -418,11 +418,9 @@ function setTextRenderer({ node, props, middleStyle, content }, { printStyle })
const fontStyle = node.style;
applyFontStyle(middleStyle, fontStyle);

const makeItFlex = () => {
middleStyle.display = 'flex';
middleStyle.maxWidth = '-webkit-fill-available';
middleStyle.alignContent = 'flex-start';
};
middleStyle.display = 'flex';
middleStyle.maxWidth = '-webkit-fill-available';
middleStyle.alignContent = 'flex-start';

if (fontStyle.textAlignHorizontal === 'CENTER') {
middleStyle.justifyContent = 'center';
Expand Down Expand Up @@ -479,7 +477,6 @@ function setTextRenderer({ node, props, middleStyle, content }, { printStyle })
}

if (Object.keys(props).includes('input')) {
makeItFlex();
const inputId = printStyle({
flex: 1,
height: '100%'
Expand All @@ -495,8 +492,6 @@ function setTextRenderer({ node, props, middleStyle, content }, { printStyle })
const styleCache = {};
let currStyle = 0;
let currStyleIndex = 0;
let nextLineCounter = 0;
let nextLineIndicator = false;

const maxCurrStyle = Object.keys(node.styleOverrideTable)
.map(s => Number.parseInt(s, 10))
Expand Down Expand Up @@ -529,7 +524,6 @@ function setTextRenderer({ node, props, middleStyle, content }, { printStyle })
) {
styleCache[currStyle].overflow = 'hidden';
styleCache[currStyle].textOverflow = 'ellipsis';
makeItFlex();
}

if (Object.keys(props).includes('ellipsisFlex') && maxCurrStyle === currStyle) {
Expand All @@ -551,30 +545,33 @@ function setTextRenderer({ node, props, middleStyle, content }, { printStyle })
.join('');
para = para.trim();

const br = Array(nextLineCounter)
.fill('<br/>')
.join('');

if (id) content.push(`<span className="${id}" key="${key}">${spaceBefore}{\`${para}\`}${spaceAfter}${br}</span>`);
else content.push(`<span key="${key}">${spaceBefore}{\`${para}\`}${spaceAfter}${br}</span>`);
if (id) content.push(`<span className="${id}" key="${key}">${spaceBefore}{\`${para}\`}${spaceAfter}</span>`);
else content.push(`<span key="${key}">${spaceBefore}{\`${para}\`}${spaceAfter}</span>`);

para = '';
currStyleIndex++;

nextLineCounter = 0;
nextLineIndicator = false;
};

for (const i in node.characters) {
let idx = node.characterStyleOverrides && node.characterStyleOverrides[i];
const char = node.characters[i];

if (nextLineIndicator && node.characters[i] !== '\n') {
commitParagraph(i);
para += char;
if (node.characters[i] === '\n' && node.characters[i - 1] === '\n') {
const id = printStyle({
flex: 1,
minWidth: '-webkit-fill-available'
});
content.push(`<div className="${id}" key="${`br${i}`}">&nbsp;</div>`);
} else if (node.characters[i] === '\n') {
nextLineIndicator = true;
nextLineCounter++;
commitParagraph(i);

const id = printStyle({
flex: 1,
content: '""',
minWidth: '-webkit-fill-available'
});
content.push(`<br className="${id}" key="${`br${i}`}" />`);
middleStyle.flexWrap = 'wrap';
} else {
if (idx == null) {
idx = 0;
Expand Down

0 comments on commit d01e93d

Please sign in to comment.