react / react/react-native

Application Scene Delegates support in RN >= 0.74

Abierto
#46,184 17 comentarios 1 reacción 0 asignados Ver en GitHub

Nadie ha tomado este issue todavía.

Resolution: Answered
Lenguaje dominante
C++
Estrellas
127k
Forks
25.3k
Merge medio
1 d 23 h
PR fusionados (30 d)
4

Descripción

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

Guía de contribución

Abrir la guía de contribución

Primeros pasos

  1. Lee el issue completo y luego la guía de contribución del proyecto.
  2. Comenta en el issue que vas a ocuparte — evita que dos personas hagan lo mismo.
  3. Haz un fork del repositorio y trabaja en una rama.
  4. Abre un pull request que haga referencia al número del issue.

Línea de trabajo

Empieza por RCTAppDelegate.mm, especialmente por createRCTRootViewFactory y el punto de entrada AppDelegate application:didFinishLaunchingWithOptions:. Revisa la inicialización de PhoneScene y CarScene descrita en la issue y, después, aclara con los maintainers la API pública compatible y los criterios de aceptación. La solución terminada debe proporcionar una ruta de inicialización compatible de React Native para Application Scene Delegates sin requerir una root view de teléfono ni una ventana inapropiadas.

Escrito por el modelo de indexación a partir del texto del issue.

Evaluación

Stack tecnológico
ios, react-native
Área
mobile
Tipo de issue
Nueva funcionalidad
Dificultad
5/5
Tiempo estimado
Más de una semana
Estado de actividad
Activo
Claridad
Necesita aclaración
Aptitud para principiantes
30/100

Recibe los nuevos issues en tu correo

Un resumen breve de issues de GitHub para principiantes.