Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

View within text returns strange image - iOS 13 #26577

Closed
djorkaeffalexandre opened this issue Sep 25, 2019 · 8 comments
Closed

View within text returns strange image - iOS 13 #26577

djorkaeffalexandre opened this issue Sep 25, 2019 · 8 comments
Labels
Bug Component: Image Platform: iOS iOS applications. Resolution: Locked This issue was locked by the bot.

Comments

@djorkaeffalexandre
Copy link

djorkaeffalexandre commented Sep 25, 2019

React Native version: 0.61.1 | 0.60.5

Steps To Reproduce

  1. Any <View> within <Text> generate a weird behavior..
<Text>
  <View style={{width: 200, height: 200}} />
</Text>
  1. Same to <Text><Image /></Text> like a:
<Text>
  <Image
    style={{ width: 30, height: 30 }}
    source={{
      uri:
      'https://upload.wikimedia.org/wikipedia/commons/5/58/Ponto_Amarelo.png',
    }}
   />
</Text>

It returns a strange image behind the image after upgrade to iOS 13.

Screenshots

Captura de Tela 2019-09-25 às 16 23 54

@KarenQiao
Copy link

yes ,i also have this problem

@djorkaeffalexandre djorkaeffalexandre changed the title Image within text returns strange image - iOS 13 View within text returns strange image - iOS 13 Sep 26, 2019
@partiellkorrekt
Copy link

I searched a little through the react-native code and found that the strange image is the placeholder icon for an attachment in an NSAttributedString. RN seems to add attachments to the string to reserve some space and lay the real view on top of the rendered string.

In RCTTextShadowView.m there is a function "attributedTextWithMeasuredAttachmentsThatFitSize" which creates the attachments by using the following code:

NSTextAttachment *attachment = [NSTextAttachment new];
attachment.bounds = (CGRect){CGPointZero, fittingSize};
[attributedText addAttribute:NSAttachmentAttributeName value:attachment range:range];

To verify that the image really is the placeholder image, I modified the code to add an empty image as the attachment image:

NSTextAttachment *attachment = [NSTextAttachment new];
attachment.bounds = (CGRect){CGPointZero, fittingSize};

// This creates an empty image on the fly (just for testing purposes)
UIGraphicsBeginImageContextWithOptions(CGSizeMake(1, 1), NO, 0);
UIImage *img = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();

// Set this empty image as the attachment image
[attachment setImage:img];
      
[attributedText addAttribute:NSAttachmentAttributeName value:attachment range:range];

Using this code, RN stops rendering the document icons and the output looks as expected.

Warning
This code might create a lot of unnecessary images and I don't know how it will affect memory usage. So don't use it in production.

partiellkorrekt added a commit to partiellkorrekt/react-native that referenced this issue Sep 30, 2019
See facebook#26577 for the idea behind this change
@partiellkorrekt
Copy link

I created a new pull-request where the image is only being created once for all attachments. This might be the way to go.

@kristerkari
Copy link

I'm seeing the same thing on 0.60.5 and iOS 13 when there is a png or svg image inside a <Text>.

@kristerkari
Copy link

I created a new 0.61.1 project that can be used to reproduce the bug:
https://github.com/kristerkari/react-native-ios-13-view-or-image-inside-text-bug

At least React Native versions 0.59, 0.60, and 0.61 seem to be affected (possibly all RN versions).

The bug can also be reproduced on my iPhone 8 device with iOS 13.1 installed.

iOS 12.1
Skärmavbild 2019-10-02 kl  10 58 13

iOS 13.0
Skärmavbild 2019-10-02 kl  10 58 16

@wumke
Copy link

wumke commented Oct 7, 2019

Also seeing this issue after updating my phone to IOS13 with RN0.58 app.

@partiellkorrekt : can you place a link to the pull request here? (I need a solution to implement in a production ready app... this issue is really a last-minute p**n in the *ss for my project!)

@partiellkorrekt
Copy link

@wumke Here you go: #26653 :)

facebook-github-bot pushed a commit that referenced this issue Oct 21, 2019
Summary:
This fixes a bug reported by Oculus and OSS.

#26577

When rendering images nested in a `<Text/>` node, on the native side, `RCTTextShadowView` adds an empty NSTextAttachment to the attributed string to add some extra space. The image is then overlaid in the empty space  . This all works fine and dandy on iOS12 and below.

Starting in iOS13, an empty NSTextAttachment doesn't render as blank space. It renders as the "missing image" white page. When the real image is overlaid on the white page, it looks super broken. See github issue and test plan for examples.

This fix is to assign an empty image to `NSTextAttachment`. I tried seeing if there was any other attribute we could use to just add white space to an attributed string, but this seems like the best one.

