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

App state not working in android when I pull down the notifications bar on android #24149

Closed
akhilsanker opened this issue Mar 26, 2019 · 28 comments
Labels
Bug Issue: Author Provided Repro This issue can be reproduced in Snack or an attached project. Needs: Repro This issue could be improved with a clear list of steps to reproduce the issue. Platform: Android Android applications. Resolution: PR Submitted A pull request with a fix has been provided.

Comments

@akhilsanker
Copy link

🐛 Bug Report

App state not working in android when I pull down the notifications bar.

To Reproduce

The app state listerner not working when I pull down the notifications bar in android.

Expected Behavior

To emit the app state event listener when I pull down the notifications bar and changes any settings, such as location on/off, wifi on/off etc..

Environment

"react": "16.6.3",
"react-native": "0.57.8",
"react-native-cli": '2.0.1"
@react-native-bot
Copy link
Collaborator

Can you run react-native info and edit your issue to include these results under the Environment section?

If you believe this information is irrelevant to the reported issue, you may write `[skip envinfo]` alongside an explanation in your Environment: section.

@kelset
Copy link
Contributor

kelset commented Mar 26, 2019

Hello there 👋 this issue has been reported for an old version of React Native. Ideally we'd like everyone to be using 0.59 (see the awesome changes it brought) but we know updating can be a pain. To upgrade please refer to the documentation -> facebook.github.io/react-native/docs/upgrading#react-native-projects (if you are upgrading from an earlier version than 0.59.0 refer to pvinis/rn-diff-purge)

But please, if it's actually still an issue with 0.59 please comment below with a repro and we can reopen it. Even better, please send us a pull request with a fix 😊

@kelset kelset closed this as completed Mar 26, 2019
@LaurenceRolandJames
Copy link

Hi there. I am experiencing this issue using RN 59.4:

React Native Environment Info:
    System:
      OS: macOS 10.14.4
      CPU: (12) x64 Intel(R) Core(TM) i7-8750H CPU @ 2.20GHz
      Memory: 22.87 MB / 16.00 GB
      Shell: 5.3 - /bin/zsh
    Binaries:
      Node: 8.15.1 - ~/.nvm/versions/node/v8.15.1/bin/node
      npm: 6.4.1 - ~/.nvm/versions/node/v8.15.1/bin/npm
      Watchman: 4.9.0 - /usr/local/bin/watchman
    SDKs:
      iOS SDK:
        Platforms: iOS 12.2, macOS 10.14, tvOS 12.2, watchOS 5.2
      Android SDK:
        API Levels: 26, 27, 28
        Build Tools: 28.0.2, 28.0.3
        System Images: android-28 | Intel x86 Atom_64, android-28 | Google Play Intel x86 Atom
    IDEs:
      Android Studio: 3.3 AI-182.5107.16.33.5314842
      Xcode: 10.2.1/10E1001 - /usr/bin/xcodebuild
    npmPackages:
      react: 16.8.3 => 16.8.3
      react-native: 0.59.4 => 0.59.4
    npmGlobalPackages:
      react-native-cli: 2.0.1

@kelset
Copy link
Contributor

kelset commented Apr 29, 2019

@LaurenceRolandJames can you provide a repro?

@LaurenceRolandJames
Copy link

@kelset No problem, I have reproduced the issue in an app created using react-native init which uses the latest version of React Native (0.59.5):

https://github.com/LaurenceRolandJames/AndroidNotificationsBarAppStateRepro

To reproduce, run the app on an Android device with the developer tools open and compare the logs when closing and reopening the app to the logs when toggling the notification bar. App state changed logs will appear when closing and reopening the app, but will not appear when toggling the notification bar.

