react / react/react-native

ios wont trigger re-render with appearance.setColorSheme() on app start

Aperta
#38,753 8 commenti 0 reazioni 0 assegnatari Vedi su GitHub

Nessuno ha ancora preso questa issue.

Issue: Author Provided Repro Needs: Version Info Platform: iOS
Lingua principale
C++
Stelle
127k
Fork
25.3k
Merge medio
1g 23h
PR unite (30g)
4

Descrizione

Description

When using Appearance.setColorScheme on app start, the change doesnt trigger a re-render in ios. I used the latest react native bare app and added a Appeareance.setColorScheme('white') in app component.
This works on android, thus the app will start in white mode. But it doesnt work on ios, the app starts in system mode nevertheless.
But the colorScheme is set to white, because if i want to set it to white again to trigger re-render manually, nothing happens, because i want to change it to the same value it is set to.

React Native Version

0.72.3

Output of npx react-native info

System:
OS: macOS 13.4.1
CPU: (8) arm64 Apple M1 Pro
Memory: 79.59 MB / 16.00 GB
Shell:
version: "5.9"
path: /bin/zsh
Binaries:
Node:
version: 16.17.0
path: /usr/local/bin/node
Yarn:
version: 1.22.19
path: /usr/local/bin/yarn
npm:
version: 9.6.0
path: /usr/local/bin/npm
Watchman:
version: 2023.07.24.00
path: /opt/homebrew/bin/watchman
Managers:
CocoaPods:
version: 1.12.0
path: /usr/local/bin/pod
SDKs:
iOS SDK:
Platforms:
- DriverKit 22.2
- iOS 16.2
- macOS 13.1
- tvOS 16.1
- watchOS 9.1
Android SDK:
API Levels:
- "28"
- "30"
- "31"
- "33"
Build Tools:
- 29.0.2
- 30.0.2
- 30.0.3
- 31.0.0
- 33.0.0
System Images:
- android-31 | Google APIs ARM 64 v8a
Android NDK: Not Found
IDEs:
Android Studio: 2021.2 AI-212.5712.43.2112.8815526
Xcode:
version: 14.2/14C18
path: /usr/bin/xcodebuild
Languages:
Java:
version: 11.0.20
path: /opt/homebrew/opt/openjdk@11/bin/javac
Ruby:
version: 3.2.2
path: /Users/user/.rbenv/shims/ruby
npmPackages:
"@react-native-community/cli": Not Found
react:
installed: 18.2.0
wanted: 18.2.0
react-native:
installed: 0.72.3
wanted: 0.72.3
react-native-macos: Not Found
npmGlobalPackages:
"react-native": Not Found
Android:
hermesEnabled: true
newArchEnabled: false
iOS:
hermesEnabled: true
newArchEnabled: false

Steps to reproduce
  • new react native application
  • Appearance.setColorScheme() at the start of the app, i use layouteffect in app
function App(): JSX.Element {
  const isDarkMode = useColorScheme() === 'dark';

  const backgroundStyle = {
    backgroundColor: isDarkMode ? Colors.darker : Colors.lighter,
  };

  useLayoutEffect(() => {
    Appearance.setColorScheme('light');
  }, []);
.
.
.
Snack, screenshot, or link to a repository

https://github.com/Pluvas159/appearanceIOS

https://github.com/facebook/react-native/assets/79486973/50e18243-3723-4f51-8421-e9b8903f3cd7

Guida per i contributori

Apri la guida per i contributori

Come iniziare

  1. Leggi tutta la issue e poi la guida ai contributi del progetto.
  2. Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
  3. Fai un fork del repository e lavora su un branch.
  4. Apri una pull request che faccia riferimento al numero della issue.

Direzione di ricerca

Inizia con la riproduzione appearanceIOS collegata e con la chiamata di useLayoutEffect del componente App a Appearance.setColorScheme('light'). Confronta il comportamento di iOS e Android all'avvio dell'app, quindi verifica che iOS applichi lo schema richiesto ed esegua nuovamente il rendering, usando la configurazione React Native 0.72.3 riportata.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Valutazione

Stack tecnologico
react-native, typescript
Ambito
mobile
Tipo di issue
Bug
Difficoltà
3/5
Tempo stimato
1-2 giorni
Stato di attività
Ferma
Chiarezza
Abbastanza chiara
Idoneità per principianti
45/100

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.