markturnip
11/18/2025, 4:15 AMContext that can be used in commonMain rather than directly referencing android.content.Context?markturnip
11/18/2025, 4:24 AM// Abstract context for shared code
interface SharedContext
// The common interface
interface MyComposableHandler {
fun doSomething(context: SharedContext)
}
Then casted in my Android source set:
// Android implementation of the interface
class AndroidComposableHandler : MyComposableHandler {
override fun doSomething(context: SharedContext) {
val activity = (context as? AndroidSharedContext)?.activityWinson Chiu
11/18/2025, 5:25 AMefemoney
11/18/2025, 5:28 AMPablichjenkov
11/18/2025, 5:35 AMmarkturnip
11/18/2025, 7:31 AMmarkturnip
11/18/2025, 7:31 AMmarkturnip
11/18/2025, 7:31 AMmarkturnip
11/18/2025, 7:32 AMandroidContext(this@MyApplication)markturnip
11/18/2025, 7:36 AMComponentActivity to initialise the `PaymentSheet`:
https://kotlinlang.slack.com/archives/C3PQML5NU/p1763450494383769?thread_ts=1738603708.469789&cid=C3PQML5NUMark
11/18/2025, 8:39 AMexpect class PlatformContext
androidMain (no casting required):
actual typealias PlatformContext = android.content.Context
iosMain:
actual class PlatformContext
?
I use this approach for PlatformTypeface because compose font classes don’t expose hasGlyph functionality whereas platform-specific typeface classes do.markturnip
11/19/2025, 1:22 AMThe following declaration is incompatible because modality is different. Expect declaration modality is ‘final’. Actual declaration modality is ‘abstract’:
expect class PlatformContext : Any
markturnip
11/19/2025, 1:22 AMexpect abstract class PlatformContextmarkturnip
11/19/2025, 2:09 AMMark
11/19/2025, 4:49 AM@Suppress("EXPECT_ACTUAL_CLASSIFIERS_ARE_IN_BETA_WARNING")
Perhaps also the fact that android Typeface is a concrete class also matters, not sure.markturnip
11/19/2025, 5:48 AM