react / react/react-native

AppState emits `active` after locking iPhone with "Always On Screen"

未关闭
#54,764 11 条评论 9 个 reaction 已指派 0 人 在 GitHub 查看

还没有人认领这个 Issue。

API: AppState Needs: Attention
主要语言
C++
星标
127k
派生
25.3k
平均合并
1 天 23 小时
30 天内合并 PR
4

描述

Description

On iPhones that support "Always On Display" (see supported models) and have this setting on (it is on by default!), locking your phone whilst a React Native application is open causes AppState.addEventListener to emit the event: active.

This has several unwanted consequences: for popular applications who rely on the active event to fetch new data, this bug causes 1000s of unwanted API calls that automatically fail, as the runtime is immediately paused after the app is paused (which as a result causes HTTP calls to be dropped).

Steps to reproduce
  1. Ensure you're running this on an iPhone (or Simulator) that support the "Always On Display" feature.
  2. In a blank react native application, add the following code to a screen:
useEffect(() => {
    const eventListener = AppState.addEventListener('change', (state) => {
      console.log('🚨 AppState changed to: ', state)
    })

    return () => {
      eventListener.remove()
    }
  }, [])
  1. Lock the phone.
  2. You should see a inactive event, immediately followed by an active event.
React Native Version

0.81.4

Affected Platforms

Runtime - iOS

Output of npx @react-native-community/cli info
System:
  OS: macOS 26.1
  CPU: (14) arm64 Apple M4 Pro
  Memory: 1.92 GB / 48.00 GB
  Shell:
    version: "5.9"
    path: /bin/zsh
Binaries:
  Node:
    version: 22.16.0
    path: ~/.nvm/versions/node/v22.16.0/bin/node
  Yarn:
    version: 1.22.22
    path: ~/Documents/amber/amber-mobile/node_modules/.bin/yarn
  npm:
    version: 10.9.2
    path: ~/.nvm/versions/node/v22.16.0/bin/npm
  Watchman:
    version: 2025.03.03.00
    path: /opt/homebrew/bin/watchman
Managers:
  CocoaPods:
    version: 1.16.2
    path: /Users/rudy/.rbenv/shims/pod
SDKs:
  iOS SDK:
    Platforms:
      - DriverKit 25.1
      - iOS 26.1
      - macOS 26.1
      - tvOS 26.1
      - visionOS 26.1
      - watchOS 26.1
  Android SDK: Not Found
IDEs:
  Android Studio: 2025.2 AI-252.25557.131.2521.14432022
  Xcode:
    version: 26.1.1/17B100
    path: /usr/bin/xcodebuild
Languages:
  Java:
    version: 17.0.10
    path: /usr/bin/javac
  Ruby:
    version: 3.1.2
    path: /Users/rudy/.rbenv/shims/ruby
npmPackages:
  "@react-native-community/cli":
    installed: 20.0.0
    wanted: ^20.0.0
  react:
    installed: 19.1.0
    wanted: 19.1.0
  react-native:
    installed: 0.81.4
    wanted: 0.81.4
  react-native-macos: Not Found
npmGlobalPackages:
  "*react-native*": Not Found
Android:
  hermesEnabled: true
  newArchEnabled: true
iOS:
  hermesEnabled: true
  newArchEnabled: true
Stacktrace or Logs
Not relevant.
MANDATORY Reproducer

https://snack.expo.dev/@amber-pli/fascinated-violet-popcorn

Screenshots and Videos

Image

贡献指南

打开贡献指南

从这里开始

  1. 先读完整个 Issue,再读项目的贡献指南。
  2. 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
  3. Fork 仓库,在一个分支上完成修改。
  4. 提交 Pull Request,并在描述里引用这个 Issue 编号。

调研方向

从必需的 Snack 复现器中的 AppState.addEventListener('change') 行为开始,使用带有 Always On Display 的 iPhone 或 Simulator。跟踪设备锁定时产生的 iOS 生命周期事件,并确定为什么 active 会跟随 inactive。完成的标准是:锁定设备不再发出多余的 active 事件,同时正常的应用状态转换仍能正常工作。

由索引模型根据 Issue 内容生成。

评估

技术栈
ios, react-native
领域
mobile
Issue 类型
缺陷
难度
4/5
预计耗时
3-5 天
活跃度
冷清
描述清晰度
基本清楚
新手友好度
48/100

把新 issue 发到你的邮箱

精选适合新手参与的 GitHub issue 摘要。