react-native icon indicating copy to clipboard operation
react-native copied to clipboard

[RCTText] Cached TextStorage not hit because of rounded width

Open cxfeng1-zz opened this issue 11 years ago • 2 comments

In method buildTextStorageForWidth, we use _cachedTextStorageWidth and _cachedTextStorage to store NSTextStorage.

  if (_cachedTextStorage && width == _cachedTextStorageWidth) {
    return _cachedTextStorage;
  }

While the text's property is updated, we construct a width to see if the NSTextStorage is built already.

  UIEdgeInsets padding = self.paddingAsInsets;
  CGFloat width = self.frame.size.width - (padding.left + padding.right);
  NSTextStorage *textStorage = [self buildTextStorageForWidth:width];

But here the width is not exactly same as the width before, because self.frame.size.width is a rounded one.

  CGRect frame = {{
    RCTRoundPixelValue(node->layout.position[CSS_LEFT]),
    RCTRoundPixelValue(node->layout.position[CSS_TOP]),
  }, {
    RCTRoundPixelValue(absoluteBottomRight.x - absoluteTopLeft.x),
    RCTRoundPixelValue(absoluteBottomRight.y - absoluteTopLeft.y)
  }};

  if (!CGRectEqualToRect(frame, _frame)) {
    _frame = frame;
    [viewsWithNewFrame addObject:self];
  }

For example , the width used to layout may be 100.0123456, the width to detect cache will be 100, which cause the text cache not hit even though using the same text and properties.

The first question is why the width and height should be rounded here ?

If they must be rounded, can we use a different value to store the unrounded frame?

cxfeng1-zz avatar Nov 26 '15 03:11 cxfeng1-zz

Hey cxfeng1, thanks for reporting this issue!

React Native, as you've probably heard, is getting really popular and truth is we're getting a bit overwhelmed by the activity surrounding it. There are just too many issues for us to manage properly.

  • If this is a feature request or a bug that you would like to be fixed by the team, please report it on Product Pains. It has a ranking feature that lets us focus on the most important issues the community is experiencing.
  • If you don't know how to do something or not sure whether some behavior is expected or a bug, please ask on StackOverflow with the tag react-native or for more real time interactions, ask on Discord in the #react-native channel.
  • We welcome clear issues and PRs that are ready for in-depth discussion; thank you for your contributions!

facebook-github-bot avatar Nov 26 '15 03:11 facebook-github-bot

Hi there! This issue is being closed because it has been inactive for a while.

But don't worry, it will live on with ProductPains! Check out its new home: https://productpains.com/post/react-native/rcttext-cached-textstorage-not-hit-because-of-rounded-width

ProductPains helps the community prioritize the most important issues thanks to its voting feature. It is easy to use - just login with GitHub.

Also, if this issue is a bug, please consider sending a PR with a fix. We're a small team and rely on the community for bug fixes of issues that don't affect fb apps.

mkonicek avatar Apr 10 '16 16:04 mkonicek