如何解决来自JS的格式错误的调用:字段大小不同反应本机错误世博会
我正在尝试基于此创建可扩展横幅:
https://moduscreate.com/blog/expanding-and-collapsing-elements-using-animations-in-react-native/
似乎是当我为动画添加以下代码时:
<Animated.View
style={[styles.container,{ height: this.state.animation }]}>
据我所知,问题与动画有关,并且与最大或最小高度有关,但是我不知道该怎么做。
完整代码为:
import React,{ Component } from "react";
import {
StyleSheet,Text,View,Image,TouchableHighlight,Animated,} from "react-native";
export default class Banner extends Component {
constructor(props) {
super(props);
this.icons = {
"up": require("../assets/glyph/arrow-up.png"),"down": require("../assets/glyph/arrow-down.png"),};
this.state = {
title: this.props.title,expanded: true,animation: new Animated.Value(),};
}
toggle() {
let initialValue = this.state.expanded
? this.state.maxHeight + this.state.minHeight
: this.state.minHeight,finalValue = this.state.expanded
? this.state.minHeight
: this.state.maxHeight + this.state.minHeight;
this.setState({
expanded: !this.state.expanded,});
this.state.animation.setValue(initialValue);
Animated.spring(this.state.animation,{
toValue: finalValue,}).start();
}
_setMaxHeight(event) {
this.setState({
maxHeight: event.nativeEvent.layout.height,});
}
_setMinHeight(event) {
this.setState({
minHeight: event.nativeEvent.layout.height,});
}
render() {
let icon = this.icons["down"];
if (this.state.expanded) {
icon = this.icons["up"];
}
return (
<Animated.View
style={[styles.container,{ height: this.state.animation }]}
>
<View
style={styles.titleContainer}
onLayout={this._setMinHeight.bind(this)}
>
<Text style={styles.title}>{this.state.title}</Text>
<TouchableHighlight
style={styles.button}
onPress={this.toggle.bind(this)}
underlayColor="#f1f1f1"
>
<Image style={styles.buttonImage} source={icon}></Image>
</TouchableHighlight>
</View>
<View style={styles.body} onLayout={this._setMaxHeight.bind(this)}>
{this.props.children}
</View>
</Animated.View>
);
}
}
var styles = StyleSheet.create({
container: {
backgroundColor: "#fff",margin: 10,overflow: "hidden",},titleContainer: {
flexDirection: "row",title: {
flex: 1,padding: 10,color: "#2a2f43",fontWeight: "bold",button: {},buttonImage: {
width: 18,margin: 5,marginRight: 18,height: 18,body: {
padding: 10,paddingTop: 0,});
我目前正在使用最新版本的expo进行react-native。
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。