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 /> doesn't recalculate it's size when a descendant <Text /> changes height due to wrapping following a device rotation #23443

Open
jeremywiebe opened this issue Feb 13, 2019 · 23 comments
Labels
Bug Component: View Issue: Author Provided Repro This issue can be reproduced in Snack or an attached project.

Comments

@jeremywiebe
Copy link

🐛 Bug Report

I believe I've found a bug in the View size calculation logic in React Native. In certain cases, the ancestor View fails to recalculate its size if a descendant <Text /> component changes in size due to a rotation and subsequent text (re)wrapping.

The following shows three states: initial, rotated, and back to original orientation. Notice that the fuschia view "grows" after returning to the original orientation.

Initial orientation

image

Portrait

image

Back to initial orientation

image

Speculative Analysis and Workaround

This appears to be an issue where an ancestor view caches a layout calculation and doesn't trigger a re-calculation when a nested Text component changes in size due to orientation changes.

After some playing around, we've figured out that if you "poke" any of the style properties that affect the view's style layout, the view will recalculate and be correct. We did this by toggling a state var upon rotation and then adding/removing a style object to the view's styles array that contained an extra paddingBottom that mirrored the existing padding on the view (basically we changed the style but the effect had no changes to the layout).

You can see a demo of the workaround by uncommenting the line of code below the FIXME comment in the code sample.

To Reproduce

See the code, but basically if you have a <ScrollView> that contains a container <View> which contains another <View> and then have a <Text> element inside that view... this layout bug will happen. I haven't been able to reduce this example further than that.

Expected Behavior

After rotating and going back to the initial orientation, the View should be exactly the same size.

Code Example

Github repo: https://github.com/jeremywiebe/react-native-text-orientation-bug

Environment

  React Native Environment Info:
    System:
      OS: macOS 10.14.2
      CPU: (8) x64 Intel(R) Core(TM) i7-7700HQ CPU @ 2.80GHz
      Memory: 34.97 MB / 16.00 GB
      Shell: 3.0.0 - /usr/local/bin/fish
    Binaries:
      Node: 8.15.0 - /usr/local/bin/node
      Yarn: 1.13.0 - /usr/local/bin/yarn
      npm: 6.4.1 - /usr/local/bin/npm
      Watchman: 4.9.0 - /usr/local/bin/watchman
    SDKs:
      iOS SDK:
        Platforms: iOS 12.1, macOS 10.14, tvOS 12.1, watchOS 5.1
      Android SDK:
        API Levels: 23, 25, 27
        Build Tools: 23.0.1, 25.0.0, 25.0.2, 25.0.3, 27.0.3, 28.0.1, 28.0.2, 28.0.3
        System Images: android-16 | Intel x86 Atom, android-16 | Google APIs Intel x86 Atom, android-19 | Intel x86 Atom, android-19 | Google APIs Intel x86 Atom, android-23 | Google APIs Intel x86 Atom_64, android-24 | Google APIs Intel x86 Atom, android-24 | Google Play Intel x86 Atom, android-25 | Google APIs Intel x86 Atom, android-28 | Google Play Intel x86 Atom
    IDEs:
      Android Studio: 3.1 AI-173.4907809
      Xcode: 10.1/10B61 - /usr/bin/xcodebuild
    npmPackages:
      react: 16.6.3 => 16.6.3 
      react-native: 0.58.4 => 0.58.4 
@hramos hramos added Issue: Author Provided Repro This issue can be reproduced in Snack or an attached project. Component: View labels Feb 13, 2019
@creambyemute
Copy link

Experiencing the same Problem.

I have a card which will wrap it's content (text) when changing from landscape <--> portrait due to space limitation. When changing back, the card is getting bigger.

@stale
Copy link

stale bot commented Aug 4, 2019

Hey there, it looks like there has been no activity on this issue recently. Has the issue been fixed, or does it still require the community's attention? This issue may be closed if no further activity occurs. You may also label this issue as a "Discussion" or add it to the "Backlog" and I will leave it open. Thank you for your contributions.

@stale stale bot added the Stale There has been a lack of activity on this issue and it may be closed soon. label Aug 4, 2019
@jeremywiebe
Copy link
Author

jeremywiebe commented Aug 4, 2019

stale[bot] this is still an issue. Please don’t close this bug.

@stale stale bot removed the Stale There has been a lack of activity on this issue and it may be closed soon. label Aug 4, 2019
@cristianoccazinsp
Copy link
Contributor

Seeing the same thing...

Text in Portrait: "bla bla bla bla bla bla..." ( 2 lines)
Text in Landscape: 'bla bla bla bla bla bla" (1 line)
Text in Portrait again after rotating: "bla bla bla bla...." (1 line)

Happens on iOS only.

@cristianoccazinsp
Copy link
Contributor

Any luck with this? Looks like poking the style prop of the view (e.g., adding a random min height each time onLayout is called) can fix the issue, but this is quite ugly and also would make every view slower.

Any quick efficient work around?

@stale
Copy link

stale bot commented Dec 11, 2019

Hey there, it looks like there has been no activity on this issue recently. Has the issue been fixed, or does it still require the community's attention? This issue may be closed if no further activity occurs. You may also label this issue as a "Discussion" or add it to the "Backlog" and I will leave it open. Thank you for your contributions.

