Skip to content

Commit 4864928

Browse files
ikeithcarlpoolejcesarmobileimhoffd
authored
feat: Camera plugin (#33)
Co-authored-by: Carl Poole <[email protected]> Co-authored-by: jcesarmobile <[email protected]> Co-authored-by: Dan Imhoff <[email protected]>
1 parent 26625cf commit 4864928

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

49 files changed

+3942
-0
lines changed

camera/.eslintignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
build
2+
dist

camera/.gitignore

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
# node files
2+
dist
3+
node_modules
4+
5+
# iOS files
6+
Pods
7+
Podfile.lock
8+
Build
9+
xcuserdata
10+
11+
# macOS files
12+
.DS_Store
13+
14+
15+
16+
# Based on Android gitignore template: https://github.com/github/gitignore/blob/HEAD/Android.gitignore
17+
18+
# Built application files
19+
*.apk
20+
*.ap_
21+
22+
# Files for the ART/Dalvik VM
23+
*.dex
24+
25+
# Java class files
26+
*.class
27+
28+
# Generated files
29+
bin
30+
gen
31+
out
32+
33+
# Gradle files
34+
.gradle
35+
build
36+
37+
# Local configuration file (sdk path, etc)
38+
local.properties
39+
40+
# Proguard folder generated by Eclipse
41+
proguard
42+
43+
# Log Files
44+
*.log
45+
46+
# Android Studio Navigation editor temp files
47+
.navigation
48+
49+
# Android Studio captures folder
50+
captures
51+
52+
# IntelliJ
53+
*.iml
54+
.idea
55+
56+
# Keystore files
57+
# Uncomment the following line if you do not want to check your keystore files in.
58+
#*.jks
59+
60+
# External native build folder generated in Android Studio 2.2 and later
61+
.externalNativeBuild

camera/.prettierignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
build
2+
dist

camera/CapacitorCamera.podspec

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
require 'json'
2+
3+
package = JSON.parse(File.read(File.join(__dir__, 'package.json')))
4+
5+
Pod::Spec.new do |s|
6+
s.name = 'CapacitorCamera'
7+
s.version = package['version']
8+
s.summary = package['description']
9+
s.license = package['license']
10+
s.homepage = package['repository']['url']
11+
s.author = package['author']
12+
s.source = { :git => package['repository']['url'], :tag => s.version.to_s }
13+
s.source_files = 'ios/Plugin/**/*.{swift,h,m,c,cc,mm,cpp}'
14+
s.ios.deployment_target = '11.0'
15+
s.dependency 'Capacitor'
16+
s.swift_version = '5.1'
17+
end

camera/LICENSE

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
Copyright 2020-present Ionic
2+
https://ionic.io
3+
4+
MIT License
5+
6+
Permission is hereby granted, free of charge, to any person obtaining
7+
a copy of this software and associated documentation files (the
8+
"Software"), to deal in the Software without restriction, including
9+
without limitation the rights to use, copy, modify, merge, publish,
10+
distribute, sublicense, and/or sell copies of the Software, and to
11+
permit persons to whom the Software is furnished to do so, subject to
12+
the following conditions:
13+
14+
The above copyright notice and this permission notice shall be
15+
included in all copies or substantial portions of the Software.
16+
17+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
18+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
19+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
20+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
21+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
22+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
23+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

camera/README.md

Lines changed: 165 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,165 @@
1+
# @capacitor/camera
2+
3+
The Camera API provides the ability to take a photo with the camera or choose an existing one from the photo album.
4+
5+
## Install
6+
7+
```bash
8+
npm install @capacitor/camera
9+
npx cap sync
10+
```
11+
12+
## API
13+
14+
<docgen-index>
15+
16+
* [`getPhoto(...)`](#getphoto)
17+
* [`checkPermissions()`](#checkpermissions)
18+
* [`requestPermissions(...)`](#requestpermissions)
19+
* [Interfaces](#interfaces)
20+
* [Type Aliases](#type-aliases)
21+
22+
</docgen-index>
23+
24+
<docgen-api>
25+
<!--Update the source file JSDoc comments and rerun docgen to update the docs below-->
26+
27+
### getPhoto(...)
28+
29+
```typescript
30+
getPhoto(options: CameraOptions) => Promise<CameraPhoto>
31+
```
32+
33+
Prompt the user to pick a photo from an album, or take a new photo
34+
with the camera.
35+
36+
| Param | Type |
37+
| ------------- | ------------------------------------------------------- |
38+
| **`options`** | <code><a href="#cameraoptions">CameraOptions</a></code> |
39+
40+
**Returns:** <code>Promise&lt;<a href="#cameraphoto">CameraPhoto</a>&gt;</code>
41+
42+
**Since:** 1.0.0
43+
44+
--------------------
45+
46+
47+
### checkPermissions()
48+
49+
```typescript
50+
checkPermissions() => Promise<CameraPermissionStatus>
51+
```
52+
53+
Check camera and photo album permissions
54+
55+
**Returns:** <code>Promise&lt;<a href="#camerapermissionstatus">CameraPermissionStatus</a>&gt;</code>
56+
57+
**Since:** 1.0.0
58+
59+
--------------------
60+
61+
62+
### requestPermissions(...)
63+
64+
```typescript
65+
requestPermissions(permissions?: CameraPluginPermissions | undefined) => Promise<CameraPermissionStatus>
66+
```
67+
68+
Request camera and photo album permissions
69+
70+
| Param | Type |
71+
| ----------------- | --------------------------------------------------------------------------- |
72+
| **`permissions`** | <code><a href="#camerapluginpermissions">CameraPluginPermissions</a></code> |
73+
74+
**Returns:** <code>Promise&lt;<a href="#camerapermissionstatus">CameraPermissionStatus</a>&gt;</code>
75+
76+
**Since:** 1.0.0
77+
78+
--------------------
79+
80+
81+
### Interfaces
82+
83+
84+
#### CameraPhoto
85+
86+
| Prop | Type | Description | Since |
87+
| ------------------ | ------------------- | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | ----- |
88+
| **`base64String`** | <code>string</code> | The base64 encoded string representation of the image, if using <a href="#cameraresulttype">CameraResultType</a>.Base64. | 1.0.0 |
89+
| **`dataUrl`** | <code>string</code> | The url starting with 'data:image/jpeg;base64,' and the base64 encoded string representation of the image, if using <a href="#cameraresulttype">CameraResultType</a>.DataUrl. | 1.0.0 |
90+
| **`path`** | <code>string</code> | If using <a href="#cameraresulttype">CameraResultType</a>.Uri, the path will contain a full, platform-specific file URL that can be read later using the Filsystem API. | 1.0.0 |
91+
| **`webPath`** | <code>string</code> | webPath returns a path that can be used to set the src attribute of an image for efficient loading and rendering. | 1.0.0 |
92+
| **`exif`** | <code>any</code> | Exif data, if any, retrieved from the image | 1.0.0 |
93+
| **`format`** | <code>string</code> | The format of the image, ex: jpeg, png, gif. iOS and Android only support jpeg. Web supports jpeg and png. gif is only supported if using file input. | 1.0.0 |
94+
95+
96+
#### CameraOptions
97+
98+
| Prop | Type | Description | Default | Since |
99+
| ------------------------- | ------------------------------------------------------------- | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | ----------------------------------- | ----- |
100+
| **`quality`** | <code>number</code> | The quality of image to return as JPEG, from 0-100 | | 1.0.0 |
101+
| **`allowEditing`** | <code>boolean</code> | Whether to allow the user to crop or make small edits (platform specific) | | 1.0.0 |
102+
| **`resultType`** | <code><a href="#cameraresulttype">CameraResultType</a></code> | How the data should be returned. Currently, only 'Base64', 'DataUrl' or 'Uri' is supported | | 1.0.0 |
103+
| **`saveToGallery`** | <code>boolean</code> | Whether to save the photo to the gallery. If the photo was picked from the gallery, it will only be saved if edited. | <code>: false</code> | 1.0.0 |
104+
| **`width`** | <code>number</code> | The width of the saved image | | 1.0.0 |
105+
| **`height`** | <code>number</code> | The height of the saved image | | 1.0.0 |
106+
| **`preserveAspectRatio`** | <code>boolean</code> | Whether to preserve the aspect ratio of the image. If this flag is true, the width and height will be used as max values and the aspect ratio will be preserved. This is only relevant when both a width and height are passed. When only width or height is provided the aspect ratio is always preserved (and this option is a no-op). A future major version will change this behavior to be default, and may also remove this option altogether. | <code>: false</code> | 1.0.0 |
107+
| **`correctOrientation`** | <code>boolean</code> | Whether to automatically rotate the image "up" to correct for orientation in portrait mode | <code>: true</code> | 1.0.0 |
108+
| **`source`** | <code><a href="#camerasource">CameraSource</a></code> | The source to get the photo from. By default this prompts the user to select either the photo album or take a photo. | <code>: CameraSource.prompt</code> | 1.0.0 |
109+
| **`direction`** | <code><a href="#cameradirection">CameraDirection</a></code> | iOS and Web only: The camera direction. | <code>: CameraDirection.rear</code> | 1.0.0 |
110+
| **`presentationStyle`** | <code>'fullscreen' \| 'popover'</code> | iOS only: The presentation style of the Camera. | <code>: 'fullscreen'</code> | 1.0.0 |
111+
| **`webUseInput`** | <code>boolean</code> | Web only: Whether to use the PWA Element experience or file input. The default is to use PWA Elements if installed and fall back to file input. To always use file input, set this to `true`. Learn more about PWA Elements: https://capacitorjs.com/docs/pwa-elements | | 1.0.0 |
112+
| **`promptLabelHeader`** | <code>string</code> | Text value to use when displaying the prompt. iOS only: The title of the action sheet. | <code>: 'Photo'</code> | 1.0.0 |
113+
| **`promptLabelCancel`** | <code>string</code> | Text value to use when displaying the prompt. iOS only: The label of the 'cancel' button. | <code>: 'Cancel'</code> | 1.0.0 |
114+
| **`promptLabelPhoto`** | <code>string</code> | Text value to use when displaying the prompt. The label of the button to select a saved image. | <code>: 'From Photos'</code> | 1.0.0 |
115+
| **`promptLabelPicture`** | <code>string</code> | Text value to use when displaying the prompt. The label of the button to open the camera. | <code>: 'Take Picture'</code> | 1.0.0 |
116+
117+
118+
#### CameraPermissionStatus
119+
120+
| Prop | Type |
121+
| ------------ | ----------------------------------------------------------------------- |
122+
| **`camera`** | <code><a href="#camerapermissionstate">CameraPermissionState</a></code> |
123+
| **`photos`** | <code><a href="#camerapermissionstate">CameraPermissionState</a></code> |
124+
125+
126+
#### CameraPluginPermissions
127+
128+
| Prop | Type |
129+
| ----------------- | ----------------------------------- |
130+
| **`permissions`** | <code>CameraPermissionType[]</code> |
131+
132+
133+
### Type Aliases
134+
135+
136+
#### CameraResultType
137+
138+
<code>'uri' | 'base64' | 'dataUrl'</code>
139+
140+
141+
#### CameraSource
142+
143+
<code>'prompt' | 'camera' | 'photos'</code>
144+
145+
146+
#### CameraDirection
147+
148+
<code>'rear' | 'front'</code>
149+
150+
151+
#### CameraPermissionState
152+
153+
<code><a href="#permissionstate">PermissionState</a> | 'limited'</code>
154+
155+
156+
#### PermissionState
157+
158+
<code>'prompt' | 'prompt-with-rationale' | 'granted' | 'denied'</code>
159+
160+
161+
#### CameraPermissionType
162+
163+
<code>'camera' | 'photos'</code>
164+
165+
</docgen-api>

camera/android/.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
/build

0 commit comments

Comments
 (0)