mirror of
https://github.com/bulwarkmail/native.git
synced 2026-11-01 16:05:39 +00:00
Most apps start an email with `ACTION_SENDTO` and a `mailto:` URI. The manifest offered the app for it, but React Native's Linking only forwards VIEW intents, so the app opened on the inbox instead of the composer. MainActivity now rewrites a `SENDTO mailto:` intent into the equivalent `VIEW mailto:` link before React Native sees it, on a cold start and when the running app receives it. The EXTRA_EMAIL, EXTRA_CC, EXTRA_BCC, EXTRA_SUBJECT and EXTRA_TEXT extras are folded into the link's query. Bcc recipients of a mailto link now reach the composer too; they were dropped for VIEW links as well.
77 lines
2.8 KiB
Kotlin
77 lines
2.8 KiB
Kotlin
package com.anonymous.bulwarkmobile
|
|
|
|
import android.content.Intent
|
|
import android.os.Build
|
|
import android.os.Bundle
|
|
|
|
import com.facebook.react.ReactActivity
|
|
import com.facebook.react.ReactActivityDelegate
|
|
import com.facebook.react.defaults.DefaultNewArchitectureEntryPoint.fabricEnabled
|
|
import com.facebook.react.defaults.DefaultReactActivityDelegate
|
|
|
|
import expo.modules.ReactActivityDelegateWrapper
|
|
|
|
class MainActivity : ReactActivity() {
|
|
override fun onCreate(savedInstanceState: Bundle?) {
|
|
// Set the theme to AppTheme BEFORE onCreate to support
|
|
// coloring the background, status bar, and navigation bar.
|
|
// This is required for expo-splash-screen.
|
|
setTheme(R.style.AppTheme);
|
|
ShareIntentStore.rewriteSendToAsView(intent)
|
|
super.onCreate(null)
|
|
NotificationTapStore.captureFromIntent(intent)
|
|
ShareIntentStore.captureFromIntent(intent, contentResolver)
|
|
}
|
|
|
|
override fun onNewIntent(intent: Intent) {
|
|
ShareIntentStore.rewriteSendToAsView(intent)
|
|
super.onNewIntent(intent)
|
|
setIntent(intent)
|
|
ShareIntentStore.captureFromIntent(intent, contentResolver)?.let { share ->
|
|
BulwarkFcmModule.emit("app:share", share.toMap())
|
|
}
|
|
val payload = NotificationTapStore.captureFromIntent(intent) ?: return
|
|
BulwarkFcmModule.emit("fcm:notificationTap", payload.toMap())
|
|
}
|
|
|
|
/**
|
|
* Returns the name of the main component registered from JavaScript. This is used to schedule
|
|
* rendering of the component.
|
|
*/
|
|
override fun getMainComponentName(): String = "main"
|
|
|
|
/**
|
|
* Returns the instance of the [ReactActivityDelegate]. We use [DefaultReactActivityDelegate]
|
|
* which allows you to enable New Architecture with a single boolean flags [fabricEnabled]
|
|
*/
|
|
override fun createReactActivityDelegate(): ReactActivityDelegate {
|
|
return ReactActivityDelegateWrapper(
|
|
this,
|
|
BuildConfig.IS_NEW_ARCHITECTURE_ENABLED,
|
|
object : DefaultReactActivityDelegate(
|
|
this,
|
|
mainComponentName,
|
|
fabricEnabled
|
|
){})
|
|
}
|
|
|
|
/**
|
|
* Align the back button behavior with Android S
|
|
* where moving root activities to background instead of finishing activities.
|
|
* @see <a href="https://developer.android.com/reference/android/app/Activity#onBackPressed()">onBackPressed</a>
|
|
*/
|
|
override fun invokeDefaultOnBackPressed() {
|
|
if (Build.VERSION.SDK_INT <= Build.VERSION_CODES.R) {
|
|
if (!moveTaskToBack(false)) {
|
|
// For non-root activities, use the default implementation to finish them.
|
|
super.invokeDefaultOnBackPressed()
|
|
}
|
|
return
|
|
}
|
|
|
|
// Use the default back button implementation on Android S
|
|
// because it's doing more than [Activity.moveTaskToBack] in fact.
|
|
super.invokeDefaultOnBackPressed()
|
|
}
|
|
}
|