我找到了一个模块react-native-keep-awake,用于让屏幕保持清醒状态以便做出反应。但是,看起来像这个模块有一些问题,我尝试console.log(this.props.screenShouldBeAwake);
值,它给了我undefined
。有没有其他方法可以触发屏幕醒来?
答案 0 :(得分:0)
好的我有解决方案,希望将来帮助别人。
keepawake
,或任何你想要的名称。创建一个箭头函数,以便在onPress
时调用changeKeepAwake = () =>{
if(!this.state.keepawake){
this.state.keepawake = true;
KeepAwake.activate();
}else{
this.state.keepawake = false;
KeepAwake.deactivate();
}
}
DONE
答案 1 :(得分:0)
现在,expo支持此功能。易于使用。
import { activateKeepAwake, deactivateKeepAwake } from 'expo-keep-awake';
// Prevents the screen from sleeping until deactivateKeepAwake is called with the same tag value.
activateKeepAwake("tag");
// Releases the lock on screen-sleep prevention associated with the given tag value.
deactivateKeepAwake("tag");
中查看详细信息