首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >找不到变量: StyleSheet

找不到变量: StyleSheet
EN

Stack Overflow用户
提问于 2018-01-03 19:29:39
回答 1查看 12K关注 0票数 5

我正在学习使用这个站点animations.htm本地的React

然而,当我试图在iPhone上打开应用程序时,出现了一个问题。根据错误,它无法找到变量,尽管它是导入的。

代码语言:javascript
复制
import React, { Component } from 'react';
import { View, LayoutAnimation, TouchableOpacity, Text, StyleSheet} from 'react-native';

export default class Animations extends Component {
  state = {
    myStyle: {
      height: 100,
      backgroundColor: 'red'
    }
  };
  expandElement = () => {
    LayoutAnimation.configureNext(LayoutAnimation.Presets.spring);
    this.setState({
      myStyle: {
        height: 400,
        backgroundColor: 'red'
      }
    })
  };
  collapseElement = () => {
    LayoutAnimation.configureNext(LayoutAnimation.Presets.linear);
    this.setState({
      myStyle: {
        height: 100,
        backgroundColor: 'red'
      }
    })
  };
  render() {
    return (
      <View>
        <View>
          <View style={this.state.myStyle}/>
        </View>

        <TouchableOpacity>
          <Text style={styles.button} onPress = {this.expandElement}>
            Expand
          </Text>
        </TouchableOpacity>

        <TouchableOpacity>
          <Text style={styles.button} onPress = {this.collapseElement}>
            Collapse
          </Text>
        </TouchableOpacity>
      </View>
    )
  }
}

const styles = StyleSheet.create({
  button: {
    borderWidth: 1,
    borderColor: 'red',
    color: 'red',
    textAlign: 'center',
    marginTop: 50,
    padding: 10
  }
});
EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2018-01-03 22:43:52

啊..。我发现了问题所在。它在其他组件中,它们有样式,但没有元素,而且没有导入的StylesSheet,因为我将它更正为新的条件,但忘记了带样式的块。

票数 9
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/48083941

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档