question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Going back does not recalculate screen height when parent height is dynamic

See original GitHub issue

Description

I have a native stack navigator inside a bottom sheet. The bottom sheet’s height is dynamic and depends on the currently focused screen. The problem is when going from a taller screen into a smaller one and then back UIViewControllerWrapperView and its children (RNSScreen & RNSScreenView) stay the size of the previous screen (check flipper screenshot below). Visually it is not changing anything, but taps are not registered anywhere below the old height.

Screenshots

Here I have the first screen where the whole area is tappable and navigates to the second small screen. When coming back, I can not tap anymore below the top 100px (the height of the second screen).

https://user-images.githubusercontent.com/25742/133996001-1c2a7f48-0220-40af-b4bf-c71c53cde0a7.mov

image

Currently, I’m changing the height via the useFocusEffect hook from react-navigation. The problem can go away if I do that on transitionEnd, but that would highly delay the animation.

I would be happy to start working on a snack but maybe there is a fast solution that I’m not aware of?

Package versions

  • React: 17.0.2
  • React Native: 0.65.1
  • React Native Screens: 3.7.2

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Comments:9 (4 by maintainers)

github_iconTop GitHub Comments

1reaction
somebody32commented, Sep 28, 2021

@WoLewicki got it, thanks. So I’ll close the issue if nothing can be done here.

For anyone having the same problem, here is a fast hack that minimizes it:

let isFocused = useRef(true);
let sheetHeight = 400;

useFocusEffect(
  useCallback(() => {
    setBottomSheetHeight(sheetHeight);
  }, [setBottomSheetHeight, sheetHeight])
);

useEffect(() => {
  return navigation.addListener('focus', () => {
    isFocused.current = true;
  });
}, [navigation]);

useEffect(() => {
  return navigation.addListener('blur', () => {
    isFocused.current = false;
  });
}, [navigation]);

useEffect(() => {
  return navigation.addListener('transitionEnd', () => {
    if (!isFocused.current) {
      return;
    }

    // this is required to allow navigational controller to get new
    // view height, otherwise it would use the cached one from the previous
    // screen. And no, setImmediate is not working,
    // and yes, 0.3 is the minimum value that works
    setBottomSheetHeight(sheetHeight + 0.3);
    setTimeout(() => {
      setBottomSheetHeight(sheetHeight);
    }, 0);
  });
}, [navigation, setBottomSheetHeight, sheetHeight]);
0reactions
WoLewickicommented, Sep 27, 2021
  1. and 3. are caused by the native navigation, which was said in previous comment.
  2. is probably due to the memoization or just how react works.

createStackNavigator does not use native animation transition options, it is fully controlled from the JS by Animated and react-native-gesture-handler. I am not sure if we can do much about it unfortunately.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Move div with dynamic height out of its parent container
I'm trying to move a div with a dynamically changing height out of it's parent div and back in.
Read more >
height - CSS: Cascading Style Sheets - MDN Web Docs
The height CSS property specifies the height of an element. By default, the property defines the height of the content area.
Read more >
aspect-ratio - CSS-Tricks
The CSS property aspect-ratio lets you create boxes that maintain proportional dimensions where the height and width of a box are calculated ...
Read more >
Build a responsive app - Adding Dynamic Containers
The height is going to be 80 and the width needs to fit the full screen width. The screen is the parent of...
Read more >
How to make div height expand with its content using CSS
The height property does not contains padding, margin and border of element. ... It is used to set height property from its parent...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found