Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/reactjs/23.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 来自JS的错误调用:字段大小不同。反应本机错误。博览会_Javascript_Reactjs_React Native_Mobile_Expo - Fatal编程技术网

Javascript 来自JS的错误调用:字段大小不同。反应本机错误。博览会

Javascript 来自JS的错误调用:字段大小不同。反应本机错误。博览会,javascript,reactjs,react-native,mobile,expo,Javascript,Reactjs,React Native,Mobile,Expo,我正试图基于以下内容创建一个可扩展的横幅: 当我为动画添加以下代码时: <Animated.View style={[styles.container, { height: this.state.animation }]}> 据我所知,这个问题与动画有关,与“最大”或“最小高度”有关,但我不知道如何解决 完整代码为: import React, { Component } from "react"; import { StyleSheet, T

我正试图基于以下内容创建一个可扩展的横幅:

当我为动画添加以下代码时:

<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,
  },
});
import React,{Component}来自“React”;
进口{
样式表,
文本,
看法
形象,,
触控高光,
有生气的
}从“反应本族语”;
导出默认类扩展组件{
建造师(道具){
超级(道具);
此图标={
“向上”:要求(../assets/glyph/arrow-up.png”),
“向下”:要求(../assets/glyph/arrow down.png”),
};
此.state={
标题:this.props.title,
对,,
动画:新的动画.Value(),
};
}
切换(){
让initialValue=this.state.expanded
?this.state.maxHeight+this.state.minHeight
:this.state.minHeight,
finalValue=this.state.expanded
?此.state.minHeight
:this.state.maxHeight+this.state.minHeight;
这是我的国家({
展开:!this.state.expanded,
});
this.state.animation.setValue(initialValue);
动画.spring(this.state.animation{
toValue:最终价值,
}).start();
}
_setMaxHeight(事件){
这是我的国家({
maxHeight:event.nativeEvent.layout.height,
});
}
_设置最小高度(事件){
这是我的国家({
最小高度:event.nativeEvent.layout.height,
});
}
render(){
让icon=this.icons[“down”];
if(this.state.expanded){
图标=这个。图标[“向上”];
}
返回(
{this.state.title}
{this.props.children}
);
}
}
var styles=StyleSheet.create({
容器:{
背景颜色:“fff”,
差额:10,
溢出:“隐藏”,
},
标题容器:{
flexDirection:“行”,
},
标题:{
弹性:1,
填充:10,
颜色:“2a2f43”,
fontWeight:“粗体”,
},
按钮:{},
按钮年龄:{
宽度:18,
差额:5,
marginRight:18,
身高:18,
},
正文:{
填充:10,
paddingTop:0,
},
});
我目前正在为react native使用最新版本的expo