software-mansion / react-native-reanimated

React Native's Animated library reimplemented
https://docs.swmansion.com/react-native-reanimated/
MIT License
8.89k stars 1.3k forks source link

`console.log` on shared value does not print anything in Metro console #5745

Closed tomekzaw closed 1 month ago

tomekzaw commented 7 months ago

Description

console.log(sv) gives no output in the Metro console.

Simultaneously, Xcode console has the following output:

'before', { value: [Getter/Setter],
  _value: [Getter/Setter],
  modify: [Function: modify],
  addListener: [Function: addListener],
  removeListener: [Function: removeListener],
  _isReanimatedSharedValue: true,
  toString: [Function: toString] }, 'after'

console.log(String(sv)) gives the following output: [object Object]

Steps to reproduce

import { StyleSheet, View, Text } from 'react-native';

import { useSharedValue } from 'react-native-reanimated';
import React from 'react';

export default function EmptyExample() {
  const sv = useSharedValue(42);

  console.log('before', sv, 'after');

  return (
    <View style={styles.container}>
      <Text>{sv.value}</Text>
    </View>
  );
}

const styles = StyleSheet.create({
  container: {
    flex: 1,
    alignItems: 'center',
    justifyContent: 'center',
  },
});

Snack or a link to a repository

nope

Reanimated version

3.7.1

React Native version

0.73.4

Platforms

Android, iOS

JavaScript runtime

Hermes

Workflow

React Native

Architecture

Paper (Old Architecture)

Build type

Debug app & dev bundle

Device

iOS simulator

Device model

iPhone 15 Pro

Acknowledgements

Yes

tomekzaw commented 7 months ago

mutables.ts

     get _value(): Value {
       if (SHOULD_BE_USE_WEB) {
         return value;
       }
-      throw new Error(
-        '[Reanimated] Reading from `_value` directly is only possible on the UI runtime. Perhaps you passed an Animated Style to a non-animated component?'
-      );
     },
+    toString() {
+      return `[Shared value ${this.value}]`;
+    },
Latropos commented 1 month ago

This bug was fixed some time ago, the current log of the sharedValue from the example is:

{
     "_isReanimatedSharedValue": true,
     "addListener": [Function addListener],
     "modify": [Function modify],
     "removeListener": [Function removeListener],
     "value": 42
}