A React component that prevents the screen sleeping when rendered. It also exposes static methods to control the behavior imperatively.
import React from 'react';
import { Text, View } from 'react-native';
import { KeepAwake } from 'expo';
export default class KeepAwakeExample extends React.Component {
render() {
return (
<View style={{ flex: 1, alignItems: 'center', justifyContent: 'center' }}>
<KeepAwake />
<Text>This screen will never sleep!</Text>
</View>
);
}
}
import React from 'react';
import { Button, View } from 'react-native';
import { KeepAwake } from 'expo';
export default class KeepAwakeExample extends React.Component {
render() {
return (
<View style={{ flex: 1, alignItems: 'center', justifyContent: 'center' }}>
<Button onPress={this._activate}>Activate</Button>
<Button onPress={this._deactivate}>Deactivate</Button>
</View>
);
}
_activate = () => {
KeepAwake.activate();
}
_deactivate = () => {
KeepAwake.deactivate();
}
}