This repository has been archived by the owner on Jun 25, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 21
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #68 from aguragorn/master
feat: ios file picker
- Loading branch information
Showing
23 changed files
with
1,131 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
import org.jetbrains.kotlin.gradle.ExperimentalKotlinGradlePluginApi | ||
|
||
plugins { | ||
kotlin("multiplatform") | ||
kotlin("native.cocoapods") | ||
alias(libs.plugins.kotlin.compose) | ||
} | ||
|
||
@OptIn(ExperimentalKotlinGradlePluginApi::class) | ||
kotlin { | ||
targetHierarchy.default() | ||
|
||
iosX64() | ||
iosArm64() | ||
iosSimulatorArm64() | ||
|
||
sourceSets { | ||
val iosMain by getting { | ||
dependencies { | ||
implementation(compose.ui) | ||
implementation(compose.foundation) | ||
implementation(compose.material) | ||
implementation(compose.runtime) | ||
|
||
implementation(project(":mpfilepicker")) | ||
} | ||
} | ||
} | ||
} | ||
|
||
|
||
kotlin.cocoapods { | ||
name = "ios" | ||
version = libs.versions.library.get() | ||
summary = | ||
"A multiplatform compose widget for picking files with each platform''s Native File Picker Dialog." | ||
homepage = "https://github.com/Wavesonics/compose-multiplatform-file-picker" | ||
ios.deploymentTarget = "14.1" | ||
|
||
framework { | ||
baseName = "ios" | ||
} | ||
|
||
podfile = project.file("../iosApp/Podfile") | ||
} | ||
|
||
repositories { | ||
mavenCentral() | ||
maven { url = uri("https://maven.pkg.jetbrains.space/public/p/kotlinx-html/maven") } | ||
maven("https://maven.pkg.jetbrains.space/public/p/compose/dev") | ||
google() | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
Pod::Spec.new do |spec| | ||
spec.name = 'ios' | ||
spec.version = '2.1.0' | ||
spec.homepage = 'https://github.com/Wavesonics/compose-multiplatform-file-picker' | ||
spec.source = { :http=> ''} | ||
spec.authors = '' | ||
spec.license = '' | ||
spec.summary = 'A multiplatform compose widget for picking files with each platform''s Native File Picker Dialog.' | ||
spec.vendored_frameworks = 'build/cocoapods/framework/ios.framework' | ||
spec.libraries = 'c++' | ||
spec.ios.deployment_target = '14.1' | ||
|
||
|
||
spec.pod_target_xcconfig = { | ||
'KOTLIN_PROJECT_PATH' => ':examples:ios', | ||
'PRODUCT_MODULE_NAME' => 'ios', | ||
} | ||
|
||
spec.script_phases = [ | ||
{ | ||
:name => 'Build ios', | ||
:execution_position => :before_compile, | ||
:shell_path => '/bin/sh', | ||
:script => <<-SCRIPT | ||
if [ "YES" = "$OVERRIDE_KOTLIN_BUILD_IDE_SUPPORTED" ]; then | ||
echo "Skipping Gradle build task invocation due to OVERRIDE_KOTLIN_BUILD_IDE_SUPPORTED environment variable set to \"YES\"" | ||
exit 0 | ||
fi | ||
set -ev | ||
REPO_ROOT="$PODS_TARGET_SRCROOT" | ||
"$REPO_ROOT/../../gradlew" -p "$REPO_ROOT" $KOTLIN_PROJECT_PATH:syncFramework \ | ||
-Pkotlin.native.cocoapods.platform=$PLATFORM_NAME \ | ||
-Pkotlin.native.cocoapods.archs="$ARCHS" \ | ||
-Pkotlin.native.cocoapods.configuration="$CONFIGURATION" | ||
SCRIPT | ||
} | ||
] | ||
spec.resources = ['build/compose/ios/ios/compose-resources'] | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,87 @@ | ||
import androidx.compose.foundation.layout.Column | ||
import androidx.compose.material.Button | ||
import androidx.compose.material.MaterialTheme | ||
import androidx.compose.material.Text | ||
import androidx.compose.runtime.getValue | ||
import androidx.compose.runtime.mutableStateOf | ||
import androidx.compose.runtime.remember | ||
import androidx.compose.runtime.setValue | ||
import androidx.compose.ui.window.ComposeUIViewController | ||
import com.darkrockstudios.libraries.mpfilepicker.DirectoryPicker | ||
import com.darkrockstudios.libraries.mpfilepicker.FilePicker | ||
import com.darkrockstudios.libraries.mpfilepicker.launchDirectoryPicker | ||
import com.darkrockstudios.libraries.mpfilepicker.launchFilePicker | ||
import kotlinx.coroutines.MainScope | ||
import kotlinx.coroutines.launch | ||
import platform.UIKit.UIViewController | ||
|
||
@Suppress("Unused", "FunctionName") | ||
fun MainViewController(): UIViewController = ComposeUIViewController { | ||
MaterialTheme { | ||
Column { | ||
var showFilePicker by remember { mutableStateOf(false) } | ||
var pathChosen by remember { mutableStateOf("") } | ||
|
||
Button(onClick = { | ||
showFilePicker = true | ||
}) { | ||
Text("Choose File") | ||
} | ||
Text("File Chosen: $pathChosen") | ||
|
||
val fileType = listOf("jpg", "png", "md") | ||
FilePicker(showFilePicker, fileExtensions = fileType) { mpFile -> | ||
pathChosen = mpFile?.path ?: "none selected" | ||
showFilePicker = false | ||
} | ||
|
||
///////////////////////////////////////////////////////////////// | ||
|
||
var nonComposeFileChosen by remember { mutableStateOf("") } | ||
|
||
Button(onClick = { | ||
MainScope().launch { | ||
nonComposeFileChosen = launchFilePicker(fileExtensions = fileType) | ||
.firstOrNull()?.path ?: "none selected" | ||
} | ||
}) { | ||
|
||
Text("Choose File Non-Compose") | ||
} | ||
Text("File Chosen: $nonComposeFileChosen") | ||
|
||
///////////////////////////////////////////////////////////////// | ||
|
||
var showDirPicker by remember { mutableStateOf(false) } | ||
var dirChosen by remember { mutableStateOf("") } | ||
|
||
Button(onClick = { | ||
showDirPicker = true | ||
}) { | ||
Text("Choose Directory") | ||
} | ||
Text("Directory Chosen: $dirChosen") | ||
|
||
DirectoryPicker(showDirPicker) { path -> | ||
dirChosen = path ?: "none selected" | ||
showDirPicker = false | ||
} | ||
|
||
///////////////////////////////////////////////////////////////// | ||
|
||
var nonComposeDirChosen by remember { mutableStateOf("") } | ||
|
||
Button(onClick = { | ||
MainScope().launch { | ||
nonComposeDirChosen = launchDirectoryPicker() | ||
.firstOrNull()?.path ?: "none selected" | ||
} | ||
}) { | ||
|
||
Text("Choose Directory Non-Compose") | ||
} | ||
Text("Directory Chosen: $nonComposeDirChosen") | ||
|
||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
|
||
target 'iosApp' do | ||
use_frameworks! | ||
platform :ios, '14.1' | ||
pod 'ios', :path => '../ios' | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
PODS: | ||
- ios (2.1.0) | ||
|
||
DEPENDENCIES: | ||
- ios (from `../ios`) | ||
|
||
EXTERNAL SOURCES: | ||
ios: | ||
:path: "../ios" | ||
|
||
SPEC CHECKSUMS: | ||
ios: 80add486144f9c02a08c206ce1fc40d4d2befb0a | ||
|
||
PODFILE CHECKSUM: d0f1a8cda67b334342153a01dcff5e0cb3dfeab9 | ||
|
||
COCOAPODS: 1.12.1 |
Oops, something went wrong.