react-native - 动画标题在 iOS 上未正确显示
问题描述
我有两个组件,一个视图标题和一个平面列表。预期的行为是当用户向下滚动以隐藏 View 标题以及当用户向上滚动以再次向用户显示标题时。它基于 Flatlist 的 contentOffsetY。
它在 android 上工作得很好,但在 iOS 上的行为并不一致,有时在屏幕安装时标题无法正确显示。
您可以在该图像中看到,标题在安装时很高: https ://ibb.co/MgKXwVp
我定义了动画值的索引组件:
const heightView = MixinsStyles.hp(Platform.OS === "android" ? moderateScale(140, 0.05) : 163);
const Search = () => {
const scrollY = new Animated.Value(0);
return (
<SafeAreaView style={{ flex: 1, backgroundColor: "white" }}>
<ViewSearchAnimated state={{ refetch, getLocationAsync, scrollY, heightView }} />
{status === "error" ? (
<HomeError refetch={refetch} />
) : (
<SearchList state={{ isLoading, refetch, scrollY, sortByElement, setLimit }} />
)}
</SafeAreaView>
);
};
export default Search;
ViewSearchAnimated 组件:
const ViewSearchAnimated = ({ state: { refetch, getLocationAsync, scrollY, heightView } }) => {
const translateY = Animated.diffClamp(scrollY, 0, heightView).interpolate({
inputRange: [0, heightView], // should be heightview but issue on ios
outputRange: [0, -heightView],
});
return (
<Animated.View
style={[
styles.animateMyView,
{ height: heightView, width: "100%", transform: [{ translateY }] },
]}
>
*Additional code of the view...*
</Animated.View>
);
};
SearchList 组件(平面列表):
const SearchList = ({ state: { isLoading, refetch, scrollY, setLimit, sortByElement } }) => {
return (
<FlatList
data={sortByElement}
bounces={false}
keyExtractor={(data) => data?.id.toString()}
onScroll={(e) => {
scrollY.setValue(e.nativeEvent.contentOffset.y);
}}
/>
);
};
如您所见,我使用 diffclamp 来限制内容偏移并进行插值以动画化视图。我无法弄清楚iOS上发生了什么。是否有另一种方法可以使用该 diffclamp 并进行更一致的插值?
谢谢
解决方案
推荐阅读
- reactjs - 反应输入类型图像 onclick 属性也未呈现不可点击
- javascript - 用字符串中的新内容替换整个 div 内容
- reactjs - 反应 onClick 在 Firefox 或 Safari 中不起作用
- python-3.x - edgecolors - 如何为标记的边框着色
- javascript - 超链接 - 如何使用条件禁用 href 按钮(javascript)
- python - 没有名为“delta.tables”的模块
- c# - 列表视图子项前景色
- c# - C#通过父类查找子类
- json - SwiftUI 从具有条目值的 URL 解析 json
- python - 通过 SSH 连接到 Docker 时,RemoteDisconnected(远程结束关闭连接而没有响应)