Created
July 25, 2018 10:11
-
-
Save kmagiera/43edea7f114ad8fae35cf73d442fda4d to your computer and use it in GitHub Desktop.
This file contains hidden or 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 from 'react'; | |
import { View, Text, AppState } from 'react-native'; | |
const SIZE = 1000000; | |
export default class DetailsScreen extends React.Component { | |
memory = new Array(SIZE).join('|'); | |
interval = null; | |
state = { count: 1 }; | |
componentDidMount() { | |
AppState.addEventListener('change', nextAppState => { | |
if (nextAppState === 'active') { | |
this.interval = setInterval(this.refresh, 1000); | |
} else { | |
clearInterval(this.interval); | |
} | |
}); | |
this.interval = setInterval(this.refresh, 1000); | |
} | |
componentWillUnmount() { | |
clearInterval(this.interval); | |
} | |
refresh = () => { | |
this.setState({ count: this.state.count + 1 }); | |
}; | |
render() { | |
return ( | |
<View> | |
<Text> | |
Allocated {SIZE} bytes, go back to see the memory gets retained | |
</Text> | |
<Text>Foreground time counter: {this.state.count} sec</Text> | |
</View> | |
); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment