Skip to content
This repository has been archived by the owner on Jun 25, 2024. It is now read-only.

Commit

Permalink
Merge pull request #68 from aguragorn/master
Browse files Browse the repository at this point in the history
feat: ios file picker
  • Loading branch information
shalva97 authored Oct 29, 2023
2 parents a09025c + 24b4d55 commit 858375a
Show file tree
Hide file tree
Showing 23 changed files with 1,131 additions and 0 deletions.
109 changes: 109 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -46,3 +46,112 @@ bin/
/.idea/deploymentTargetDropDown.xml
/.idea/artifacts/desktop_jvm_1_0_SNAPSHOT.xml
/local.properties

# Created by https://www.toptal.com/developers/gitignore/api/xcode,cocoapods,swift
# Edit at https://www.toptal.com/developers/gitignore?templates=xcode,cocoapods,swift

### CocoaPods ###
## CocoaPods GitIgnore Template

# CocoaPods - Only use to conserve bandwidth / Save time on Pushing
# - Also handy if you have a large number of dependant pods
# - AS PER https://guides.cocoapods.org/using/using-cocoapods.html NEVER IGNORE THE LOCK FILE
Pods/

### Swift ###
# Xcode
#
# gitignore contributors: remember to update Global/Xcode.gitignore, Objective-C.gitignore & Swift.gitignore

## User settings
xcuserdata/

## compatibility with Xcode 8 and earlier (ignoring not required starting Xcode 9)
*.xcscmblueprint
*.xccheckout

## compatibility with Xcode 3 and earlier (ignoring not required starting Xcode 4)
DerivedData/
*.moved-aside
*.pbxuser
!default.pbxuser
*.mode1v3
!default.mode1v3
*.mode2v3
!default.mode2v3
*.perspectivev3
!default.perspectivev3

## Obj-C/Swift specific
*.hmap

## App packaging
*.ipa
*.dSYM.zip
*.dSYM

## Playgrounds
timeline.xctimeline
playground.xcworkspace

# Swift Package Manager
# Add this line if you want to avoid checking in source code from Swift Package Manager dependencies.
# Packages/
# Package.pins
# Package.resolved
# *.xcodeproj
# Xcode automatically generates this directory with a .xcworkspacedata file and xcuserdata
# hence it is not needed unless you have added a package configuration file to your project
# .swiftpm

.build/

# CocoaPods
# We recommend against adding the Pods directory to your .gitignore. However
# you should judge for yourself, the pros and cons are mentioned at:
# https://guides.cocoapods.org/using/using-cocoapods.html#should-i-check-the-pods-directory-into-source-control
# Pods/
# Add this line if you want to avoid checking in source code from the Xcode workspace
# *.xcworkspace

# Carthage
# Add this line if you want to avoid checking in source code from Carthage dependencies.
# Carthage/Checkouts

Carthage/Build/

# Accio dependency management
Dependencies/
.accio/

# fastlane
# It is recommended to not store the screenshots in the git repo.
# Instead, use fastlane to re-generate the screenshots whenever they are needed.
# For more information about the recommended setup visit:
# https://docs.fastlane.tools/best-practices/source-control/#source-control

fastlane/report.xml
fastlane/Preview.html
fastlane/screenshots/**/*.png
fastlane/test_output

# Code Injection
# After new code Injection tools there's a generated folder /iOSInjectionProject
# https://github.com/johnno1962/injectionforxcode

iOSInjectionProject/

### Xcode ###

## Xcode 8 and earlier

### Xcode Patch ###
*.xcodeproj/*
!*.xcodeproj/project.pbxproj
!*.xcodeproj/xcshareddata/
!*.xcodeproj/project.xcworkspace/
!*.xcworkspace/contents.xcworkspacedata
/*.gcno
**/xcshareddata/WorkspaceSettings.xcsettings

# End of https://www.toptal.com/developers/gitignore/api/xcode,cocoapods,swift
19 changes: 19 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,25 @@ Click on a green button next to the main function in `examples/jvm/.../Main.kt`
Open the project in Android Studio. A run configuration for Android should be added automatically.
Clicking on it will run it on an emulator.

### iOS

Requirements:
- MacOS
- Xcode
- Android Studio

Setup your environment by following the [Official Multiplatform Mobile Guide](https://kotlinlang.org/docs/multiplatform-mobile-setup.html).
To run iOS example app you also need to follow the [Set-up an environment to work with CocoaPods Guide](https://kotlinlang.org/docs/native-cocoapods.html#set-up-an-environment-to-work-with-cocoapods).

Open the project in Android Studio, install `Kotlin Multiplatform Mobile` plugin. Create an `iOS Application` run config
and enter the following:
- Xcode Project File: `<project_dir>/examples/iosApp/iosApp.xcworkspace`
- Xcode Project Scheme: `iosApp`
- Xcode Project Cinfiguration: `Debug`
- Execution Target: choose any simulator you have already created

Use it to launch a simulator and run/debug the example iOS App,

[badge-kotlin]: https://img.shields.io/badge/kotlin-1.8.20-blue.svg?logo=kotlin

<!-- PLATFORMS -->
Expand Down
52 changes: 52 additions & 0 deletions examples/ios/build.gradle.kts
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()
}
39 changes: 39 additions & 0 deletions examples/ios/ios.podspec
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
87 changes: 87 additions & 0 deletions examples/ios/src/iosMain/kotlin/main.ios.kt
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")

}
}
}
6 changes: 6 additions & 0 deletions examples/iosApp/Podfile
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
16 changes: 16 additions & 0 deletions examples/iosApp/Podfile.lock
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
Loading

0 comments on commit 858375a

Please sign in to comment.