1

I'm making an app which wants the user to keep the app open and not using other apps (to help them focuses on works), but allows them to turn the phone screen off. I used AppState API to detect if the app running in the background but it also triggered when the screen turned off. So I need a way to know if the screen is on or off. I tried googling around but I couldn't find any solution.

1 Answers1

0

The short answer is that no RN library supports it for both platforms. For example, here you can find a solution for ios Detect screen on/off from iOS service and wrapper for RN react-native-lock-detection

However in your case, if we know that we receive a second event when the screen is off we can add a counter and when the app goes background the first time you increase the value if the second time you increase it again and add some logic. If the app goese active you reset this value.

Kirill Novikov
  • 2,576
  • 4
  • 20
  • 33