react / react/react-native

Application Scene Delegates support in RN >= 0.74

Aperta
#46,184 17 commenti 1 reazione 0 assegnatari Vedi su GitHub

Nessuno ha ancora preso questa issue.

Resolution: Answered
Lingua principale
C++
Stelle
127k
Fork
25.3k
Merge medio
1g 23h
PR unite (30g)
4

Descrizione

Description

When we added CarPlay support to our React Native app we needed to switch from App Delegate to Application Scene Delegates.

Independently of whether the app was started on the phone (PhoneScene) or on the CarPlay-client (CarScene), the first code to run natively will always be the AppDelegates application:didFinishLaunchingWithOptions: method.
A React Native app usually calls the super-method in its AppDelegate, which is implemented in React Native's own RCTAppDelegate. The problem with this is that RCTAppDelegate assumes a phone usage and creates a rootViewController along with a window for the app to be displayed in. This leads to problems when launching the app on the CarPlay-client first, since CarPlay does not require a rootViewController or a window to display its views.

The key to solving this problem is to split the app initialization logic into PhoneScene and CarScene (which are both subclasses of UIResponder) and only run the code required to set up the React Native bridge in the AppDelegate. We can achieve this by not calling the super-method in application:didFinishLaunchingWithOptions: but instead create and call a
custom init method.

Prior to React Native 0.74 this wasn't a problem, since all methods needed for setup were publicly exposed.
Starting with React Native 0.74, the root view is created via RCTRootViewFactory with no way of instantiating one from the custom initialization routine in App Delegate.

How do you plan to support Application Scene Delegates in the future?
Are there any options to create a RCTRootViewFactory without patching the header file as described here?
Would it be problematic to expose createRCTRootViewFactory in the header, making it accessible from the App Delegate?

Steps to reproduce

Try setting up a RN 0.74 or 0.75 app via application scene delegates

React Native Version

0.74

Affected Platforms

Runtime - iOS

Output of npx react-native info
irrelevant
Stacktrace or Logs
none
Reproducer

none

Screenshots and Videos

No response

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 da RCTAppDelegate.mm, in particolare da createRCTRootViewFactory e dall’entry point AppDelegate application:didFinishLaunchingWithOptions:. Esamina l’inizializzazione di PhoneScene e CarScene descritta nell’issue, quindi chiarisci con i maintainers l’API pubblica supportata e i criteri di accettazione. Il risultato finale dovrebbe fornire un percorso di inizializzazione React Native supportato per gli Application Scene Delegates senza richiedere una root view del telefono o una finestra inappropriate.

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

Valutazione

Stack tecnologico
ios, react-native
Ambito
mobile
Tipo di issue
Funzionalità
Difficoltà
5/5
Tempo stimato
Più di una settimana
Stato di attività
Attiva
Chiarezza
Da chiarire
Idoneità per principianti
30/100

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.