15

GitHub - Wavesonics/compose-multiplatform-file-picker: A multiplatform compose w...

 1 year ago
source link: https://github.com/Wavesonics/compose-multiplatform-file-picker
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.
neoserver,ios ssh client

Compose Multiplatform File Picker

A multiplatform compose widget for picking files with each platform's Native File Picker Dialog.

Currently supports: Desktop and Android.

Desktop/JVM Implementation

The native desktop dialog implementation is derived from the Pacmc project

See FileChooser.kt as well as the lwjgl gradle filter.

Include in your project:

implementation("com.darkrockstudios:mpfilepicker:1.0.0")

How to use

In your shared jetbrains compose multiplatform code, add one of the following.

To show the dialog, simply set the boolean state to true via a button or what ever you want.

Pick a file with a filter:

var showFilePicker by remember { mutableStateOf(false) }

val fileType = "jpg"
FilePicker(showFilePicker, fileExtension = fileType) { path ->
    showFilePicker = false
    // do something with path
}

Pick a directory:

var showDirPicker by remember { mutableStateOf(false) }

DirectoryPicker(showDirPicker) { path ->
    showDirPicker = false
    // do something with path
}

On each supported platform, it will update the platform native file picker dialog. On desktop it will fall back to the Swing file picker if the native one can't be use for some reason.

Windows

Windows native file picker

Android

Android native file picker

Known Bugs

  • Setting the initial directory doesn't seem to effect Android's file picker at all, not sure why that is yet.

About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK