88 lines
3.2 KiB
Kotlin
88 lines
3.2 KiB
Kotlin
package com.locphamtran.recipescamera
|
|
|
|
import android.content.Intent
|
|
import android.os.Build
|
|
import android.os.Bundle
|
|
import android.view.KeyEvent
|
|
|
|
import com.facebook.react.ReactActivity
|
|
import com.facebook.react.ReactActivityDelegate
|
|
import com.facebook.react.defaults.DefaultNewArchitectureEntryPoint.fabricEnabled
|
|
import com.facebook.react.defaults.DefaultReactActivityDelegate
|
|
|
|
import com.locphamtran.recipescamera.volume.VolumeShutterModule
|
|
|
|
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);
|
|
super.onCreate(null)
|
|
}
|
|
|
|
/**
|
|
* A share delivered to the running app lands here, and React Native never hands
|
|
* the new intent to the activity (nothing in ReactActivity/ReactDelegate calls
|
|
* setIntent) — so getIntent() keeps returning the launch intent and the share
|
|
* intake would read a photo the user shared minutes ago, or none at all.
|
|
*/
|
|
override fun onNewIntent(intent: Intent) {
|
|
setIntent(intent)
|
|
super.onNewIntent(intent)
|
|
}
|
|
|
|
/**
|
|
* Volume keys double as a shutter release while the camera screen is up.
|
|
* This is the only place that runs before the window turns them into a
|
|
* stream-volume change, so the module gets first refusal and the keys it
|
|
* does not claim (everything, outside the camera) fall through to the
|
|
* default handling unchanged.
|
|
*/
|
|
override fun dispatchKeyEvent(event: KeyEvent): Boolean {
|
|
return VolumeShutterModule.onKeyEvent(event) || super.dispatchKeyEvent(event)
|
|
}
|
|
|
|
/**
|
|
* 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()
|
|
}
|
|
}
|