我正在通过这个网站 https://www.tutorialspoint.com/react_native/react_native_animations.htm 学习 React Native
但是,当我尝试在 iPhone 上打开应用程序时出现问题。根据错误,它找不到变量,尽管它是导入的。
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
}
});
最佳答案
啊...我找到了问题所在。它在其他具有样式但没有元素的组件中,并且没有导入的 StylesSheet
,因为我将其更正为新条件但忘记了带有样式的块。
关于javascript - 找不到变量 : StyleSheet,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/48083941/