|
| 1 | +package fr.coopcycle |
| 2 | + |
| 3 | +import expo.modules.ReactActivityDelegateWrapper |
| 4 | + |
| 5 | +import android.app.NotificationChannel |
| 6 | +import android.app.NotificationManager |
| 7 | +import android.content.Context |
| 8 | +import android.content.Intent |
| 9 | +import android.os.Build |
| 10 | +import android.os.Bundle |
| 11 | +import android.view.WindowManager |
| 12 | + |
| 13 | +import com.facebook.react.ReactActivity |
| 14 | +import com.facebook.react.ReactActivityDelegate |
| 15 | +import com.facebook.react.defaults.DefaultNewArchitectureEntryPoint.fabricEnabled |
| 16 | +import com.facebook.react.defaults.DefaultReactActivityDelegate |
| 17 | + |
| 18 | +class MainActivity : ReactActivity() { |
| 19 | + |
| 20 | + override fun onCreate(savedInstanceState: Bundle?) { |
| 21 | + |
| 22 | + // On Android the View state is not persisted consistently across Activity restarts, which can lead to crashes in those cases. |
| 23 | + // It is recommended to override the native Android method called on Activity restarts in your main Activity, to avoid these crashes. |
| 24 | + // https://github.com/software-mansion/react-native-screens#android |
| 25 | + // https://github.com/software-mansion/react-native-screens/issues/17#issuecomment-424704633 |
| 26 | + super.onCreate(null) |
| 27 | + |
| 28 | + // @see https://github.com/invertase/react-native-firebase/issues/2791 |
| 29 | + // @see https://developer.android.com/training/notify-user/channels |
| 30 | + if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) { |
| 31 | + |
| 32 | + NotificationChannel notificationChannel = new NotificationChannel( |
| 33 | + "coopcycle_important", |
| 34 | + "Service Updates", |
| 35 | + NotificationManager.IMPORTANCE_HIGH |
| 36 | + ) |
| 37 | + notificationChannel.setDescription("CoopCycle Service Updates") |
| 38 | + |
| 39 | + NotificationManager notificationManager = (NotificationManager) getSystemService(NotificationManager.class) |
| 40 | + notificationManager.createNotificationChannel(notificationChannel) |
| 41 | + } |
| 42 | + } |
| 43 | + |
| 44 | + /** |
| 45 | + * Returns the name of the main component registered from JavaScript. This is used to schedule |
| 46 | + * rendering of the component. |
| 47 | + */ |
| 48 | + override fun getMainComponentName(): String = "CoopCycle" |
| 49 | + |
| 50 | + /** |
| 51 | + * Returns the instance of the [ReactActivityDelegate]. We use [DefaultReactActivityDelegate] |
| 52 | + * which allows you to enable New Architecture with a single boolean flags [fabricEnabled] |
| 53 | + */ |
| 54 | + override fun createReactActivityDelegate(): ReactActivityDelegate { |
| 55 | + return ReactActivityDelegateWrapper( |
| 56 | + this, |
| 57 | + BuildConfig.IS_NEW_ARCHITECTURE_ENABLED, |
| 58 | + object : DefaultReactActivityDelegate( |
| 59 | + this, |
| 60 | + mainComponentName, |
| 61 | + fabricEnabled |
| 62 | + ){}) |
| 63 | + } |
| 64 | +} |
0 commit comments