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.

Getting scaling effect when moving bottom sheet up and down

See original GitHub issue

Ask your Question

Hello,

I’ve switched to using your bottom sheet from the react-native-scroll-bottom-sheet. I’m wondering if you know how to get the same effect as displayed here: https://www.npmjs.com/package/react-native-scroll-bottom-sheet - where the card scales down as you move the bottom sheet up. In react-native-scroll-bottom-sheet it was using animatedPosition in combination with features from react reanimated v2, but it seems to have a different functionality with your bottom sheet. Trying to use this now:

import { Extrapolate, interpolateNode, useSharedValue } from 'react-native-reanimated';
........
   
  const animatedPosition = useSharedValue<number>(0);
   const animatedIndex = useSharedValue<number>(0);
   const cardScale = interpolateNode(animatedPosition.value, {
      inputRange: [0, 0.6, 1],
      outputRange: [1, 0.9, 0.7],
      extrapolate: Extrapolate.CLAMP,
   });

where cardScale ends up here - this is the image I’m trying to scale:

const CardView: FunctionComponent<CardViewProps> = ({ source, cardScale }) => {
   return (
      <View style={styles.container}>
         <Animated.Image
            source={source}
            style={[styles.imageStyle, { transform: [{ scale: cardScale }] }]}
         />
      </View>
   );
};

and the BottomSheet looks like so:

 <BottomSheet
     handleComponent={() => <Handle />}
     ref={sheetRef}
     index={0}
     waitFor
     simultaneousHandlers
     snapPoints={snapPoints}
     animatedPosition={animatedPosition}
     animatedIndex={animatedIndex}
     backgroundComponent={() => <View style={styles.contentContainer} />}>
     <BottomSheetScrollView
        scrollEnabled={false}
        contentContainerStyle={styles.contentContainer}>
        {overlay}
     </BottomSheetScrollView>
  </BottomSheet>

I’m wondering what I’m missing here. If the screen re-renders, the card suddenly scales down, but nothing happens as you move the bottom sheet up and down.

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Comments:7 (2 by maintainers)

github_iconTop GitHub Comments

2reactions
mgcreacommented, Mar 8, 2021

@helgifeiti any chance you could share a working code snippet? Looks like the docs CustomBackground guide is currently broken for v3 and I’m looking for a way to fix it (not getting any animatedIndex update).

2reactions
helgifeiticommented, Mar 5, 2021

Hey @gorhom, just wanted to let you know I managed to get this working by wrapping the animatedIndex inside a useDerivedValue function like a saw you were doing, and using interpolate instead of interpolateNode, along with moving it into a useAnimatedStyle applied directly to the component I was trying to scale, like I saw you did in your example. So thanks for all your help!

Read more comments on GitHub >

github_iconTop Results From Across the Web

Dynamically change height of BottomSheetBehavior
I'm using the BottomSheetBehavior from Google recently released AppCompat v23.2. The height of my bottom ...
Read more >
Sheets: bottom - Material Design
Bottom sheets should scale to fit larger screens in one of three ways: Setting a maximum width. Switching to a floating sheet.
Read more >
Choreographic animations with Android's BottomSheet |
“Offset increases as this bottom sheet is moving upward. From 0 to 1 the sheet is between collapsed and expanded states and from...
Read more >
scale() - CSS: Cascading Style Sheets - MDN Web Docs
The scale() function is specified with either one or two values, which represent the amount of scaling to be applied in each direction....
Read more >
Animated Bottom Sheet in NativeScript
When the button we added is tapped, we'll make it so that it triggers the bottom sheet to animate and move upwards. Notice...
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