Changelog: [iOS][Fixed] Fixed bug rendering nested text on iOS13

Reviewed By: xyin96

Differential Revision: D18048277

fbshipit-source-id: 711cee96934fc1937d694621a4417c152dde3a31
@PeteTheHeat
Copy link
Contributor

This commit fixes this issue :)
06599b3

grabbou pushed a commit that referenced this issue Oct 28, 2019
Summary:
This fixes a bug reported by Oculus and OSS.

#26577

When rendering images nested in a `<Text/>` node, on the native side, `RCTTextShadowView` adds an empty NSTextAttachment to the attributed string to add some extra space. The image is then overlaid in the empty space  . This all works fine and dandy on iOS12 and below.

Starting in iOS13, an empty NSTextAttachment doesn't render as blank space. It renders as the "missing image" white page. When the real image is overlaid on the white page, it looks super broken. See github issue and test plan for examples.

This fix is to assign an empty image to `NSTextAttachment`. I tried seeing if there was any other attribute we could use to just add white space to an attributed string, but this seems like the best one.

Changelog: [iOS][Fixed] Fixed bug rendering nested text on iOS13

Reviewed By: xyin96

Differential Revision: D18048277

fbshipit-source-id: 711cee96934fc1937d694621a4417c152dde3a31
douglowder pushed a commit to react-native-tvos/react-native-tvos that referenced this issue Dec 11, 2019
Summary:
This fixes a bug reported by Oculus and OSS.

facebook/react-native#26577

When rendering images nested in a `<Text/>` node, on the native side, `RCTTextShadowView` adds an empty NSTextAttachment to the attributed string to add some extra space. The image is then overlaid in the empty space  . This all works fine and dandy on iOS12 and below.

Starting in iOS13, an empty NSTextAttachment doesn't render as blank space. It renders as the "missing image" white page. When the real image is overlaid on the white page, it looks super broken. See github issue and test plan for examples.

This fix is to assign an empty image to `NSTextAttachment`. I tried seeing if there was any other attribute we could use to just add white space to an attributed string, but this seems like the best one.

Changelog: [iOS][Fixed] Fixed bug rendering nested text on iOS13

Reviewed By: xyin96

Differential Revision: D18048277

fbshipit-source-id: 711cee96934fc1937d694621a4417c152dde3a31
dmiskiew pushed a commit to offCents/react-native that referenced this issue Jan 17, 2020
Summary:
This fixes a bug reported by Oculus and OSS.

facebook#26577

When rendering images nested in a `<Text/>` node, on the native side, `RCTTextShadowView` adds an empty NSTextAttachment to the attributed string to add some extra space. The image is then overlaid in the empty space  . This all works fine and dandy on iOS12 and below.

Starting in iOS13, an empty NSTextAttachment doesn't render as blank space. It renders as the "missing image" white page. When the real image is overlaid on the white page, it looks super broken. See github issue and test plan for examples.

This fix is to assign an empty image to `NSTextAttachment`. I tried seeing if there was any other attribute we could use to just add white space to an attributed string, but this seems like the best one.

Changelog: [iOS][Fixed] Fixed bug rendering nested text on iOS13

Reviewed By: xyin96

Differential Revision: D18048277

fbshipit-source-id: 711cee96934fc1937d694621a4417c152dde3a31
maxfurman pushed a commit to TeamGuilded/react-native that referenced this issue Jun 16, 2020
Summary:
This fixes a bug reported by Oculus and OSS.

facebook#26577

When rendering images nested in a `<Text/>` node, on the native side, `RCTTextShadowView` adds an empty NSTextAttachment to the attributed string to add some extra space. The image is then overlaid in the empty space  . This all works fine and dandy on iOS12 and below.

Starting in iOS13, an empty NSTextAttachment doesn't render as blank space. It renders as the "missing image" white page. When the real image is overlaid on the white page, it looks super broken. See github issue and test plan for examples.

This fix is to assign an empty image to `NSTextAttachment`. I tried seeing if there was any other attribute we could use to just add white space to an attributed string, but this seems like the best one.

Changelog: [iOS][Fixed] Fixed bug rendering nested text on iOS13

Reviewed By: xyin96

Differential Revision: D18048277

fbshipit-source-id: 711cee96934fc1937d694621a4417c152dde3a31
@facebook facebook locked as resolved and limited conversation to collaborators Oct 3, 2021
@react-native-bot react-native-bot added the Resolution: Locked This issue was locked by the bot. label Oct 3, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Bug Component: Image Platform: iOS iOS applications. Resolution: Locked This issue was locked by the bot.
Projects
None yet
Development

No branches or pull requests

7 participants