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.

Using translateY to non-absolute elements.

See original GitHub issue

Idk is there anybody who having this issue like me but, what im trying to do is , i want to collapse my header up when i scroll down and show it again immediately if i scroll up. Basic animation you know it:

And im using a method like below for the animation:

 const H_MAX_HEIGHT = 130;
  const H_MIN_HEIGHT = 0;
  const scrollY = useRef(new Animated.Value(0)).current;
  const diffClampScrollY = Animated.diffClamp(scrollY, 0, H_MAX_HEIGHT);
  const headerScrollHeight = Animated.interpolate(diffClampScrollY, {
    inputRange: [H_MIN_HEIGHT, H_MAX_HEIGHT],
    outputRange: [H_MIN_HEIGHT, -H_MAX_HEIGHT],
    extrapolate: diffClampScrollY,
  });

H_MAX_HEIGHT 130 becouse my header is position absolute and it haas 130px of height. so i give this headerScrollHeight to my header as a translateY value, it goes up nothings wong. butt i want also the next element go up and clear the empty area… Actually the next element is scrollview’s itself, and its not position abosolute … and if i give this headerScrollHeight to it as well, as a translateY value, its going up but shaking too much… 😦 i dont know what to do… in the scrollview i have a masonrylist component, in which i can’t get the scroll position with Animated… i can only get regular scrollY axis. thats why i collapsed the masonrylist component with a scrollview to convert it to Animated.ScrollView.. to get Animated.event properly… …

///// entire component is looking like that ///

<Animated.View
        style={{
          left: 0,
          right: 0,
          top: 0,
          position: 'absolute',
          height: H_MAX_HEIGHT,
          width: width,
          paddingHorizontal: 20,
          transform: [{translateY: headerScrollHeight}],
          overflow: 'hidden',
          zIndex: 999,
          backgroundColor: '#fff',
        }}>
        <Animatable.View animation="bounceInDown" delay={1500}>
          <HeaderNavigation FilterItems={FilterItems} props={navigation} />
        </Animatable.View>
      </Animated.View>
      <Animated.ScrollView
        onScroll={Animated.event([
          {
            nativeEvent: {contentOffset: {y: scrollY}},
          },
        ])}
        scrollEventThrottle={1}
        bounces={false}
        style={[styles.Wrapper, {paddingTop: H_MAX_HEIGHT}]}>
        <MasonryList
          imageContainerStyle={styles.Image}
          columns={2}
          spacing={5}
          images={data}
          onPressImage={item => navigation.navigate('Detail', {item})}
        />
      </Animated.ScrollView>

Issue Analytics

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

github_iconTop GitHub Comments

2reactions
Mhde96commented, Mar 6, 2020

i have the same problem if you solve it please tell me how

1reaction
matthieugayoncommented, Apr 29, 2020

Same here, did you manage to solve that issue ?

Read more comments on GitHub >

github_iconTop Results From Across the Web

css element with translatey(0) is not being positioned properly
To get an absolutely positioned element to go to the top of the page, as is described in the question, it needs to...
Read more >
translateY() - CSS: Cascading Style Sheets - MDN Web Docs
The translateY() CSS function repositions an element vertically on the 2D plane. Its result is a data type.
Read more >
Why moving elements with translate() is better than pos:abs ...
Every 10 seconds, I add a class, that has the property translateY(300px), so the images gets "pushed up" and reveals the other image....
Read more >
translate - CSS-Tricks
The translate CSS property allows you to transfer an element from one ... Computed value: as specified, but with relative lengths converted ...
Read more >
Position · Bootstrap v5.0
This class applies the transformations translateX(-50%) and translateY(-50%) to the element which, in combination with the edge positioning utilities, ...
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