Skip to content
Merged
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 25 additions & 3 deletions android/app/src/main/java/com/expensify/chat/MainApplication.kt
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,12 @@ import com.facebook.react.modules.i18nmanager.I18nUtil
import com.facebook.react.soloader.OpenSourceMergedSoMapping
import com.facebook.soloader.SoLoader
import expo.modules.ApplicationLifecycleDispatcher
import java.lang.ref.WeakReference
import com.facebook.react.ReactNativeApplicationEntryPoint.loadReactNative

class MainApplication : MultiDexApplication(), ReactApplication {
private var plaidLinkActivity: WeakReference<Activity>? = null

override val reactHost: ReactHost by lazy {
getDefaultReactHost(
context = applicationContext,
Expand All @@ -52,7 +55,8 @@ class MainApplication : MultiDexApplication(), ReactApplication {

// Plaid's LinkActivity calls setRequestedOrientation(PORTRAIT) in its own onCreate(),
// which forces the UI to portrait even when the device is in landscape. We override it
// here so Plaid can render in whichever orientation the device is actually in.
// on tablets only, because on phones the landscape keyboard leaves Plaid's WebView too short
// to show its inputs.
registerActivityLifecycleCallbacks(object : Application.ActivityLifecycleCallbacks {
override fun onActivityCreated(activity: Activity, savedInstanceState: Bundle?) {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.TIRAMISU) {
Expand All @@ -64,15 +68,20 @@ class MainApplication : MultiDexApplication(), ReactApplication {
}
}
if (activity.javaClass.name == "com.plaid.internal.link.LinkActivity") {
activity.requestedOrientation = ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED
plaidLinkActivity = WeakReference(activity)
applyPlaidOrientation(activity, activity.resources.configuration)
}
}
override fun onActivityStarted(activity: Activity) {}
override fun onActivityResumed(activity: Activity) {}
override fun onActivityPaused(activity: Activity) {}
override fun onActivityStopped(activity: Activity) {}
override fun onActivitySaveInstanceState(activity: Activity, outState: Bundle) {}
override fun onActivityDestroyed(activity: Activity) {}
override fun onActivityDestroyed(activity: Activity) {
if (plaidLinkActivity?.get() === activity) {
plaidLinkActivity = null
}
}
Comment on lines +80 to +84

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Those LOC doesn't have in your proposal. Can you explain it a bit here?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

these are from Codex comment above and i think it's valid concern. LinkActivity has smallestScreenSize in configChanges, so fold/unfold doesn't recreate it and onActivityCreated won't run again. that's why we keep ref and re-apply in onConfigurationChanged

})

ReactFontManager.getInstance().addCustomFont(this, "Custom Emoji Font", R.font.custom_emoji_font)
Expand Down Expand Up @@ -117,6 +126,19 @@ class MainApplication : MultiDexApplication(), ReactApplication {
override fun onConfigurationChanged(newConfig: Configuration) {
super.onConfigurationChanged(newConfig)
ApplicationLifecycleDispatcher.onConfigurationChanged(this, newConfig)
// LinkActivity handles smallestScreenSize itself, so folding or unfolding does not recreate it.
plaidLinkActivity?.get()?.let { applyPlaidOrientation(it, newConfig) }
}

private fun applyPlaidOrientation(activity: Activity, config: Configuration) {
if (config.smallestScreenWidthDp >= 600) {
activity.requestedOrientation = ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED
return
}
// Android 8.0 throws when a translucent activity requests a fixed orientation; Plaid skips it there too.
if (Build.VERSION.SDK_INT != Build.VERSION_CODES.O) {
activity.requestedOrientation = ActivityInfo.SCREEN_ORIENTATION_PORTRAIT

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@mukhrr why don't we use Plaid's requestedOrientation? (I recall Plaid already set ActivityInfo.SCREEN_ORIENTATION_PORTRAIT)

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

hmm yeah, it makes sense to me

}
}

private fun isOnfidoProcess(): Boolean {
Expand Down
Loading