-
Notifications
You must be signed in to change notification settings - Fork 658
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
[connect] Cleanup EmbeddedComponentManager
scope and setup
#9809
Conversation
Diffuse output:
APK
|
|
||
override fun onCreate(savedInstanceState: Bundle?) { | ||
super.onCreate(savedInstanceState) | ||
|
||
EmbeddedComponentManager.onActivityCreate(this@MainActivity) |
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.
👀 Moved to BaseActivity#onCreate()
|
||
@OptIn(PrivateBetaConnectSDK::class) | ||
@Singleton | ||
class EmbeddedComponentManagerProvider @Inject constructor( |
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.
👀 Reduced to EmbeddedComponentManagerManager
val appearanceInfo = settingsService.getAppearanceId() | ||
?.let { AppearanceInfo.getAppearance(it, context).appearance } | ||
?: return@LaunchedEffect | ||
embeddedComponentManager.update(appearanceInfo) |
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.
👀 Binding the app appearance setting to the manager is now done in EmbeddedComponentLoaderViewModel
import javax.inject.Inject | ||
|
||
@Suppress("ConstPropertyName") | ||
private object BasicComponentExampleDestination { |
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.
👀 nit: moved this below the Activity definition
loadManager() | ||
return | ||
// Bind appearance settings to the manager. | ||
activity.lifecycleScope.launch { |
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.
👀 Important that we bind in the Activity scope and not ViewModel scope, otherwise there'd be a memory leak
8f8ba76
to
b7a66a3
Compare
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.
Looks like some classes (BaseActivity, EmbeddedComponentManagerFactory) aren't defined. Approach looks great though - thanks for cleaning this up!
@@ -37,7 +37,10 @@ fun EmbeddedComponentManagerLoader( | |||
) { | |||
val embeddedComponentManager = embeddedComponentAsync() | |||
when (embeddedComponentAsync) { | |||
is Uninitialized, is Loading -> LoadingScreen() | |||
is Uninitialized -> { | |||
// Don't show anything to avoid flicker. |
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.
Good catch
@@ -248,6 +248,8 @@ internal class StripeConnectWebViewContainerImpl<Listener, Props>( | |||
|
|||
private fun bindViewState(state: StripeConnectWebViewContainerState) { | |||
val viewBinding = this.viewBinding ?: return | |||
logger.debug("Binding view state: $state") | |||
viewBinding.root.setBackgroundColor(state.backgroundColor) |
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.
Nice! Looks like this fixes MXMOBILE-2996 - I've linked this PR and marked it as done.
b7a66a3
to
47f60e0
Compare
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.
Looks great!
Summary
Addresses this PR comment.
Instead of having a singleton
EmbeddedComponentManager
app instance in the Example app:EmbeddedComponentManager
instances inEmbeddedComponentLoaderViewModel
EmbeddedComponentManagerProvider
has been demoted to aFactory
, simplifying its roleEmbeddedComponentLoaderViewModel
is also responsible for binding app appearance settings to the manager inActivity#onCreate()
. It does so by being being a lifecycle observer that Activities must register. This is aided by introducing aBaseActivity
that our activities should extend.Also, fixed a minor visual glitch with embedded component backgrounds.
Motivation
See comment. Overall, I think this eliminates some confusing state logic we had between
EmbeddedComponentManagerProvider
andEmbeddedComponentLoaderViewModel
. There are clearer separations of concerns.Testing
Screenshots
Screen.Recording.2024-12-19.at.1.20.01.PM-compressed.mov