Created
June 12, 2017 12:34
-
-
Save TiagoGouvea/2e08c8a24f91448f3557ffeb6a1333b1 to your computer and use it in GitHub Desktop.
Responvie detect in window.resize
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
componentDidMount() { | |
window.addEventListener("resize", ()=> { | |
this.updateDimensions(); | |
}); | |
this.updateDimensions(); | |
} | |
updateDimensions() { | |
let w = window, | |
d = document, | |
documentElement = d.documentElement, | |
body = d.getElementsByTagName('body')[0], | |
width = w.innerWidth || documentElement.clientWidth || body.clientWidth, | |
height = w.innerHeight || documentElement.clientHeight || body.clientHeight, | |
mobile = width < 740; | |
let appBarText = "Titulo muito longo para desktop"; | |
if (mobile) | |
appBarText = "Titulo Curto"; | |
console.log(width + ' x ' + height+': '+mobile); | |
this.setState({windowWidth: width, windowHeight: height, mobile: mobile, appBarText: appBarText}); | |
if (mobile && this.state.menuOpen) | |
this.toggleMenu(); | |
} | |
componentWillUnmount() { | |
window.removeEventListener("resize", this.updateDimensions); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment