-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit f319168
Showing
14 changed files
with
1,301 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
name: build | ||
|
||
on: | ||
workflow_dispatch: | ||
push: | ||
branches: [ main ] | ||
paths: | ||
- '.swiftlint.yml' | ||
- '**/*.swift' | ||
pull_request: | ||
branches: [ main ] | ||
paths: | ||
- '.swiftlint.yml' | ||
- '**/*.swift' | ||
|
||
jobs: | ||
build: | ||
|
||
runs-on: macos-latest | ||
|
||
steps: | ||
- uses: actions/checkout@v2 | ||
- name: Build | ||
run: swift build -v |
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,24 @@ | ||
name: swiftlint | ||
|
||
on: | ||
workflow_dispatch: | ||
push: | ||
branches: [ main ] | ||
paths: | ||
- '.swiftlint.yml' | ||
- '**/*.swift' | ||
pull_request: | ||
branches: [ main ] | ||
paths: | ||
- '.swiftlint.yml' | ||
- '**/*.swift' | ||
|
||
jobs: | ||
build: | ||
|
||
runs-on: ubuntu-latest | ||
|
||
steps: | ||
- uses: actions/checkout@v2 | ||
- name: GitHub Action for SwiftLint | ||
uses: norio-nomura/[email protected] |
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,24 @@ | ||
name: test | ||
|
||
on: | ||
workflow_dispatch: | ||
push: | ||
branches: [ main ] | ||
paths: | ||
- '.swiftlint.yml' | ||
- '**/*.swift' | ||
pull_request: | ||
branches: [ main ] | ||
paths: | ||
- '.swiftlint.yml' | ||
- '**/*.swift' | ||
|
||
jobs: | ||
build: | ||
|
||
runs-on: macos-latest | ||
|
||
steps: | ||
- uses: actions/checkout@v2 | ||
- name: Run tests | ||
run: swift test -v |
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,7 @@ | ||
.DS_Store | ||
/.build | ||
/Packages | ||
/*.xcodeproj | ||
xcuserdata/ | ||
DerivedData/ | ||
.swiftpm/xcode/package.xcworkspace/contents.xcworkspacedata |
Empty file.
8 changes: 8 additions & 0 deletions
8
.swiftpm/xcode/package.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist
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,8 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd"> | ||
<plist version="1.0"> | ||
<dict> | ||
<key>IDEDidComputeMac32BitWarning</key> | ||
<true/> | ||
</dict> | ||
</plist> |
Large diffs are not rendered by default.
Oops, something went wrong.
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,22 @@ | ||
// swift-tools-version:5.3 | ||
// The swift-tools-version declares the minimum version of Swift required to build this package. | ||
|
||
import PackageDescription | ||
|
||
let package = Package( | ||
name: "ImagePickerModule", | ||
platforms: [.iOS(SupportedPlatform.IOSVersion.v14)], | ||
products: [ | ||
.library( | ||
name: "ImagePickerModule", | ||
targets: ["ImagePickerModule"] | ||
) | ||
], | ||
targets: [ | ||
.target(name: "ImagePickerModule"), | ||
.testTarget( | ||
name: "ImagePickerModuleTests", | ||
dependencies: ["ImagePickerModule"] | ||
) | ||
] | ||
) |
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,63 @@ | ||
# Image Picker Module | ||
[![build](https://github.com/swiftui-packages/image-picker-module/actions/workflows/build.yml/badge.svg)](https://github.com/swiftui-packages/image-picker-module/actions/workflows/build.yml) | ||
[![test](https://github.com/swiftui-packages/image-picker-module/actions/workflows/test.yml/badge.svg)](https://github.com/swiftui-packages/image-picker-module/actions/workflows/test.yml) | ||
[![swiftlint](https://github.com/swiftui-packages/image-picker-module/actions/workflows/swiftlint.yml/badge.svg)](https://github.com/swiftui-packages/image-picker-module/actions/workflows/swiftlint.yml) | ||
[![Codacy Badge](https://app.codacy.com/project/badge/Grade/d62a7ab525064c0d9a8a9f5a667b2506)](https://www.codacy.com/gh/swiftui-packages/image-picker-module/dashboard?utm_source=github.com&utm_medium=referral&utm_content=swiftui-packages/image-picker-module&utm_campaign=Badge_Grade) | ||
[![swiftpackageindex swift versions](https://img.shields.io/endpoint?url=https%3A%2F%2Fswiftpackageindex.com%2Fapi%2Fpackages%2Fswiftui-packages%2Fimage-picker-module%2Fbadge%3Ftype%3Dswift-versions)](https://swiftpackageindex.com/swiftui-packages/image-picker-module) | ||
[![swiftpackageindex platforms](https://img.shields.io/endpoint?url=https%3A%2F%2Fswiftpackageindex.com%2Fapi%2Fpackages%2Fswiftui-packages%2Fimage-picker-module%2Fbadge%3Ftype%3Dplatforms)](https://swiftpackageindex.com/swiftui-packages/image-picker-module) | ||
|
||
## Usage | ||
You have 3 options to make use of the Image Picker Module in your SwiftUI project: | ||
|
||
1. Use plain ImagePicker which has the parameters soruce type and a completion function, which returns the selected picture or taken photo | ||
2. Use the ImagePickerButton which takes a binding of an optional UIImage and lets you define a label for the button. The Button itself comes with some functionality, which will be expanded in the future. For example does it detect if a photo was taken and shows you the option to remove it or show it in full screen. | ||
3. Use the ImagesPickerButton, which is supposed to expand image collections and there for takes a UIImage Array Binding and again lets you set its label. | ||
|
||
<br> | ||
|
||
## Integration | ||
1. Copy the resource url: | ||
``` | ||
https://github.com/swiftui-packages/image-picker-module.git | ||
``` | ||
|
||
2. Open your Xcode project | ||
|
||
3. Two options a and b for step 3<br> | ||
a) At the menu bar navigate to _File_ / _Swift Packages_ / _Add Package Dependency_<br> | ||
b1) Select the project's root folder<br> | ||
b2) select your app name under _PROJECT_<br> | ||
b3) Open _Swift Packages_ tab on the right side of _Info_ and _Build Settings_<br> | ||
b4) Hit the _+_ button at the bottom of the list<br> | ||
|
||
4. Here you should be prompted to "_Choose Package Repository:_" | ||
|
||
5. Paste the resource url | ||
|
||
6. Select _Next_ to go with the latest version or select a specific version or branch | ||
|
||
7. After a short loading period of package resolution you get prompted to _Choose package products and targets_ (the default should be fine) | ||
|
||
8. The complete hit the _Finish_ button | ||
|
||
9. Import ImagePickerModule into the files where you want to use it | ||
|
||
<br> | ||
|
||
## required info.plist entries | ||
- _Privacy - Camera Usage Description_ | ||
|
||
<br> | ||
|
||
## Can also be found here | ||
- [Swift Package Registry](https://swiftpackageregistry.com/swiftui-packages/image-picker-module) | ||
- [Swift Package Index](https://swiftpackageindex.com/swiftui-packages/image-picker-module) | ||
- [Swift Pack](https://swiftpack.co/package/swiftui-packages/image-picker-module) | ||
|
||
<br> | ||
|
||
## ToDos | ||
- maintaining README.md file | ||
- GIF of importing Swift Package Manager Packages into Xcode Projects | ||
- phrasing an introduction text | ||
- writing usage instructions with code examples |
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,61 @@ | ||
// | ||
// ImagePicker.swift | ||
// ImagePickerModule | ||
// | ||
// Created by Cem Yilmaz on 20.08.21. | ||
// | ||
|
||
import SwiftUI | ||
|
||
#if canImport(UIKit) | ||
public struct ImagePicker: UIViewControllerRepresentable { | ||
private let sourceType: UIImagePickerController.SourceType | ||
private let onImagePicked: (UIImage) -> Void | ||
@Environment(\.presentationMode) private var presentationMode: Binding<PresentationMode> | ||
|
||
public init(sourceType: UIImagePickerController.SourceType, onImagePicked: @escaping (UIImage) -> Void) { | ||
self.sourceType = sourceType | ||
self.onImagePicked = onImagePicked | ||
} | ||
|
||
public func makeUIViewController(context: Context) -> UIImagePickerController { | ||
let picker = UIImagePickerController() | ||
picker.sourceType = self.sourceType | ||
picker.delegate = context.coordinator | ||
return picker | ||
} | ||
|
||
public func updateUIViewController(_ uiViewController: UIImagePickerController, context: Context) {} | ||
|
||
public func makeCoordinator() -> Coordinator { | ||
Coordinator( | ||
onDismiss: { self.presentationMode.wrappedValue.dismiss() }, | ||
onImagePicked: self.onImagePicked | ||
) | ||
} | ||
|
||
final public class Coordinator: NSObject, UINavigationControllerDelegate, UIImagePickerControllerDelegate { | ||
private let onDismiss: () -> Void | ||
private let onImagePicked: (UIImage) -> Void | ||
|
||
init(onDismiss: @escaping () -> Void, onImagePicked: @escaping (UIImage) -> Void) { | ||
self.onDismiss = onDismiss | ||
self.onImagePicked = onImagePicked | ||
} | ||
|
||
public func imagePickerController( | ||
_ picker: UIImagePickerController, | ||
didFinishPickingMediaWithInfo info: [UIImagePickerController.InfoKey: Any] | ||
) { | ||
if let image = info[.originalImage] as? UIImage { | ||
self.onImagePicked(image) | ||
} | ||
self.onDismiss() | ||
} | ||
|
||
public func imagePickerControllerDidCancel(_: UIImagePickerController) { | ||
self.onDismiss() | ||
} | ||
} | ||
} | ||
#endif |
Oops, something went wrong.