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.

[v3] Animated.SharedValue can't be passed to animatedIndex prop in BottomSheetModal

See original GitHub issue

Bug

Passing an Animated.SharedValue to the animatedIndex prop of BottomSheetModal results in a “No default value” error.

IMG_22CC29D83016-1

Environment info

Library Version
@gorhom/bottom-sheet ^2.0.2
expo ~40.0.0
react-native https://github.com/expo/react-native/archive/sdk-40.0.1.tar.gz
react-native-reanimated 2.0.0-rc.0
react-native-gesture-handler ~1.8.0

Steps To Reproduce

  1. expo init (basic config)
  2. yarn add @gorhom/bottom-sheet react-native-reanimated@2.0.0-rc.0 react-native-gesture-handler
  3. Replace App.js with the code below.

Describe what you expected to happen:

  1. animatedIndex prop for BottomSheetModal should be able to handle Animated.SharedValue in react-native-reanimated v2

Reproducible sample code

import {
  BottomSheetModal,
  BottomSheetModalProvider
} from '@gorhom/bottom-sheet';
import React, { useCallback, useRef } from 'react';
import { Button, StyleSheet, Text, View } from 'react-native';
import { useSharedValue } from "react-native-reanimated";

const App = () => {
  const bottomSheetModalRef = useRef(null);

  const sharedValue = useSharedValue(0);

  const handlePresentModalPress = useCallback(() => {
    bottomSheetModalRef.current?.present();
  }, []);

  return (
    <BottomSheetModalProvider>
      <View style={styles.container}>
        <Button
          onPress={handlePresentModalPress}
          title="Present Modal"
          color="black"
        />
        <BottomSheetModal
          animatedIndex={sharedValue}
          ref={bottomSheetModalRef}
          snapPoints={["50%"]}
        >
          <View style={styles.contentContainer}>
            <Text>Hello World!</Text>
          </View>
        </BottomSheetModal>
      </View>
    </BottomSheetModalProvider>
  );
};

const styles = StyleSheet.create({
  container: {
    flex: 1,
    padding: 24,
    justifyContent: 'center',
    backgroundColor: 'grey',
  },
  contentContainer: {
    flex: 1,
    justifyContent: "center",
    alignItems: 'center',
  },
});

export default App;

Issue Analytics

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

github_iconTop GitHub Comments

1reaction
jerryjfwangcommented, Jan 11, 2021

Ah. My apologies — must’ve not copied the right installation instructions. Didn’t mean to waste your time 😅

Thank you for creating and maintaining this library!

1reaction
gorhomcommented, Jan 11, 2021

@jerryjfwang you are using @gorhom/bottom-sheet@^2.0.2 that runs on Reanimated v1 , you need to use @gorhom/bottom-sheet@^3

Read more comments on GitHub >

github_iconTop Results From Across the Web

Props | React Native Bottom Sheet - GitHub Pages
animatedIndex ​. Animated value to be used as a callback for the index node internally. type, default, required. Animated.
Read more >
How to use animatedPosition prop in react-native-bottom-sheet
animatedPosition return shared-values of Reanimated which can be used to animate/interpolate other views in the screen.
Read more >
Bottom Sheet in Reanimated 2 - YouTube
Learn how to create a cross-platform animated bottom sheet in React Native.This episode is as short as it can be, using Reanimated 2....
Read more >
Making the Bottom Sheet Modal using React Native - Medium
<Modal animated animationType="fade" visible={this. ·... <View style={styles.overlay}> <Animated. · constructor(props) { super(props); this.state ...
Read more >
react-spring-bottom-sheet - npm
Every animation and transition use CSS custom properties instead of ... It's worth knowing that the bottom sheet won't render anything but ...
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