Use PlatformContext to pass Android Activity Context to use cases #310
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Since many use cases should use an Activity Context rather than the Application Context on Android to work properly (mostly to launch Intents), refactor these use cases to take a
PlatformContext
argument and use it to wrap the Android Context on Android.PlatformContext
from the ui module to the domain module so it can be referenced from use cases.PlatformContext
as an empty object on iOS and a class containing aContext
reference on Android.LocalPlatformContext
CompositionLocal with anexpect getPlatformContext()
composable function. There is no need to create a new CompositionLocal because Android already hasLocalContext
to carry the Context over to any composable function, and an expect function is safer because it guarantees that a non-nullPlatformContext
is provided for every platform at compile time.UrlOpener
,OpenMapUseCase
,ApplyForAppClinicUseCase
,OpenCocUseCase
,OpenFaqUseCase
,OpenLinkUseCase
,OpenPartnerLinkUseCase
,OpenXAccountUseCase
,OpenXHashtagUseCase
,OpenYoutubeUseCase
,ShareSessionUseCase
to accept aPlatformContext
as first argument.ShareSessionUseCase
to useShareCompat.IntentBuilder
from the androidx.core library.Uri.Builder
instead of custom String formatting to build mapUri
.