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