Alexander Suraphel
12/27/2021, 4:40 PMBig Chungus
12/27/2021, 5:37 PMDavid W
12/27/2021, 6:09 PMDavid W
12/27/2021, 6:10 PMspierce7
01/01/2022, 12:15 AMgildor
01/01/2022, 1:11 AMStuie
01/01/2022, 1:17 AMexpect/actual
for creating a Composable (or much of anything else) so I'll need to do a bit of digging.
Is there a good sample repository you know of? The examples in the compose-jb repo seem to be very basic, but perhaps I missed something in there.Big Chungus
01/01/2022, 1:44 AMStuie
01/01/2022, 2:24 AMcommon
desktop
android
common
contains androidMain
commonMain
and desktopMain
desktop
contains commonMain
and jvmMain
android
just contains what I'm used to in a single-module Android app (I'm an Android developer most of the time).
common.commonMain
seems like the obvious place to put my `expect`s.
Then have an actual
in desktop.jvmMain
that uses JavaFX WebView
And an actual
in android
that uses Android's WebView.
I'm trying that out now, but I've messed things up somewhere, it seems. desktop.jvmMain
actual
is complaining that there's no expect
in desktop.commonMain
, which seems to be too specific, since I want to implement the same in android
.
I'll keep playing around, but I'd appreciate any pointers if you've got them.
Apologies for the wall of text.spierce7
01/01/2022, 3:05 AMcontainscommon
androidMain
andcommonMain
desktopMain
This sounds wrong. Android should contain commonMain, and androidMain. Desktop should contain commonMain, and desktopMain. If you wanted to get pretty advanced you could also add another layer of jvmMain to be shared between android and desktop.containsdesktop
andcommonMain
jvmMain
Big Chungus
01/01/2022, 3:07 AMspierce7
01/01/2022, 3:07 AMYes - this is correct.seems like the obvious place to put my `expect`s.common.commonMain
expect
/ actual
is a way to enforce a compile time contract between platforms. expect
is in the common layer, and then when you compile it, the compiler enforces a single resolved actual
of it when it combines all the dependent source sets together (at least that’s my mental model for it)Big Chungus
01/01/2022, 3:08 AMStuie
01/01/2022, 3:12 AMexpects
and not know if there's an actual
out there outside your boundary.
@spierce7 For which module? The project is the result of going through the New Project
wizard, and choosing Compose multiplatform.spierce7
01/01/2022, 3:13 AMStuie
01/01/2022, 3:39 AMorg.openjfx.javafxplugin
in common/build.gradle.kts
because com.android.library
is already applied, and the javafxplugin applies the java
plugin.
The 'java' plugin has been applied, but it is not compatible with the Android plugins.
Not sure if I can specify plugins for particular flavors, or where I would stick the javafx
and android
blocks.
Here's what my common/build.gradle.kts
looks likeBig Chungus
01/01/2022, 3:43 AMStuie
01/01/2022, 4:57 AMcommon
if you need use something like a WebView which has platform-specific implementations not covered by Compose?Stuie
01/01/2022, 5:04 AMcommon
/`SomeScreen.kt`
@Composable
expect fun SomeScreen() {}
The actuals
have to be in common
, but actual fun SomeScreen
in the desktopMain
sourceSet requires JavaFX with its WebView, and actual fun SomeScreen
in the androidMain
sourceSet requires the Android WebView.
If I move the expect
out of common
, then it has to be to either the android
or desktop
module, at which point I can just define a solid implementation with no `expect`/`actual` , and then I have to define it again for the other platform. I cannot refer to either implementation within the common
module.Stuie
01/01/2022, 5:07 AMspierce7
01/01/2022, 5:34 AMI think I’ve arrived at the conclusion that I just need to create my UI once per platform, which I was hoping to avoid.Maybe I’m not following everything you’ve said well enough, but if this is still over the WebView thing, I think you’ve arrived at the wrong conclusion. It’s difficult to follow discussion, because it sounds like you have a module called
common
, which is difficult to follow when there are common source sets.
Think of it this way: Create a new module. A compose library called compose-webview
. It will support 2 platforms, jvm and android. Here is the folder heirarchy:
• ./compose-webview
◦ src
▪︎ commonMain
▪︎ jvmMain
▪︎ androidMain
Inside commonMain
there will be:
@Compose
expect fun WebView(url: String)
Inside jvmMain
you will have the corresponding
@Compose
actual fun WebView(url: String) {
// delegate to JavaFX WebView. I don't know how to do that
}
@Compose
actual fun WebView(url: String) {
// delegate to Android WebView using the interop apis: <https://developer.android.com/jetpack/compose/interop/interop-apis>
}
Stuie
01/01/2022, 5:59 AMcom.android.library
and javafx plugin in this new module, and then arrive at the same problem as before?
The 'java' plugin has been applied, but it is not compatible with the Android plugins.
spierce7
01/01/2022, 3:55 PMspierce7
01/01/2022, 3:55 PMgildor
01/01/2022, 4:03 PMAlexander Suraphel
01/01/2022, 4:05 PMAlexander Suraphel
01/01/2022, 4:06 PMgildor
01/01/2022, 4:07 PMgildor
01/01/2022, 4:08 PMStuie
01/01/2022, 5:37 PMgildor
01/02/2022, 3:15 AM