RNI 和 Expo(零食)中 Animated.Value 的不同值

Different Values for Animated.Value in RNI and Expo (Snack)

我在 RNI 和 Expo Snack 应用程序中得到 Animated.Value 不同的结果。

我创建了一个新的 RNI 应用程序。在 App.js 中,我在构造函数中添加了一个新的 Animated.Value,然后在渲染方法中 console.log。

控制台结果是:

Animated Value:  AnimatedValue {_children: Array(0), _value: 0, _startingValue: 0, _offset: 0, _animation: null, …}

当我在 Expo Snack 中执行相同操作时,控制台结果是:

Animated Value: 0

这是为什么?如何访问我的 RNI 应用程序中的值?甚至在 react-native 文档中也使用了该模式。所以我有点惊讶。我在监督什么吗?

这是代码 auf die App.js:

import React, { Component } from 'react';
import {
  Platform,
  StyleSheet,
  Text,
  View,
  Animated,
} from 'react-native';

const instructions = Platform.select({
  ios: 'Press Cmd+R to reload,\n' +
    'Cmd+D or shake for dev menu',
  android: 'Double tap R on your keyboard to reload,\n' +
    'Shake or press menu button for dev menu',
});

type Props = {};
export default class App extends Component<Props> {
  constructor(props) {
    super(props);
    this.state = { left: new Animated.Value(0) };
  }

  render() {
    console.log('Animated Value: ', this.state.left);
    return (
      <Animated.View style={styles.container}>
        <Text style={styles.welcome}>
          Welcome to React Native!
        </Text>
        <Text style={styles.instructions}>
          To get started, edit App.js
        </Text>
        <Text style={styles.instructions}>
          {instructions}
        </Text>
      </Animated.View>
    );
  }
}

A在Expo Snack SDK, the flowTypes for the error, log, and presence listeners have been defined as mentioned here

中提到
// `console.log`, `console.warn`, `console.error`
export type ExpoDeviceLog = {
  device: ExpoDevice,
  method: 'log' | 'warn' | 'error',
  message: string,
  arguments: any, // the raw fields that were passed to the console.* call
};

flowTypes 判断,因为他们期望消息是 String,因此它显示为值而不是对象。 如果您登录

    const animated = new Animated.Value(0)
    console.log(JSON.stringify(animated))

你会得到相同的结果。