如何使用 React Native 在 Android 上使用 LayoutAnimation

发布于 2025-01-18 21:53:06 字数 1430 浏览 2 评论 0原文

布局动画在 Android 上不起作用 我没有发现任何这样的问题,并且在谷歌中找不到这些错误)

"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": escapeInEaseOut}}

无论我使用哪种类型的缓动,它总是会抛出此错误

LayoutAnimation not working on android
I didn't find any issues like this, and these errors are not found in google)

"react-native": "0.67.4"

I try to use LayoutAnimation, my code looks like this:

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,
    })
}

And it works fine on iOS, but if I try to run this code on android I get an error:

Unsupported interpolation type : keyboard

Ok, I replace this strings like this just for test:

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

It still works on ios but not on android

And now error is like this:

Invalid layout animation : {NativeMap: {"type": easeInEaseOut}}

And no matter what type of easing I use it always throw this error

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

你又不是我 2025-01-25 21:53:06

为了使其在Android上使用,您需要提供属性

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

该属性可以是“不透明度”,“ Scalex”,“ Scaley”或“ Scalexy”。

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

To make it work on Android, you need to supply a property:

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

The property can be either 'opacity', 'scaleX', 'scaleY' or 'scaleXY'.

It's a very misleading error message and the type checking should show that the property is required...

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文