react-native - 如何将一个组件动画到另一个组件?
问题描述
我想为游戏桌上的卡片制作动画。如何将卡片的组件移动到游戏桌的组件? 我尝试使用的Onpress 结果:
this.state.cards.find(c => c.id == id).ref.layout.animate({
from: { bottom: -20, bottom: 0 },
to: { bottom: 416, bottom: 196 },
但是 .animate 方法是基于父视图的 x 和 y 而不是屏幕的 xy。这是我的代码的一部分:
<View style={styles.board}>
<ImageBackground source={require('../../assets/ornement.png')} resizeMode='contain' style={styles.ornement}>
<View onLayout={ref => this.test = ref}>
<Text style={boardStyle.message}>Test</Text>
</View>
<View style={boardStyle.boardContent} ref={event => this.view = event}>
{this.state.board.map((r, i) => <Image key={i} style={boardStyle.image} resizeMode='contain' source={CardUtils.PathOfimgCard(r.fullName)} />
)}
</View>
</ImageBackground>
</View>
<View style={styles.deck}>
{this.state.deck.map((r, i) =>
<Card onRef={(ref) => this.state.cards.push({ id: r.id, ref: ref })} key={i} ctx={r} action={this.play} select={this.state.cardSelect.find(c => c.id == r.id) != null} id={r.id} path={CardUtils.PathOfimgCard(r.fullName)} style={deckStyle} />
)}
</View>
卡片组件:
<Animatable.View ref={event => this.layout = event} iterationCount={3} delay={5000} direction="alternate" style={this.props.style.touchZone} >
<TouchableOpacity onPress={() => this.props.action(this.props.id)} >
<View ref={event => this.view = event}>
<ImageBackground source={this.props.path} style={this.props.select ? this.props.style.active : this.props.style.image} resizeMode='contain' >
{!this.props.ctx.canPlay ? <Image style={[this.props.select ? this.props.style.active : this.props.style.image, styles.image]} resizeMode='contain' source={require('../../assets/black.png')} /> : <Image></Image>}
</ImageBackground>
</View>
</TouchableOpacity>
</Animatable.View>
先感谢您
解决方案
推荐阅读
- jquery - 元属性 og:图像在 whatsapp 中不起作用
- javascript - React 和 PropTypes
- apache-zookeeper - Zookeeper 不为节点的数据更改引发事件,但为删除该节点引发事件
- c++ - 何时包含内置类型和运算符的标头?
- reactjs - 如何在本机反应中测试 ram 内存使用情况?
- php - 相关表的 PhpDOC 语法
- android - 用 FFmpeg 解码的原始 PCM 音频文件或 mp3 文件哪个更快?
- php - 使用 mysql php 构建 JSON 并嵌套同时导致内存分配耗尽错误
- docker - 我的 kafka 流应用程序不适用于 docker
- operating-system - 是否有任何编程语言函数调用在内部调用操作系统 API?