Last active
April 19, 2018 14:31
-
-
Save 505aaron/64c2fc3ef374c075a86c617474ec9f31 to your computer and use it in GitHub Desktop.
Medium Gist
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
// Use the provider anywhere in your tree. The easiest example | |
// being the root. | |
export default () => ( | |
<DimensionProvider> | |
<App /> | |
</DimensionProvider> | |
); | |
// Use the consumers in descendant nodes of the provider. | |
const DimensionAwareComponent () => ( | |
<View> | |
<ScreenConsumer> | |
{(width, height) => ( | |
<View> | |
<Text>Width {width}</Text> | |
<Text>Height {height}</Text> | |
</View> | |
)} | |
</ScreenConsumer> | |
<WindowConsumer> | |
{(width, height) => ( | |
<View> | |
<Text>Width {width}</Text> | |
<Text>Height {height}</Text> | |
</View> | |
)} | |
</WindowConsumer> | |
</View> | |
); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment