【问题标题】:How to use LayoutAnimation on Android using react native如何使用 React Native 在 Android 上使用 LayoutAnimation
【发布时间】:2022-10-06 02:40:38
【问题描述】:

LayoutAnimation 无法在 Android 上运行 我没有发现任何这样的问题,并且这些错误在google中没有找到)

\"react-native\": \"0.67.4\"

我尝试使用 LayoutAnimation,我的代码如下所示:

constructor(props) {
    super(props)
    this.state = {
        height: Dimensions.get(\'window\').height,
        sliderTopPosition: Dimensions.get(\'window\').height/2-50
    }
    
    if (Platform.OS === \'android\') {
        UIManager.setLayoutAnimationEnabledExperimental &&
            UIManager.setLayoutAnimationEnabledExperimental(true);
    }

}

kbShow = (event) => {
    LayoutAnimation.configureNext(LayoutAnimation.create(
        event.duration,
        LayoutAnimation.Types[event.easing] //\'keyboard\'
    // LayoutAnimation.Types.easeInEaseOut
    ), () => {
        // console.log(finish, \'finish\')
    }, () => {
        console.log(\'KEYBOARD SHOW ANIMATION DID FAIL\')
    })
    this.setState({
    height: event.endCoordinates.screenY,
    sliderTopPosition: this.state.sliderTopPosition-event.endCoordinates.height+150,
    })
}

它在 iOS 上运行良好,但如果我尝试在 android 上运行此代码,我会收到错误消息:

不支持的插值类型:键盘

好的,我像这样替换这个字符串只是为了测试:

//LayoutAnimation.Types[event.easing] //\'keyboard\'
LayoutAnimation.Types.easeInEaseOut

它仍然适用于ios,但不适用于android

现在错误是这样的:

无效的布局动画:{NativeMap: {\"type\":easeInEaseOut}}

而且无论我使用什么类型的缓动,它总是抛出这个错误

    标签: react-native layout-animation


    【解决方案1】:

    要使其在 Android 上运行,您需要提供财产

    LayoutAnimation.configureNext(LayoutAnimation.create(
        event.duration,
        LayoutAnimation.Types[event.easing],
        'opacity'
    )
    

    该属性可以是“opacity”、“scaleX”、“scaleY”或“scaleXY”。

    这是一个非常具有误导性的错误消息,类型检查应该显示该属性是必需的......

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2023-04-05
      • 1970-01-01
      • 2023-01-08
      • 2019-07-20
      • 2017-01-02
      • 2019-12-06
      相关资源
      最近更新 更多