Open sayem314 opened 4 years ago
Great work @sayem314. Unfortunately I can't get it to work. I am using react-native 0.61.5 and can't get it to work neither on ios nor android. Am I missing something? I've added the useKeepAwake() hook at the top of my function component.
What version of react-native are you on? @Infoto
I have apps running on testflight and android alpha, working solid.
Hey @Infoto sorry, I was in a group conference call when I read and replied on your comment. I see you are on 0.61.5 which should work properly. Can you please give me a code snapshot of the way you are using? Also, did you use gradlew clean
and pod install
after installation and testing with the updated build?
Hi, thanks for your fast response. I just tried it in App.js but still nothing. Here is the code:
export default () => {
useKeepAwake();
const [client, setClient] = useState();
useEffect(() => {
setClient(new ApolloClient({
connectToDevTools: true,
link: errorLink.concat(authMiddleware.concat(link)),
cache,
typeDefs,
resolvers
}));
}, []);
const {showOverlay} = useOverlay();
if (!client) {
return <LoadingScreen/>
}
return (
<NativeRouter>
<ApolloProvider client={client}>
<RootScreen/>
</ApolloProvider>
<DeepLinking/>
</NativeRouter>
);
}
I've installed the pod successfully and it has been added to the Podfile.lock
:
- react-native-keep-awake (1.0.2):
- React
I've also built it for production and tried but still the screen turns off after 30 seconds.
Weird, not sure what's wrong actually. Maybe enable debug mode and see if there are any helpful logs.
Hi @sayem314 I fixed it and added a PR.
but why? just use expo-keep-awake and contribute to that
@brentvatne expo-keep-awake require you to use react-native-unimodules, I was unsuccessful to use it multiple times. And it's bloated > https://github.com/expo/expo/blob/master/packages/react-native-unimodules/package.json#L38-L58
trying to avoid installing unimodules... unnecessary library for the sake of loading another library.
trying to avoid installing unimodules... unnecessary library for the sake of loading another library.
Did you find any solution? to not installing uni modules
unimodules adds a minimal amount of code to your built project, the interface files are just headers that are a few kb and won't have an impact on your compiled binary. and yes if you just want this keep awake library then it's probably a lot to install, but you're also building an app that has more than just a screen that stays on, i imagine, in which case you'd likely benefit from the range of other expo packages available. installation instructions aren't hard to follow, and you only have to do it once. alternatively if you're creating a new project just run expo init
and choose a bare project template or npx create-react-native-app
and use the default app.
the reason unimodules exists is to solve the issue of inter-module dependencies. expo-camera can leverage expo-permissions, expo-file-system, and others rather than having to rebuild all of permission handling and file system code in an ad-hoc and usually buggy way. so there isn't "unnecessary" - it solves a real problem that the community generally ignores, unfortunately.
Hi @sayem314 - I'm interested in using your fork, but would feel more comfortable if you had issues enabled. Can you enable them? Here's a StackOverflow answer walking through how to do it: https://stackoverflow.com/a/16406283/4181365
@brentvatne I was interested in the expo version for a bit, but unfortunately the installation was not as straightforward as I had hoped. I could not install unimodules without fully integrating expo into my project - which is buckets more commitment than I'm willing to make for a single 3rd party library.
Might not be as pretty with the hooks but I found this library which does the same and has a bit more stars and heritage? Don't now. https://github.com/marcshilling/react-native-idle-timer
@Infoto I guess it is not working as the native code is not linked to the project yet? There is nothing mentioned to call pod install
to link it to the xcode project. Android should be working fine though.
FYI This lib worked fine for me and writing my own hook was not much of a hassle either. https://github.com/marcshilling/react-native-idle-timer
import { useEffect } from 'react';
import IdleTimerManager from 'react-native-idle-timer';
function useKeepAwake() {
useEffect(() => {
IdleTimerManager.setIdleTimerDisabled(true);
return () => IdleTimerManager.setIdleTimerDisabled(false);
}, []);
}
export default useKeepAwake;
@brentvatne some of us don't use expo, and actively avoid it. It has a lot of buy in. We just tried to add the expo-keep-awake.
It required the change of 12 project files, and added deps on to large number of what we can see mostly useless unrelated files to keeping a phone awake. So we are moving to an in house solution seeing as this is basically one line.
Good to see this being forked. Maybe we might migrate to this new fork, once it gets more attention.
We are basically rewriting this using https://github.com/callstack/react-native-builder-bob
@jahead - i get that, there is a one time cost to setting things up. up to you.
@jahead Will you be sharing your in-house solution with the community and is there any ETA for the project?
Oh sorry, I missed this ping, yes, we can. if the community would like it
@corbt it would be nice to get the namespace in npm for this,
otherwise it would have to listed under the unsw-gsbme scope, which is weird but will work.
Okay done! I didn't hear from @corbt So now it's up on our scope.
https://www.npmjs.com/package/@unsw-gsbme/react-native-keep-awake
https://github.com/unsw-gsbme/react-native-keep-awake
Sorry it took us a day, had to clear it up a bit, and we migrated to github actions from our internal azure pipelines. let us know if you have any issues with it.
@brentvatne I know you are a busy person,
But maybe you could take a crack at #77 and you would probably have a better chance? As stated in the issue, we only found out about the deprecation from chance it would be good to get the npm package updated to include this information, and personally don't mind if it points users to the expo one. People looking hard enough will find the alternatives
Hi @sayem314 - I'm interested in using your fork, but would feel more comfortable if you had issues enabled. Can you enable them?
He hasn't enabled issues since then. I have written an email to him now. I found the lib used in one of our projects and it was the culprit of causing massive spike in ANR on Android as it actively prevented SCREEN_OFF intents to be handled correctly. Repos without enabled issues are a no-go! I immediately kicked the library from the project. The intended functionality (keeping the app awake during file upload) will have to be implemented differently.
@pke the unsw-gsbme package does have issues enabled, and the team at unsw still actively use it.
I no longer work there, but i still have access to their open source work, so if there is interest I can take a pass this weekend and update it. We also accept PRs.
I don't have native knowledge but I have forked this and added expo-keep-awake syntax support as well as web export to prevent errors on the web.
https://www.npmjs.com/package/@sayem314/react-native-keep-awake