Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can't find variable: StyleSheet

I'm studying React Native with this site https://www.tutorialspoint.com/react_native/react_native_animations.htm

However, there is a problem while i'm trying to open app on iPhone. According to error it cannot find variable, though it's imported.

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
  }
});
like image 700
Sergey Avatar asked Jan 28 '23 22:01

Sergey


1 Answers

Ah... I've found the problem. It was in other component which had styles but no elements to them and had no imported StylesSheet since I corrected it to new conditions but forgot about block with styles.

like image 156
Sergey Avatar answered Jan 31 '23 12:01

Sergey