Inline image breaking layout when setting lineHeight in react-native-render-html

I’m using the react-native-render-html (Foundry release) to render HTML content in my React Native app. The HTML content includes inline images along with text.

My HTML includes text and inline images as shown below:

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
<code><div class="bbWrapper">
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Pariatur anim occaecat mollit amet dolor ut laboris fugiat quis cupidatat non ad reprehenderit id. Nisi ut enim adipisicing duis deserunt anim nostrud duis ex dolore laborum qui incididunt. Labore dolor magna commodo deserunt consectetur.
.<br>
lorem ipsum dolor sit amet <img src="https://data.voz.vn/styles/next/xenforo/smilies/popopo/after_boom.png?v=01" srcset="https://data.voz.vn/styles/next/xenforo/smilies/popopo/after_boom.png?v=01 1x, https://data.voz.vn/styles/next/xenforo/smilies/popopo/after_boom_x2.png?v=01 2x" class="smilie" loading="lazy" alt=":after_boom:" title="after_boom :after_boom:" data-shortname=":after_boom:"></div>
</code>
<code><div class="bbWrapper"> Lorem ipsum dolor sit amet, consectetur adipiscing elit. Pariatur anim occaecat mollit amet dolor ut laboris fugiat quis cupidatat non ad reprehenderit id. Nisi ut enim adipisicing duis deserunt anim nostrud duis ex dolore laborum qui incididunt. Labore dolor magna commodo deserunt consectetur. .<br> lorem ipsum dolor sit amet <img src="https://data.voz.vn/styles/next/xenforo/smilies/popopo/after_boom.png?v=01" srcset="https://data.voz.vn/styles/next/xenforo/smilies/popopo/after_boom.png?v=01 1x, https://data.voz.vn/styles/next/xenforo/smilies/popopo/after_boom_x2.png?v=01 2x" class="smilie" loading="lazy" alt=":after_boom:" title="after_boom :after_boom:" data-shortname=":after_boom:"></div> </code>
<div class="bbWrapper">
  Lorem ipsum dolor sit amet, consectetur adipiscing elit. Pariatur anim occaecat mollit amet dolor ut laboris fugiat quis cupidatat non ad reprehenderit id. Nisi ut enim adipisicing duis deserunt anim nostrud duis ex dolore laborum qui incididunt. Labore dolor magna commodo deserunt consectetur.
  .<br>
  lorem ipsum dolor sit amet <img src="https://data.voz.vn/styles/next/xenforo/smilies/popopo/after_boom.png?v=01" srcset="https://data.voz.vn/styles/next/xenforo/smilies/popopo/after_boom.png?v=01 1x, https://data.voz.vn/styles/next/xenforo/smilies/popopo/after_boom_x2.png?v=01 2x" class="smilie" loading="lazy" alt=":after_boom:" title="after_boom    :after_boom:" data-shortname=":after_boom:"></div>

I have customized the img element model to allow mixed content using the following code:

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
<code>const customHTMLElementModels = {
img: defaultHTMLElementModels.img.extend({
contentModel: HTMLContentModel.mixed,
}),
};
</code>
<code>const customHTMLElementModels = { img: defaultHTMLElementModels.img.extend({ contentModel: HTMLContentModel.mixed, }), }; </code>
const customHTMLElementModels = {
  img: defaultHTMLElementModels.img.extend({
    contentModel: HTMLContentModel.mixed,
  }),
};

In the main RenderHTML component, I have set the defaultTextProps to specify a custom line height for the text:

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
<code><RenderHTML
contentWidth={width}
source={source}
customHTMLElementModels={customHTMLElementModels}
renderersProps={renderersProps}
enableCSSInlineProcessing={true}
debug
defaultTextProps={{
selectable: true,
style: {
fontFamily: 'sans-serif',
fontSize: 16,
fontWeight: '400',
lineHeight: 24, // layout breaks here
color: 'black',
},
}}
/>
</code>
<code><RenderHTML contentWidth={width} source={source} customHTMLElementModels={customHTMLElementModels} renderersProps={renderersProps} enableCSSInlineProcessing={true} debug defaultTextProps={{ selectable: true, style: { fontFamily: 'sans-serif', fontSize: 16, fontWeight: '400', lineHeight: 24, // layout breaks here color: 'black', }, }} /> </code>
<RenderHTML
  contentWidth={width}
  source={source}
  customHTMLElementModels={customHTMLElementModels}
  renderersProps={renderersProps}
  enableCSSInlineProcessing={true}
  debug
  defaultTextProps={{
    selectable: true,
    style: {
      fontFamily: 'sans-serif',
      fontSize: 16,
      fontWeight: '400',
      lineHeight: 24, // layout breaks here
      color: 'black',
    },
  }}
/>

The problem I’m facing is that when I set a custom lineHeight value, it applies the same line height to all the text, including the lines containing inline images. This causes the layout to break and the images to overlap with the text.

LineHeight applies the same too all the text

However, if I don’t set a custom lineHeight, the lines with inline images have a dynamic height that adjusts based on the image size, and the layout looks fine.

Lineheight does not applies the same to all the text

How can I achieve a layout where the lineHeight is set to a default value for regular text, but for lines containing inline images, the height should dynamically adjust to accommodate the image size without breaking the layout?

I would appreciate any suggestions or workarounds to solve this issue while still being able to set a custom line height for the text.

Thank you in advance!

Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa Dịch vụ tổ chức sự kiện 5 sao Thông tin về chúng tôi Dịch vụ sinh nhật bé trai Dịch vụ sinh nhật bé gái Sự kiện trọn gói Các tiết mục giải trí Dịch vụ bổ trợ Tiệc cưới sang trọng Dịch vụ khai trương Tư vấn tổ chức sự kiện Hình ảnh sự kiện Cập nhật tin tức Liên hệ ngay Thuê chú hề chuyên nghiệp Tiệc tất niên cho công ty Trang trí tiệc cuối năm Tiệc tất niên độc đáo Sinh nhật bé Hải Đăng Sinh nhật đáng yêu bé Khánh Vân Sinh nhật sang trọng Bích Ngân Tiệc sinh nhật bé Thanh Trang Dịch vụ ông già Noel Xiếc thú vui nhộn Biểu diễn xiếc quay đĩa Dịch vụ tổ chức tiệc uy tín Khám phá dịch vụ của chúng tôi Tiệc sinh nhật cho bé trai Trang trí tiệc cho bé gái Gói sự kiện chuyên nghiệp Chương trình giải trí hấp dẫn Dịch vụ hỗ trợ sự kiện Trang trí tiệc cưới đẹp Khởi đầu thành công với khai trương Chuyên gia tư vấn sự kiện Xem ảnh các sự kiện đẹp Tin mới về sự kiện Kết nối với đội ngũ chuyên gia Chú hề vui nhộn cho tiệc sinh nhật Ý tưởng tiệc cuối năm Tất niên độc đáo Trang trí tiệc hiện đại Tổ chức sinh nhật cho Hải Đăng Sinh nhật độc quyền Khánh Vân Phong cách tiệc Bích Ngân Trang trí tiệc bé Thanh Trang Thuê dịch vụ ông già Noel chuyên nghiệp Xem xiếc khỉ đặc sắc Xiếc quay đĩa thú vị
Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa
Thiết kế website Thiết kế website Thiết kế website Cách kháng tài khoản quảng cáo Mua bán Fanpage Facebook Dịch vụ SEO Tổ chức sinh nhật