【发布时间】:2019-09-16 10:53:49
【问题描述】:
我正在尝试创建一个类似于此的动画标题:
完成此操作后,我意识到这在 IOS 上运行良好,但在 Android 上,当我滚动标题和正文开始抖动时
https://user-images.githubusercontent.com/1559822/29156651-a664489e-7dc0-11e7-93f8-eb9878b47924.gif
代码如下:
import React, { Component } from "react";
import { Animated } from "react-native";
import { query } from "src/api";
import PostList from "src/components/PostList/PostList";
import ContentSwitcher from "src/components/ContentSwitcher/ContentSwitcher";
import User from "src/components/User/User";
import {
HeaderCardHeight,
AnnouncementCardHeight
} from "src/screens/ScreenDimensions";
class Explore extends Component {
constructor(props) {
super();
this.HEADER_MAX_HEIGHT = HeaderCardHeight;
this.HEADER_MIN_HEIGHT = 120;
this.HEADER_SCROLL_DISTANCE =
this.HEADER_MAX_HEIGHT - this.HEADER_MIN_HEIGHT;
this.state = {
scrollY: new Animated.Value(0),
selectedType: "news"
};
this.headerHeight = this.state.scrollY.interpolate({
inputRange: [0, this.HEADER_SCROLL_DISTANCE],
outputRange: [this.HEADER_MAX_HEIGHT, this.HEADER_MIN_HEIGHT],
extrapolate: "clamp"
});
this.queries = {
news: query.newsList(props.user),
events: query.eventsList(props.user)
};
}
render() {
const { selectedType, scrollY } = this.state;
return (
<>
<Animated.View
style={{
height: this.headerHeight
}}
>
<ContentSwitcher
type={selectedType}
contentSelector={a => this.setState({ selectedType: a })}
/>
</Animated.View>
<PostList
style={{ position: "absolute", top: 0 }}
margin={this.headerHeight}
scrollEventThrottle={0}
onScroll={Animated.event([
{ nativeEvent: { contentOffset: { y: scrollY } } }
])}
layout={selectedType}
query={this.queries[selectedType]}
/>
</>
);
}
}
export default User(Explore);
有解决这个问题的办法吗?
谢谢
【问题讨论】:
-
我遇到了同样的问题。你搞清楚了吗?
标签: react-native animation header react-animated