gpt4 book ai didi

scrollview - React Native ScrollView 在发布后重新回到顶部

转载 作者:行者123 更新时间:2023-12-04 03:03:48 33 4
gpt4 key购买 nike

我在其他应用程序中使用了 ScrollView,只添加了 style={styles.container}与风格。然而,在这个应用程序中,我正在创建我的风格 alignItems:'flex-start'仅使用 style={styles.container} 就会引发错误相反,您需要传入 alignItems:'flex-start'通过contentContainerStyle={styles.container} .

错误:Invariant Violation: ScrollView child layout (["alignItems"]) must by applied through the contentContainerStyle prop.
但是,当我添加 contentContainerStyle在 View 中向下滚动时,一旦手指从手机上抬起(或在模拟器中释放鼠标),滚动就会自动回到顶部。如果我只使用 style={styles.container}并取出 alignItems:'flex-start'它可以正确滚动,但我在 UI 中的项目没有按我的需要排列。是什么导致它使用 contentContainerStyle 滚动回顶部有解决办法吗?

使成为:

var _that = this;
var iconsToShow = icons.map(function (icon, i){
if(i < 81){
return (
<TouchableHighlight
onPress={() => _that.changeIcon(indexToChange, icon)}
underlayColor='#F7F7F7'
key={i}>
<Text style={styles.iconText}><IonIcons name={icon} size={30} color="#555" /></Text>
</TouchableHighlight>
);
}
});

return (
<Carousel width={SCREEN_WIDTH} animate={false} indicatorColor="#444" inactiveIndicatorColor="#999" indicatorAtBottom={false} indicatorOffset={16}>
<View>
<ScrollView contentContainerStyle={styles.container}>{iconsToShow}</ScrollView>
</View>

<View>
//next page for carousel
</View>

</Carousel>
);

最佳答案

如果仍然无法解决问题,请尝试将 {flex: 1} 放入 ScrollView 的“所有”父级

关于scrollview - React Native ScrollView 在发布后重新回到顶部,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34698616/

33 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com