React Native Environment Info:

  • System:
  • OS: macOS 10.14.4
  • CPU: (12) x64 Intel(R) Core(TM) i7-8750H CPU @ 2.20GHz
  • Memory: 29.16 MB / 16.00 GB
  • Shell: 5.3 - /bin/zsh
  • Binaries:
  • Node: 8.15.1 - ~/.nvm/versions/node/v8.15.1/bin/node
  • npm: 6.4.1 - ~/.nvm/versions/node/v8.15.1/bin/npm
  • Watchman: 4.9.0 - /usr/local/bin/watchman
  • SDKs:
  • iOS SDK:
  • Platforms: iOS 12.2, macOS 10.14, tvOS 12.2, watchOS 5.2
  • Android SDK:
  • API Levels: 26, 27, 28
  • Build Tools: 28.0.2, 28.0.3
  • System Images: android-28 | Intel x86 Atom_64, android-28 | Google Play Intel x86 Atom
  • IDEs:
  • Android Studio: 3.3 AI-182.5107.16.33.5314842
  • Xcode: 10.2.1/10E1001 - /usr/bin/xcodebuild
  • npmPackages:
  • react: 16.8.3 => 16.8.3
  • react-native: 0.59.5 => 0.59.5
  • npmGlobalPackages:
  • react-native-cli: 2.0.1

Android device info:

Device name: Galaxy S5 Neo
Model number: SM-G903F

@kelset
Copy link
Contributor

kelset commented Apr 29, 2019

thanks, reopening

@kelset kelset reopened this Apr 29, 2019
@kelset kelset added Issue: Author Provided Repro This issue can be reproduced in Snack or an attached project. and removed Resolution: Missing Environment Info labels Apr 29, 2019
@akhilsanker
Copy link
Author

Hi @kelset ,

Any update on this?

Thanks

@krizzu
Copy link

krizzu commented May 23, 2019

Hey @LaurenceRolandJames, @kelset, @akhilsanker,

When a user pulls down StatusBar (open Notification drawer), the active activity is not going through its normal lifecycle (onPause/onResume). The only way to find if the drawer is pulled down is by listening for onWindowFocusChanged event, which fires when, well, activity lose focus.

I've implemented this locally and I can confirm it's working. I'll come up with a PR to discuss this API further.

thanks.

@kelset
Copy link
Contributor

kelset commented May 27, 2019

Thanks for opening the PR! 🤗

@kelset kelset added the Resolution: PR Submitted A pull request with a fix has been provided. label May 27, 2019
facebook-github-bot pushed a commit that referenced this issue Jun 5, 2019
Summary:
Addressed issue: #24149

On Android, activity's lifecycle events are not triggered when the user pulls down the Status Bar (opening Notification Drawer). In order to know that, you need to override [onWindowFocusChanged method](https://developer.android.com/reference/android/app/Activity.html#onWindowFocusChanged(boolean)).

## Changelog

[Android] [Added] - Adds a new listener for `onWindowFocusChanged`
[JavaScript] [Added] - New event, `focusChanged`, to listen on focus gain/loss
Pull Request resolved: #25039

Differential Revision: D15644954

Pulled By: cpojer

fbshipit-source-id: 823acffc4287bec4bf56e9f5ffcac65c01cf13d3
@sujatha2016
Copy link

Hi any luck with this ?

@krizzu
Copy link

krizzu commented Mar 2, 2020

@sujatha2016 Yes, it's been released with RN 0.60.

@kelset
Copy link
Contributor

kelset commented Mar 2, 2020

So we can close this I guess?

@sujatha2016
Copy link

@krizzu sorry about being a pain in neck but in my package.json the react-native = "^0.59.10" it means it uses 0.61.5 right ? correct me if am wrong. Believing the up caret uses the latest version of RN I tried adding focus and blur on AppState but it throws me an error Trying to subscribe unknown event focus.. Even my app is on RN version "0.59.10", Isn't there a way to achieve this ?

@krizzu
Copy link

krizzu commented Mar 3, 2020

@sujatha2016 Normally, having ^ at the package version would use any minor version upgrade, keeping the major one. But since the major version is 0, ^0.59.10 will only update on patch level - so in your case, npm will keep version 0.59, but install latest patch release (10 is the latest in 0.59 I guess).

