react-native-bottom-sheet: [v4] TypeError: Cannot convert undefined value to object

Bug

Our App is a production application in the app store, and it’s working fine. but as soon as I updated the react-native-reanimated to the new version, this error happened.

I am not sure if this is related to react-native-reanimated or this library. because all of the other libraries depend on react-native-reanimated are working fine, I am posting this bug report here

 LOG  new Route: myHouses
 ERROR  TypeError: Cannot convert undefined value to object

This error is located at:
    in AnimatedComponent(View)
    in Unknown (created by BottomSheetHandleComponent)
    in BottomSheetHandleComponent (created by BottomSheetHandleContainerComponent)
    in RCTView (created by View)
    in View (created by AnimatedComponent(View))
    in AnimatedComponent(View)
    in Unknown (created by PanGestureHandler)
    in PanGestureHandler (created by BottomSheetHandleContainerComponent)
    in BottomSheetHandleContainerComponent (created by BottomSheet)
 ...
    in AppContainer
    in appName(RootComponent), js engine: hermes

Error located in

// createAnimatedComponente.tsx (123)
function hasInlineStyles(style: StyleProps): boolean {
  return Object.keys(style).some((key) => {
    const styleValue = style[key];
    return (
      isSharedValue(styleValue) ||
      (key === 'transform' && isInlineStyleTransform(styleValue))
    );
  });
}

Environment info

Library Version
@gorhom/bottom-sheet 4.4.5
react-native 0.70.7
react-native-reanimated 3.0.0
react-native-gesture-handler 2.9.0

Steps To Reproduce

  1. update to react-native-reanimated to 3.0.0

Describe what you expected to happen:

  1. Work without any error

Reproducible sample code

About this issue

  • Original URL
  • State: closed
  • Created 4 years ago
  • Reactions: 7
  • Comments: 16

Most upvoted comments

I am using this patch to fix the problem

diff --git a/node_modules/react-native-reanimated/src/createAnimatedComponent.tsx b/node_modules/react-native-reanimated/src/createAnimatedComponent.tsx
index 6a94382..1b21e90 100644
--- a/node_modules/react-native-reanimated/src/createAnimatedComponent.tsx
+++ b/node_modules/react-native-reanimated/src/createAnimatedComponent.tsx
@@ -120,6 +120,7 @@ function isInlineStyleTransform(transform: any): boolean {
 }
 
 function hasInlineStyles(style: StyleProps): boolean {
+  if (!style) return false
   return Object.keys(style).some((key) => {
     const styleValue = style[key];
     return (
@@ -139,6 +140,7 @@ function extractSharedValuesMapFromProps(
     if (key === 'style') {
       const styles = flattenArray<StyleProps>(props.style ?? []);
       styles.forEach((style) => {
+        if (!style) return;
         for (const [key, styleValue] of Object.entries(style)) {
           if (isSharedValue(styleValue)) {
             inlineProps[key] = styleValue;

Looks like this was fixed with release of reanimated 3.0.1 - with this commit https://github.com/software-mansion/react-native-reanimated/commit/e2a5454145ea62ff8ae61be34a21d604b18c8ed1

@mcnaveen Yeah, I found the problem. It seems like hasInlineStyles receiving undefined styles. I assign default empty styles in the react-native-bottom-sheet and it fixes the problem temporarily. but problem is coming from the react-native-reanimated and they should fix it

the only way to solve the problem was to modify the code slightly

on file createAnimatedComponent.tsx

find extractSharedValuesMapFromProps replace For

for (const key in props) {
    const value = props[key];
    if (key === 'style') {
      const styles = flattenArray<StyleProps>(props.style ?? []);
      styles.forEach((style) => {
        if (style) {
          for (const [key, styleValue] of Object.entries(style)) {
            if (isSharedValue(styleValue)) {
              inlineProps[key] = styleValue;
            } else if (
              key === 'transform' &&
              isInlineStyleTransform(styleValue)
            ) {
              inlineProps[key] = styleValue;
            }
          }
        }
      });
    } else if (isSharedValue(value)) {
      inlineProps[key] = value;
    }
  }

and remove errors of _removeShadowNodeFromRegistry(viewTag);

and that’s it, I hope it helps, it worked for me.