Giorgi
12/28/2023, 2:09 PMGiorgi
12/28/2023, 2:09 PMpublic interface MPFile<out T : Any> {
// on JS this will be a file name, on other platforms it will be a file path
public val path: String
public val platformFile: T
public suspend fun getFileByteArray(): ByteArray
}
public typealias FileSelected = (MPFile<Any>?) -> Unit
@Composable
public expect fun FilePicker(
show: Boolean,
initialDirectory: String? = null,
fileExtensions: List<String> = emptyList(),
title: String? = null,
onFileSelected: FileSelected,
)
It works, but I'm forced to add arguments, which does not work or works differently, to all targets. for example title
argument, it only has effect on JVM and MacOS.
Return type is MPFile<Any>
so it is always required to be cast to some platform specific object, here is the issue about that https://github.com/Wavesonics/compose-multiplatform-file-picker/issues/69.
few functionality that I cant imagine being possible to cover via common code
• on some platforms there is synchronous and asynchronous versions for file picker dialog
• on Windows there are 2 variants of file pickers: GetOpenFileNameA and GetOpenFileNameW
• There could be a case where you want to set a dialog title on Windows and not on MacOS
Currently I think that there should be no common code written in this library. This should be done in other projects that depend on the library.
How would you design the API for it?Giorgi
12/28/2023, 2:10 PMjw
12/28/2023, 4:02 PMjw
12/28/2023, 4:12 PMGiorgi
12/31/2023, 12:42 PM<input type="file">
? that seems to be this https://developer.mozilla.org/en-US/docs/Web/API/File. Kotlinx.io library code in JS tries to load fs and path modules. This will not work in a browser, but only for Nodejs
I guess all I can do is wait and it is better to keep the common code,
okay, I think I know what to do. Common code that is already written will stay. Also there will be platform specific functions like FilePickerAndroid and FilePickerJvm, there was a PR for this already here https://github.com/Wavesonics/compose-multiplatform-file-picker/pull/89/commits/c7975da115a7f4be27eed5b7b341a0f8ea0e0cd7