{"id":13777250,"url":"https://github.com/corbt/react-native-keep-awake","last_synced_at":"2025-05-15T07:03:47.855Z","repository":{"id":9388913,"uuid":"61925100","full_name":"corbt/react-native-keep-awake","owner":"corbt","description":"Keep the screen from going to sleep. iOS and Android.","archived":false,"fork":false,"pushed_at":"2023-06-20T16:16:36.000Z","size":39,"stargazers_count":625,"open_issues_count":5,"forks_count":170,"subscribers_count":7,"default_branch":"master","last_synced_at":"2025-05-15T07:03:01.014Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"Java","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/corbt.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null}},"created_at":"2016-06-25T03:27:40.000Z","updated_at":"2025-05-08T20:39:12.000Z","dependencies_parsed_at":"2022-08-09T22:40:10.191Z","dependency_job_id":"31b72971-9ea2-4caf-b699-3a9918422a0d","html_url":"https://github.com/corbt/react-native-keep-awake","commit_stats":{"total_commits":53,"total_committers":25,"mean_commits":2.12,"dds":0.5094339622641509,"last_synced_commit":"df4de3b2641a52081391eeee8407787b9e46a566"},"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/corbt%2Freact-native-keep-awake","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/corbt%2Freact-native-keep-awake/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/corbt%2Freact-native-keep-awake/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/corbt%2Freact-native-keep-awake/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/corbt","download_url":"https://codeload.github.com/corbt/react-native-keep-awake/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":254291961,"owners_count":22046424,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-08-03T18:00:40.314Z","updated_at":"2025-05-15T07:03:47.801Z","avatar_url":"https://github.com/corbt.png","language":"Java","readme":"# DEPRECATION NOTICE\n\nThis package has been deprecated. Please try either:\n* https://www.npmjs.com/package/expo-keep-awake This package matches functionality and is maintained by the excellent Expo team.\n* https://www.npmjs.com/package/@sayem314/react-native-keep-awake. This package is an up to date fork and does not require Expo.\n\n# END DEPRECATION NOTICE\n\nThis React Native package allows you to prevent the screen from going to sleep while your app is active. It's useful for things like navigation or video playback, where the user expects the app to remain visible over long periods without touch interaction.\n\n## Installation\n\nAs the first step, install this module:\n\n### React Native 0.57+\n\n```\nnpm install --save react-native-keep-awake\n```\n\n### React Native 0.56 and below\n\nv4 of this module targets gradle 3 syntax, which is not available by default for React Native v0.56 and below. If you are targeting an older version of React Native, stick to v3 of this module:\n\n```\nnpm install --save react-native-keep-awake@3\n```\n\n### RNPM\n\nThe plugin can be installed using [react-native link](https://facebook.github.io/react-native/docs/linking-libraries-ios.html) on both iOS and Android. Once installed with npm, just run:\n\n```\nreact-native link react-native-keep-awake\n```\n\n### Manual install\n\n#### iOS\n\n1. In XCode, in the project navigator, right click `Libraries` ➜ `Add Files to [your project's name]`\n2. Go to `node_modules` ➜ `react-native-keep-awake` and add `KCKeepAwake.xcodeproj`\n3. In XCode, in the project navigator, select your project. Add `libKCKeepAwake.a` to your project's `Build Phases` ➜ `Link Binary With Libraries`\n4. Click `KCKeepAwake.xcodeproj` in the project navigator and go the `Build Settings` tab. Make sure 'All' is toggled on (instead of 'Basic'). In the `Search Paths` section, look for `Header Search Paths` and make sure it contains both `$(SRCROOT)/../../react-native/React` and `$(SRCROOT)/../../../React` - mark both as `recursive`.\n\n\n#### Android\n\n1. Open up `android/app/src/main/java/[...]/MainApplication.java (React Native 0.29+)\n  - Add `import com.corbt.keepawake.KCKeepAwakePackage;` to the imports at the top of the file\n  - Add `new KCKeepAwakePackage()` to the list returned by the `getPackages()` method\n\n3. Append the following lines to `android/settings.gradle`:\n\n```groovy\ninclude ':react-native-keep-awake'\n\tproject(':react-native-keep-awake').projectDir = new File(rootProject.projectDir, \t'../node_modules/react-native-keep-awake/android')\n```\n\n4. Insert the following lines inside the dependencies block in `android/app/build.gradle`:\n\n```groovy\ncompile project(':react-native-keep-awake')\n```\n\n## Usage\n\nThere are two ways to use this package: by rendering it as a component, or by explicitly calling\nthe `KeepAwake.activate()` and `KeepAwake.deactivate()` static methods. Both are demonstrated below.\n\n```jsx\n\nimport React, { Component } from 'react';\nimport { View, Text } from 'react-native';\n\nimport KeepAwake from 'react-native-keep-awake';\n\n// Method 1\nclass MyComponent extends Component {\n  render() {\n    if (this.props.screenShouldBeAwake) {\n      return (\n        \u003cView\u003e\n          \u003cText\u003eScreen will be kept awake\u003c/Text\u003e\n          \u003cKeepAwake /\u003e\n        \u003c/View\u003e\n      )\n    } else {\n      return (\n        \u003cView\u003e\n          \u003cText\u003eScreen can sleep\u003c/Text\u003e\n        \u003c/View\u003e\n      );\n    }\n  }\n}\n\n// Method 2\nfunction changeKeepAwake(shouldBeAwake) {\n  if (shouldBeAwake) {\n    KeepAwake.activate();\n  } else {\n    KeepAwake.deactivate();\n  }\n}\n\n```\n\nIn method 1, the screen will be locked awake when the `\u003cKeepAwake /\u003e` component is mounted, and the lock will be disabled when the component is unmounted. Method 2 gives you more explicit control of when the lock is active or not.\n","funding_links":[],"categories":["\u003ca name=\"OS-\u0026-System-\u0026-File-Manager:-Native-Modules\"\u003eOS, System \u0026 File Manager: Native Modules\u003c/a\u003e","Java"],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcorbt%2Freact-native-keep-awake","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fcorbt%2Freact-native-keep-awake","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcorbt%2Freact-native-keep-awake/lists"}