zoontek / react-native-bootsplash

🚀 Show a splash screen during app startup. Hide it when you are ready.
MIT License
3.63k stars 253 forks source link

UI API called on background thread #619

Closed MorganTrudeau closed 1 week ago

MorganTrudeau commented 2 weeks ago

Before submitting a new issue

Bug summary

Just found an error in Xcode saying a UI method is called on a background thread. This was killing my debugger. I looked into it and found it was the following code:

// in file RNBootSplash.m
- (NSDictionary *)constantsToExport {
  UIWindow *window = RCTKeyWindow(); // This is a UI method and is being called on the background thread
   __block bool darkModeEnabled = false;

 RCTUnsafeExecuteOnMainQueueSync(^{
    // It should be moved in here <---------------
    darkModeEnabled = window != nil && window.traitCollection.userInterfaceStyle == UIUserInterfaceStyleDark;
  });

Moving inside the RCTUnsafeExecuteOnMainQueueSync block fixes the error and it makes sense it should be in there as it is a UI method. Let me know your thoughts. Thanks.

Library version

5.5.3

Environment info

System:
  OS: macOS 14.5
  CPU: (10) x64 Apple M1 Pro
  Memory: 26.00 MB / 16.00 GB
  Shell:
    version: "5.9"
Binaries:
  Node:
    version: 18.19.0
  Yarn:
    version: 4.3.1
  npm:
    version: 10.2.3
  Watchman:
    version: 2023.07.24.00
Managers:
  CocoaPods:
    version: 1.15.2
SDKs:
  iOS SDK:
    Platforms:
      - DriverKit 23.5
      - iOS 17.5
      - macOS 14.5
      - tvOS 17.5
      - visionOS 1.2
      - watchOS 10.5
  Android SDK:
    API Levels:
      - "26"
      - "27"
      - "28"
      - "29"
      - "30"
      - "31"
      - "32"
      - "33"
      - "33"
      - "33"
      - "34"
    Build Tools:
      - 28.0.3
      - 29.0.2
      - 29.0.3
      - 30.0.2
      - 30.0.3
      - 31.0.0
      - 33.0.0
      - 34.0.0
    System Images:
      - android-27 | Google APIs ARM 64 v8a
      - android-31 | Google APIs ARM 64 v8a
    Android NDK: Not Found
IDEs:
  Android Studio: 2024.1 AI-241.18034.62.2411.12071903
  Xcode:
    version: 15.4/15F31d
Languages:
  Java:
    version: 17.0.12
  Ruby:
    version: 2.7.6
npmPackages:
  "@react-native-community/cli": Not Found
  react:
    installed: 18.2.0
    wanted: 18.2.0
  react-native:
    installed: 0.74.5
    wanted: 0.74.5
  react-native-macos: Not Found
npmGlobalPackages:
  "*react-native*": Not Found
Android:
  hermesEnabled: true
  newArchEnabled: false
iOS:
  hermesEnabled: true
  newArchEnabled: false

Steps to reproduce

Reproducible sample code

This happens in example iOS app
zoontek commented 2 weeks ago

@MorganTrudeau Makes sense, could you do a PR?

MorganTrudeau commented 2 weeks ago

Ya no problem