@@ -237,41 +237,12 @@ private static void buildSpannedFromShadowNode(
237237 supportsInlineViews ,
238238 inlineViews ,
239239 sb .length ());
240- } else if (child instanceof ReactTextInlineImageShadowNode ) {
241- // We make the image take up 1 character in the span and put a corresponding character into
242- // the text so that the image doesn't run over any following text.
243- sb .append (INLINE_VIEW_PLACEHOLDER );
244- ops .add (
245- new SetSpanOperation (
246- sb .length () - INLINE_VIEW_PLACEHOLDER .length (),
247- sb .length (),
248- ((ReactTextInlineImageShadowNode ) child ).buildInlineImageSpan ()));
240+ } else if (child instanceof ReactTextInlineImageShadowNode inlineImageChild ) {
241+ addInlineImageSpan (ops , sb , inlineImageChild );
249242 } else if (supportsInlineViews ) {
250- int reactTag = child .getReactTag ();
251- YogaValue widthValue = child .getStyleWidth ();
252- YogaValue heightValue = child .getStyleHeight ();
253-
254- float width ;
255- float height ;
256- if (widthValue .unit != YogaUnit .POINT || heightValue .unit != YogaUnit .POINT ) {
257- // If the measurement of the child isn't calculated, we calculate the layout for the
258- // view using Yoga
259- child .calculateLayout ();
260- width = child .getLayoutWidth ();
261- height = child .getLayoutHeight ();
262- } else {
263- width = widthValue .value ;
264- height = heightValue .value ;
265- }
266-
267- // We make the inline view take up 1 character in the span and put a corresponding character
268- // into
269- // the text so that the inline view doesn't run over any following text.
270- sb .append (INLINE_VIEW_PLACEHOLDER );
243+ addInlineViewPlaceholderSpan (ops , sb , child );
271244
272- TextLayoutUtils .addInlineViewPlaceholderSpan (ops , sb , reactTag , width , height );
273-
274- inlineViews .put (reactTag , child );
245+ inlineViews .put (child .getReactTag (), child );
275246 } else {
276247 throw new IllegalViewOperationException (
277248 "Unexpected view type nested under a <Text> or <TextInput> node: " + child .getClass ());
@@ -287,6 +258,40 @@ private static void buildSpannedFromShadowNode(
287258 }
288259 }
289260
261+ private static void addInlineImageSpan (List <SetSpanOperation > ops , SpannableStringBuilder sb ,
262+ ReactTextInlineImageShadowNode child ) {
263+ // We make the image take up 1 character in the span and put a corresponding character into
264+ // the text so that the image doesn't run over any following text.
265+ sb .append (INLINE_VIEW_PLACEHOLDER );
266+ ops .add (new SetSpanOperation (sb .length () - INLINE_VIEW_PLACEHOLDER .length (), sb .length (),
267+ child .buildInlineImageSpan ()));
268+ }
269+
270+ private static void addInlineViewPlaceholderSpan (List <SetSpanOperation > ops , SpannableStringBuilder sb ,
271+ ReactShadowNode child ) {
272+ YogaValue widthValue = child .getStyleWidth ();
273+ YogaValue heightValue = child .getStyleHeight ();
274+
275+ float width ;
276+ float height ;
277+ if (widthValue .unit != YogaUnit .POINT || heightValue .unit != YogaUnit .POINT ) {
278+ // If the measurement of the child isn't calculated, we calculate the layout for the
279+ // view using Yoga
280+ child .calculateLayout ();
281+ width = child .getLayoutWidth ();
282+ height = child .getLayoutHeight ();
283+ } else {
284+ width = widthValue .value ;
285+ height = heightValue .value ;
286+ }
287+
288+ // We make the inline view take up 1 character in the span and put a corresponding character into the text so that
289+ // the inline view doesn't run over any following text.
290+ sb .append (INLINE_VIEW_PLACEHOLDER );
291+
292+ TextLayoutUtils .addInlineViewPlaceholderSpan (ops , sb , child .getReactTag (), width , height );
293+ }
294+
290295 // `nativeViewHierarchyOptimizer` can be `null` as long as `supportsInlineViews` is `false`.
291296 protected Spannable spannedFromShadowNode (
292297 ReactBaseTextShadowNode textShadowNode ,
0 commit comments