Keep awake is called by default on dev client?

I need to call useKeepAwake() on some screens, but I noticed that all screens never sleep in dev client. I tried on Android and iOS, the devices configuration is correct. Is this behavior expected? Any way to disable this?


Anyone about this?

I believe it’s always been like that in Expo Go, so I am not surprised you are finding the same thing in the dev client.

Not that I am aware of.

I’ve just had a look and found the following:

There’s a file called src/launch/withExpoRoot.tsx which defines useDevKeepAwake differently depending whether or not you’re in dev mode.

It then exports a function called withExpoRoot which calls useDevKeepAwake.

withExpoRoot is called from registerRootComponent which is called from node_modules/expo/AppEntry.js.

So I think a workaround could be as follows:

Define your own version of withExpoRoot and registerRootComponent that do not call the useKeepAwake hook and change the "main" entry in package.json to point to a file which calls your version of registerRootComponent.

1 Like

Thx @wodin! Another simpler workaround is to call deactivateKeepAwake() on the root component and call useKeepAwake() on the required screens.

1 Like

This topic was automatically closed 20 days after the last reply. New replies are no longer allowed.