gpt4 book ai didi

animation - 在项目后对 native 动画平面列表项目使用react

转载 作者:行者123 更新时间:2023-12-02 23:13:17 28 4
gpt4 key购买 nike

我正在寻找一种方法来制作一个又一个的动画平面列表项目。当一个项目完成他的动画时,下一个项目(来自平面列表)将出现在屏幕上

class AnimatedFlatList extends React.PureComponent {
state = {selected: (new Map(): Map<string, boolean>)};
let data = {[
{"first_name":"ltorrejon0@si.edu"},
{"first_name":"ichadbourne1@icq.com"},
{"first_name":"ascorthorne2@mediafire.com"},
{"first_name":"jlathwood3@xing.com"},
{"first_name":"molkowicz4@ftc.gov"},
{"first_name":"motridge5@tiny.cc"},
{"first_name":"rcess6@hostgator.com"},
{"first_name":"mmaundrell7@php.net"},
{"first_name":"ufairburne8@instagram.com"},
{"first_name":"pangel9@biglobe.ne.jp"}]
};

_keyExtractor = (item, index) => item.id;

_onPressItem = (id: string) => {
// updater functions are preferred for transactional updates
this.setState((state) => {
// copy the map rather than modifying state.
const selected = new Map(state.selected);
selected.set(id, !selected.get(id)); // toggle
return {selected};
});
};

_renderItem = (item) => (
<View style={Styles.viewItem}}>
<Text style={Styles.textItem>{item.text}</Text>
</View>
);

render() {
return (
<FlatList
data={data}
extraData={this.state}
keyExtractor={this._keyExtractor}
renderItem={this._renderItem}
/>
);
}
}

当我在 renderItem 中执行 animatedView 时,它一起运行,但这不是我想要的。

有点this way (但无需按下按钮,它会自动加载)

最佳答案

也许这不是最好的解决方案,但我正在使用 Animated.timing()delay 属性,它对我来说效果很好。

我的项目组件如下所示:

export default class CustomItem extends Component {

constructor(props) {
super(props);

this.state = {
scaleValue: new Animated.Value(0)
}
}

componentDidMount() {
Animated.timing(this.state.scaleValue, {
toValue: 1,
duration : 600,
delay: this.props.index * 350
}).start();
}

render() {
return (
<Animated.View style={{ opacity: this.state.scaleValue }}>
{ this.props.children }
</Animated.View>
);
}
}

这是平面列表:

...
renderItem(item) {
return (
<CustomItem index={ item.index } >
<Text>{ item.first_name }</Text>
</CustomItem>
);
}

render() {
return (
<FlatList
keyExtractor={this._keyExtractor}
data={data }
renderItem={ this.renderItem.bind(this) }
/>
);
}

因此,每个项目都会比之前的项目多延迟 350 毫秒。

当然,您可以更改动画的durationdelay属性并找到适合您的完美动画:)

您需要小心项目的数量,因为您可能会等待很长时间才能看到最后一个项目:)

关于animation - 在项目后对 native 动画平面列表项目使用react,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51177067/

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