From 0e0c3fb08f73951e40cef464b42e2354af957fb8 Mon Sep 17 00:00:00 2001 From: IvanIhnatsiuk Date: Thu, 11 Dec 2025 00:06:34 +0100 Subject: [PATCH 1/8] fix: set single attributed string to text view --- example/src/App.tsx | 74 +++++ ios/EnrichedTextInputView.h | 25 +- ios/EnrichedTextInputView.mm | 32 +- ios/inputParser/InputParser.mm | 299 ++++++++++++------ ios/styles/BlockQuoteStyle.mm | 96 ++++-- ios/styles/BoldStyle.mm | 79 ++--- ios/styles/CodeBlockStyle.mm | 102 +++--- ios/styles/HeadingStyleBase.mm | 72 +++-- ios/styles/ImageAttachment.h | 10 + ios/styles/ImageAttachment.mm | 33 ++ ios/styles/ImageStyle.mm | 134 ++++---- ios/styles/InlineCodeStyle.mm | 142 ++++----- ios/styles/ItalicStyle.mm | 73 ++--- ios/styles/LinkStyle.mm | 148 +++++++-- ios/styles/MediaAttachment.h | 23 ++ ios/styles/MediaAttachment.mm | 33 ++ ios/styles/MentionStyle.mm | 97 ++++++ ios/styles/OrderedListStyle.mm | 107 +++++-- ios/styles/StrikethroughStyle.mm | 35 ++- ios/styles/UnderlineStyle.mm | 34 +- ios/styles/UnorderedListStyle.mm | 93 ++++-- ios/utils/BaseStyleProtocol.h | 5 +- ios/utils/OccurenceUtils.h | 103 ++++--- ios/utils/OccurenceUtils.mm | 513 +++++++++++++++++++------------ ios/utils/ParagraphsUtils.h | 2 + ios/utils/ParagraphsUtils.mm | 50 +++ ios/utils/StyleHeaders.h | 14 +- ios/utils/TextInsertionUtils.h | 16 +- ios/utils/TextInsertionUtils.mm | 23 ++ 29 files changed, 1677 insertions(+), 790 deletions(-) create mode 100644 ios/styles/ImageAttachment.h create mode 100644 ios/styles/ImageAttachment.mm create mode 100644 ios/styles/MediaAttachment.h create mode 100644 ios/styles/MediaAttachment.mm diff --git a/example/src/App.tsx b/example/src/App.tsx index d36ac903a..a4587fba7 100644 --- a/example/src/App.tsx +++ b/example/src/App.tsx @@ -70,6 +70,78 @@ const DEBUG_SCROLLABLE = false; // See: https://github.com/software-mansion/react-native-enriched/issues/229 const ANDROID_EXPERIMENTAL_SYNCHRONOUS_EVENTS = false; +const generateHugeHtml = (repeat = 10) => { + const parts: string[] = []; + parts.push(''); + + // small helper to make deterministic colors + const colorAt = (i: number) => { + const r = (37 * (i + 1)) % 256; + const g = (83 * (i + 7)) % 256; + const b = (199 * (i + 13)) % 256; + const toHex = (n: number) => n.toString(16).padStart(2, '0'); + return `#${toHex(r)}${toHex(g)}${toHex(b)}`; + }; + + for (let i = 0; i < repeat; i++) { + const col = colorAt(i); + const imgW = 200 + (i % 5) * 40; + const imgH = 100 + (i % 3) * 30; + + parts.push( + // Headings + `\n

Section ${i + 1}

`, + `\n

Subsection ${i + 1}.1

`, + `\n

Topic ${i + 1}.1.a

`, + + // Paragraph with mixed inline styles + `\n

This is a bold and italic paragraph with underline, ` + + `strike, inline_code_${i}, ` + + `a link ${i}, ` + + `, ` + + `, ` + + `colored text ${col} and some plain text to bulk it up.

`, + + // Line break + `\n
`, + + // Unordered list + `\n`, + + // Ordered list + `\n
    `, + `\n
  1. step 1.${i}
  2. `, + `\n
  3. step 2.${i}
  4. `, + `\n
  5. step 3.${i}
  6. `, + `\n
`, + + // Blockquote + `\n
`, + `\n

“Blockquote line 1 for ${i}.”

`, + `\n

“Blockquote line 2 for ${i}.”

`, + `\n
`, + + // Code block (escaped characters) + `\n`, + `\n

for (let k = 0; k < ${i % 7}; k++) { console.log("block_${i}"); }

`, + `\n
`, + + // Image (self-closing) + `\n

` + ); + } + + parts.push('\n'); + return parts.join(''); +}; + +const initialHugeHtml = generateHugeHtml(); +console.log(initialHugeHtml.length); + export default function App() { const [isChannelPopupOpen, setIsChannelPopupOpen] = useState(false); const [isUserPopupOpen, setIsUserPopupOpen] = useState(false); @@ -82,6 +154,7 @@ export default function App() { const [stylesState, setStylesState] = useState(DEFAULT_STYLE); const [currentLink, setCurrentLink] = useState(DEFAULT_LINK_STATE); + const [visible, setVisible] = useState(false); const ref = useRef(null); @@ -287,6 +360,7 @@ export default function App() { style={styles.container} contentContainerStyle={styles.content} > +