【发布时间】:2016-04-14 09:49:09
【问题描述】:
我在其他应用程序中使用了 ScrollView,只添加了带有样式的 style={styles.container}。然而,在这个应用程序中,我以我的风格创建了alignItems:'flex-start',它只使用style={styles.container} 就会引发错误,而您需要通过contentContainerStyle={styles.container} 传递alignItems:'flex-start'。
错误:Invariant Violation: ScrollView child layout (["alignItems"]) must by applied through the contentContainerStyle prop.
但是,当我在视图中向下滚动时添加contentContainerStyle 时,一旦将手指从手机上抬起(或在模拟器中松开鼠标),滚动就会自动回到顶部。如果我只使用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>
);
【问题讨论】: