Repository navigation
Keep Plaid in portrait on Android phones so its inputs stay visible #105598
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 2 commits
efd395a
5777edc
bd672b6
e1fc9d3
84c3808
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -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, | ||
|
|
@@ -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) { | ||
|
|
@@ -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 | ||
| } | ||
| } | ||
| }) | ||
|
|
||
| ReactFontManager.getInstance().addCustomFont(this, "Custom Emoji Font", R.font.custom_emoji_font) | ||
|
|
@@ -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 | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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)
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. hmm yeah, it makes sense to me |
||
| } | ||
| } | ||
|
|
||
| private fun isOnfidoProcess(): Boolean { | ||
|
|
||
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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.
LinkActivityhassmallestScreenSizeinconfigChanges, so fold/unfold doesn't recreate it andonActivityCreatedwon't run again. that's why we keep ref and re-apply inonConfigurationChanged