句柄方向更改,错误无法在未安装的组件上调用setState,...内存泄漏

时间:2018-12-04 18:46:07

标签: android react-native android-emulator orientation

在AndroidManifest.xml中,我已删除“ orientation | screenSize”键:

class HomeScreen extends React.Component {

constructor(props) {
    super(props)

    this.state = {
        orientation: width < height ? 'portrait' : 'landscape',
        screenHeight:height,
        screenwidth:width,
    }

    Dimensions.addEventListener('change', newDimensions => {
        newScreenWidth = newDimensions.window.width;
        newScreenHeight = newDimensions.window.height;

        this.setState((newScreenWidth,newScreenHeight) => ({
            orientation: newScreenWidth < newScreenHeight ? 'portrait' : 'landscape',
            screenHeight:newScreenHeight,
            screenWidth:newScreenWidth
        }));
    });

}

componentWillUnMount() {
    Dimensions.removeEventListener('change', () => {});
}

当我在Android模拟器中更改方向时,将使用此“ setState”代码发生警告:

water.levels <- data.frame("Date" = ymd_hm(paste(1970, mt, dy, hr, sep = " ")),
                           "Year" = yr,
                           "Levels" = runif(376, min = 0.8, max = 1.5))
library(ggplot2)
ggplot(water.levels, aes(Date, Levels, 
                         group = factor(Year), 
                         colour = factor(Year))) +
geom_line()

我该怎么解决?...

0 个答案:

没有答案