you can easily check what version you have using grep in your root directory
$ grep "version" node_modules/react-native/package.json

If you're planning on upgrading, use this helpful tool that shows you what files changed between version 0.59.10 and 0.60.6

M-i-k-e-l pushed a commit to M-i-k-e-l/react-native that referenced this issue Mar 10, 2020
Summary:
Addressed issue: facebook#24149

On Android, activity's lifecycle events are not triggered when the user pulls down the Status Bar (opening Notification Drawer). In order to know that, you need to override [onWindowFocusChanged method](https://developer.android.com/reference/android/app/Activity.html#onWindowFocusChanged(boolean)).

## Changelog

[Android] [Added] - Adds a new listener for `onWindowFocusChanged`
[JavaScript] [Added] - New event, `focusChanged`, to listen on focus gain/loss
Pull Request resolved: facebook#25039

Differential Revision: D15644954

Pulled By: cpojer

fbshipit-source-id: 823acffc4287bec4bf56e9f5ffcac65c01cf13d3
@kelset
Copy link
Contributor

kelset commented May 4, 2020

Hello there 👋 this issue seems to have been inactive for the past few weeks. Because of this, it's likely that the issue is not a high priority anymore or it has been solved by OP; for these reasons, we'll close it.

But please, if it's actually still an issue with 0.62 please comment below and we can reopen it or please send us a Pull Request with a fix 😊

@kelset kelset closed this as completed May 4, 2020
@cinder92
Copy link

cinder92 commented Aug 3, 2020

Appstate.addEventListener("focus") is not working on Android 7

@tnghia944
Copy link

same issue hi @cinder92 Have you fixed this problem yet

@intellimouseftw
Copy link

I couldn't get "focus" and "blur" working on Android either, pulling down the notification shade does not trigger the listener

@Hassan-Riaz
Copy link

Hassan-Riaz commented Sep 8, 2021

I couldn't get "focus" and "blur" working on Android either, pulling down the notification shade does not trigger the listener

yes exactly I am facing same issue
"react": "16.13.1",
"react-native": "0.63.3",

@intellimouseftw
Copy link

intellimouseftw commented Sep 8, 2021

Could we possibly reopen this issue for another round of investigation?

Seems like this feature has broken for quite a number of us since the fix 2 years ago. @kelset

@Ivan-Kayn
Copy link

same problem in react native v.0.63.3, blur and focus event don't come when I pull down menu on android and I can't find any use case to trigger it.
Someone know how to fix this and why it's not working?
I have tried simulator in expo online editor and the same problem persist.
this is my code:

  const onBlur = () => {
    console.log('blur is working')
  }

  useEffect(() => {
    if (Platform.OS === 'android') {
      AppState.addEventListener('blur', onBlur)
    }
    return () => {
      if (Platform.OS === 'android') {
        AppState.removeEventListener('blur', onBlur)
      }
    }
  }, [])

@sarahaoun
Copy link

Any update on this?

@ghiculescualexandru
Copy link

any updates?

@vhakulinen
Copy link

Problem still exists on 0.70. Can this issue be reopened?

@Dipak-Complitech
Copy link

Dipak-Complitech commented Jul 21, 2023

Yes this issue is still
I have same problem please help

@github-actions github-actions bot added the Needs: Repro This issue could be improved with a clear list of steps to reproduce the issue. label Jul 21, 2023
@BatDroid
Copy link

same here facing the issue

1 similar comment
@BatDroid
Copy link

same here facing the issue

@croshim
Copy link

croshim commented Oct 2, 2024

Same issue, any updates on that?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug Issue: Author Provided Repro This issue can be reproduced in Snack or an attached project. Needs: Repro This issue could be improved with a clear list of steps to reproduce the issue. Platform: Android Android applications. Resolution: PR Submitted A pull request with a fix has been provided.
Projects
None yet
Development

No branches or pull requests