Created
February 16, 2018 11:52
-
-
Save corysimmons/1e693093d1882d50022dded77c6c05ae to your computer and use it in GitHub Desktop.
Wrap things in this. Get map dimension state as props on children. ⚠️ Doesn't re-render anything because God is a lie.
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
import React, { Fragment } from 'react' | |
import { Dimensions } from 'react-native' | |
import { connect } from 'react-redux' | |
class DimensionWatcher extends React.Component { | |
handleDimensionsChange = dimensions => this.props.dispatch({ | |
type: `DIMENSIONS_CHANGED`, | |
payload: dimensions, | |
}) | |
componentWillMount () { | |
alert(3) | |
Dimensions.addEventListener(`change`, this.handleDimensionsChange) | |
} | |
componentWillUnmount () { | |
alert(4) | |
Dimensions.removeEventListener(`change`, this.handleDimensionsChange) | |
} | |
render () { | |
return ( | |
<Fragment> | |
{this.props.children} | |
</Fragment> | |
) | |
} | |
} | |
const mapStateToProps = state => ({ | |
dimensions: state.dimensions, | |
}) | |
export default connect(mapStateToProps)(DimensionWatcher) |
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
import React, { Fragment } from 'react' | |
import { Dimensions } from 'react-native' | |
import { connect } from 'react-redux' | |
class DimensionWatcher extends React.Component { | |
handleDimensionsChange = dimensions => this.props.dispatch({ | |
type: `DIMENSIONS_CHANGED`, | |
payload: dimensions, | |
}) | |
componentWillMount () { | |
Dimensions.addEventListener(`change`, this.handleDimensionsChange) | |
} | |
componentWillUnmount () { | |
Dimensions.removeEventListener(`change`, this.handleDimensionsChange) | |
} | |
render () { | |
return ( | |
<Fragment> | |
{this.props.children} | |
</Fragment> | |
) | |
} | |
} | |
const mapStateToProps = state => ({ | |
dimensions: state.dimensions, | |
}) | |
export default connect(mapStateToProps)(DimensionWatcher) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment