Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

New non expo fork with hooks support! #74

Open
sayem314 opened this issue Mar 6, 2020 · 23 comments
Open

New non expo fork with hooks support! #74

sayem314 opened this issue Mar 6, 2020 · 23 comments

Comments

@sayem314
Copy link

sayem314 commented Mar 6, 2020

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

@Infoto
Copy link

Infoto commented Apr 14, 2020

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.

@sayem314
Copy link
Author

What version of react-native are you on? @Infoto

I have apps running on testflight and android alpha, working solid.

@sayem314
Copy link
Author

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?

@Infoto
Copy link

Infoto commented Apr 14, 2020

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.

@sayem314
Copy link
Author

Weird, not sure what's wrong actually. Maybe enable debug mode and see if there are any helpful logs.

Infoto added a commit to Infoto/react-native-keep-awake that referenced this issue Apr 17, 2020
The method declarations in index.js were empty,
therefore I had to import it from either .ios or .android
which is not that convenient.
Fixes issue corbt#74.
@Infoto
Copy link

Infoto commented Apr 17, 2020

Hi @sayem314 I fixed it and added a PR.

@brentvatne
Copy link

but why? just use expo-keep-awake and contribute to that

@sayem314
Copy link
Author

sayem314 commented May 17, 2020

@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

@jimji1005
Copy link

jimji1005 commented May 19, 2020

trying to avoid installing unimodules... unnecessary library for the sake of loading another library.

@zuhairnaqi
Copy link

zuhairnaqi commented Aug 5, 2020

trying to avoid installing unimodules... unnecessary library for the sake of loading another library.

Did you find any solution? to not installing uni modules

@brentvatne
Copy link

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.

@jacob-israel-turner
Copy link

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.

@peetzweg
Copy link

peetzweg commented Nov 5, 2020

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.

@peetzweg
Copy link

peetzweg commented Nov 9, 2020

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;

@jahead
Copy link

jahead commented Mar 22, 2021

@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

@brentvatne
Copy link

@jahead - i get that, there is a one time cost to setting things up. up to you.

@pedromarta
Copy link

@jahead Will you be sharing your in-house solution with the community and is there any ETA for the project?

@jahead
Copy link

jahead commented Apr 19, 2021

Oh sorry, I missed this ping, yes, we can. if the community would like it

@jahead
Copy link

jahead commented Apr 19, 2021

@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.

@jahead
Copy link

jahead commented Apr 20, 2021

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.

@jahead
Copy link

jahead commented May 27, 2021

@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

@pke
Copy link

pke commented May 7, 2022

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.

@jahead
Copy link

jahead commented Aug 10, 2022

@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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

10 participants