@stale stale bot added the Stale There has been a lack of activity on this issue and it may be closed soon. label Dec 11, 2019
@cristianoccazinsp
Copy link
Contributor

Still an issue with 0.61.5

@stale stale bot removed the Stale There has been a lack of activity on this issue and it may be closed soon. label Dec 11, 2019
@stale
Copy link

stale bot commented Mar 11, 2020

Hey there, it looks like there has been no activity on this issue recently. Has the issue been fixed, or does it still require the community's attention? This issue may be closed if no further activity occurs. You may also label this issue as a "Discussion" or add it to the "Backlog" and I will leave it open. Thank you for your contributions.

@stale stale bot added the Stale There has been a lack of activity on this issue and it may be closed soon. label Mar 11, 2020
@cristianoccazinsp
Copy link
Contributor

This is still an issue and hasn't been fixed.

@stale stale bot removed the Stale There has been a lack of activity on this issue and it may be closed soon. label Mar 11, 2020
@stale
Copy link

stale bot commented Jun 9, 2020

Hey there, it looks like there has been no activity on this issue recently. Has the issue been fixed, or does it still require the community's attention? This issue may be closed if no further activity occurs. You may also label this issue as a "Discussion" or add it to the "Backlog" and I will leave it open. Thank you for your contributions.

@stale stale bot added the Stale There has been a lack of activity on this issue and it may be closed soon. label Jun 9, 2020
@cristianoccazinsp
Copy link
Contributor

This is still an issue.

@stale stale bot removed the Stale There has been a lack of activity on this issue and it may be closed soon. label Jun 9, 2020
@tapz
Copy link

tapz commented Aug 12, 2020

Not sure if it's the same issue, but in Android when rotating the device to landscape the window scaled outside of the visible screen area. So if I position something absolutely and set right: 0, the view is partially outside the screen. This didn't happen in RN 0.62. I'm using RN 0.63.2 and React 16.13.1.

@stale
Copy link

stale bot commented Dec 25, 2020

Hey there, it looks like there has been no activity on this issue recently. Has the issue been fixed, or does it still require the community's attention? This issue may be closed if no further activity occurs. You may also label this issue as a "Discussion" or add it to the "Backlog" and I will leave it open. Thank you for your contributions.

@stale stale bot added the Stale There has been a lack of activity on this issue and it may be closed soon. label Dec 25, 2020
@cristianoccazinsp
Copy link
Contributor

cristianoccazinsp commented Dec 25, 2020 via email

@stale stale bot removed the Stale There has been a lack of activity on this issue and it may be closed soon. label Dec 25, 2020
@Jacky-Rolo
Copy link

Jacky-Rolo commented Oct 1, 2021

I have a very very similar issue (react-native: 0.64.2), but @jeremywiebe 's workaround is NOT work for me.

Some how add inline Math.random() can solve my issue

<View style{{ flex ...}}>
  // Children
  <Text style={{display: 'none'}}>{`${Math.random()}`}</Text>  //  <-- super weird work around
</View>

I tried

  1. use key to re-mount whole component
  2. use fixed string replace Math.random
  3. use state to store Math.random, update it after rotate

none of them can solve issue.

I guess inline Math.random() make RN re-trigger something to manipulate iOS recalculate

I REAL wonder does this workaround can solve rest of yours' issue ??? 🤔
give me a emoji if this super weird workaround help you

@cristianoccazinsp
Copy link
Contributor

cristianoccazinsp commented Oct 1, 2021 via email

@stale
Copy link

stale bot commented Jan 9, 2022

Hey there, it looks like there has been no activity on this issue recently. Has the issue been fixed, or does it still require the community's attention? This issue may be closed if no further activity occurs. You may also label this issue as a "Discussion" or add it to the "Backlog" and I will leave it open. Thank you for your contributions.

@stale stale bot added the Stale There has been a lack of activity on this issue and it may be closed soon. label Jan 9, 2022
@cristianoccazinsp
Copy link
Contributor

Still a bug.

@stale stale bot removed the Stale There has been a lack of activity on this issue and it may be closed soon. label Jan 9, 2022
@danger9224
Copy link

danger9224 commented Sep 7, 2022

For me, randomly updating the minHeight of the View containing the Text did the trick. Like so:

<View style={{ minHeight: Math.random() }}>
  <Text></Text> // <-- the text that changes their height
</View>

@cristianoccazinsp
Copy link
Contributor

That’s an awful work around as it means constant re renders, and hard to explain. Would you do this for every text component you use?

@github-actions
Copy link

github-actions bot commented Mar 6, 2023

This issue is stale because it has been open 180 days with no activity. Remove stale label or comment or this will be closed in 7 days.

@github-actions github-actions bot added the Stale There has been a lack of activity on this issue and it may be closed soon. label Mar 6, 2023
@jeremywiebe
Copy link
Author

Still an issue.

@github-actions github-actions bot removed the Stale There has been a lack of activity on this issue and it may be closed soon. label Mar 7, 2023
@praisedavid787

This comment was marked as abuse.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug Component: View Issue: Author Provided Repro This issue can be reproduced in Snack or an attached project.
Projects
None yet
Development

No branches or pull requests

9 participants