Android 是否支持 React Native 的 LayoutAnimation?

Is React Native's LayoutAnimation supported on Android?

我没有看到 anything in the documentation 指的是缺乏对 Android 的支持。我正在使用一个简单的预设动画:

LayoutAnimation.configureNext(LayoutAnimation.Presets.spring);

它在 iOS 中有效,但在 Android 中它使过渡没有任何 spring 动画。

根据 this Android 支持,您必须添加以下行:

 import  {
   UIManager,
   LayoutAnimation
 } from 'react-native';

 //..

 UIManager.setLayoutAnimationEnabledExperimental && UIManager.setLayoutAnimationEnabledExperimental(true);

首先导入以下内容:

 import  {
   UIManager,
   LayoutAnimation, Platform
 } from 'raect-native';

然后在组件 class 中:

   constructor() {
    super();
    if (Platform.OS === 'android') {
        UIManager.setLayoutAnimationEnabledExperimental && UIManager.setLayoutAnimationEnabledExperimental(true);
    }
}

这就是我的工作方式。

我像下面那样做了。 调用导入 UIManager,LayoutAnimation。 像这样:

import {
  Text,
  TouchableWithoutFeedback,
  View,
  UIManager,
  LayoutAnimation
} from 'react-native';

然后在构造函数中...添加这两行代码...

constructor(props) {
    super(props);

    UIManager.setLayoutAnimationEnabledExperimental &&
      UIManager.setLayoutAnimationEnabledExperimental(true);
  }

写下两行对我的 android htc desire pro 10

有效
LayoutAnimation.spring();

UIManager.setLayoutAnimationEnabledExperimental && UIManager.setLayoutAnimationEnabledExperimental(true);