Skip to content

Commit f090ebc

Browse files
authored
docs: add additional plugin documentation from v2 site (#92)
1 parent 2d7127a commit f090ebc

File tree

22 files changed

+701
-8
lines changed

22 files changed

+701
-8
lines changed

action-sheet/README.md

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,33 @@ npm install @capacitor/action-sheet
99
npx cap sync
1010
```
1111

12+
## Example
13+
14+
```typescript
15+
import { ActionSheet, ActionSheetOptionStyle } from '@capacitor/action-sheet';
16+
17+
const showActions = async () => {
18+
const result = await ActionSheet.showActions({
19+
title: 'Photo Options',
20+
message: 'Select an option to perform',
21+
options: [
22+
{
23+
title: 'Upload',
24+
},
25+
{
26+
title: 'Share',
27+
},
28+
{
29+
title: 'Remove',
30+
style: ActionSheetOptionStyle.Destructive,
31+
},
32+
],
33+
});
34+
35+
console.log('Action Sheet result:', result);
36+
};
37+
```
38+
1239
## API
1340

1441
<docgen-index>

app-launcher/README.md

Lines changed: 23 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,22 @@ npm install @capacitor/app-launcher
99
npx cap sync
1010
```
1111

12+
## Example
13+
14+
```typescript
15+
import { AppLauncher } from '@capacitor/app-launcher';
16+
17+
const checkCanOpenUrl = async () => {
18+
const { value } = await AppLauncher.canOpenUrl({ url: 'com.getcapacitor.myapp' });
19+
20+
alert('Can open url: ', value);
21+
};
22+
23+
const openPortfolioPage = async () => {
24+
await AppLauncher.openUrl({ url: 'com.getcapacitor.myapp://page?id=portfolio' });
25+
};
26+
```
27+
1228
## API
1329

1430
<docgen-index>
@@ -30,10 +46,13 @@ canOpenUrl(options: CanOpenURLOptions) => Promise<CanOpenURLResult>
3046

3147
Check if an app can be opened with the given URL.
3248

33-
On iOS you must declare the URL schemes you pass to this method by adding
34-
the LSApplicationQueriesSchemes key to your app's Info.plist file.
35-
This method always returns false for undeclared schemes, whether or not an appropriate
36-
app is installed. To learn more about the key, see
49+
On iOS you must declare the URL schemes you pass to this method by adding
50+
the `LSApplicationQueriesSchemes` key to your app's `Info.plist` file.
51+
Learn more about configuring
52+
[`Info.plist`](https://capacitorjs.com/docs/ios/configuration#configuring-infoplist).
53+
54+
This method always returns false for undeclared schemes, whether or not an
55+
appropriate app is installed. To learn more about the key, see
3756
[LSApplicationQueriesSchemes](https://developer.apple.com/library/archive/documentation/General/Reference/InfoPlistKeyReference/Articles/LaunchServicesKeys.html#//apple_ref/doc/plist/info/LSApplicationQueriesSchemes).
3857

3958
| Param | Type |

app-launcher/src/definitions.ts

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,13 @@ export interface AppLauncherPlugin {
22
/**
33
* Check if an app can be opened with the given URL.
44
*
5-
* On iOS you must declare the URL schemes you pass to this method by adding
6-
* the LSApplicationQueriesSchemes key to your app's Info.plist file.
7-
* This method always returns false for undeclared schemes, whether or not an appropriate
8-
* app is installed. To learn more about the key, see
5+
* On iOS you must declare the URL schemes you pass to this method by adding
6+
* the `LSApplicationQueriesSchemes` key to your app's `Info.plist` file.
7+
* Learn more about configuring
8+
* [`Info.plist`](https://capacitorjs.com/docs/ios/configuration#configuring-infoplist).
9+
*
10+
* This method always returns false for undeclared schemes, whether or not an
11+
* appropriate app is installed. To learn more about the key, see
912
* [LSApplicationQueriesSchemes](https://developer.apple.com/library/archive/documentation/General/Reference/InfoPlistKeyReference/Articles/LaunchServicesKeys.html#//apple_ref/doc/plist/info/LSApplicationQueriesSchemes).
1013
*
1114
* @since 1.0.0

app/README.md

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,30 @@ npm install @capacitor/app
99
npx cap sync
1010
```
1111

12+
## Example
13+
14+
```typescript
15+
import { App } from '@capacitor/app';
16+
17+
App.addListener('appStateChange', ({ isActive }) => {
18+
console.log('App state changed. Is active?', isActive);
19+
});
20+
21+
App.addListener('appUrlOpen', data => {
22+
console.log('App opened with URL:', data);
23+
});
24+
25+
App.addListener('appRestoredResult', data => {
26+
console.log('Restored state:', data);
27+
});
28+
29+
const checkAppLaunchUrl = async () => {
30+
const { url } = await App.getLaunchUrl();
31+
32+
alert('App opened with URL: ' + url);
33+
};
34+
```
35+
1236
## API
1337

1438
<docgen-index>
@@ -144,6 +168,24 @@ If the app was launched with previously persisted plugin call data, such as on A
144168
when an activity returns to an app that was closed, this call will return any data
145169
the app was launched with, converted into the form of a result from a plugin call.
146170

171+
On Android, due to memory constraints on low-end devices, it's possible
172+
that, if your app launches a new activity, your app will be terminated by
173+
the operating system in order to reduce memory consumption.
174+
175+
For example, that means the Camera API, which launches a new Activity to
176+
take a photo, may not be able to return data back to your app.
177+
178+
To avoid this, Capacitor stores all restored activity results on launch.
179+
You should add a listener for `appRestoredResult` in order to handle any
180+
plugin call results that were delivered when your app was not running.
181+
182+
Once you have that result (if any), you can update the UI to restore a
183+
logical experience for the user, such as navigating or selecting the
184+
proper tab.
185+
186+
We recommend every Android app using plugins that rely on external
187+
Activities (for example, Camera) to have this event and process handled.
188+
147189
| Param | Type |
148190
| ------------------ | ------------------------------------------------------------- |
149191
| **`eventName`** | <code>'appRestoredResult'</code> |

app/src/definitions.ts

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -178,6 +178,24 @@ export interface AppPlugin {
178178
* when an activity returns to an app that was closed, this call will return any data
179179
* the app was launched with, converted into the form of a result from a plugin call.
180180
*
181+
* On Android, due to memory constraints on low-end devices, it's possible
182+
* that, if your app launches a new activity, your app will be terminated by
183+
* the operating system in order to reduce memory consumption.
184+
*
185+
* For example, that means the Camera API, which launches a new Activity to
186+
* take a photo, may not be able to return data back to your app.
187+
*
188+
* To avoid this, Capacitor stores all restored activity results on launch.
189+
* You should add a listener for `appRestoredResult` in order to handle any
190+
* plugin call results that were delivered when your app was not running.
191+
*
192+
* Once you have that result (if any), you can update the UI to restore a
193+
* logical experience for the user, such as navigating or selecting the
194+
* proper tab.
195+
*
196+
* We recommend every Android app using plugins that rely on external
197+
* Activities (for example, Camera) to have this event and process handled.
198+
*
181199
* @since 1.0.0
182200
*/
183201
addListener(

browser/README.md

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,25 @@
22

33
The Browser API provides the ability to open an in-app browser and subscribe to browser events.
44

5+
On iOS, this uses `SFSafariViewController` and is compliant with leading OAuth service in-app-browser requirements.
6+
57
## Install
68

79
```bash
810
npm install @capacitor/browser
911
npx cap sync
1012
```
1113

14+
## Example
15+
16+
```typescript
17+
import { Browser } from '@capacitor/browser';
18+
19+
const openCapacitorSite = async () => {
20+
await Browser.open({ url: 'http://capacitorjs.com/' });
21+
};
22+
```
23+
1224
## API
1325

1426
<docgen-index>

camera/README.md

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,58 @@ npm install @capacitor/camera
99
npx cap sync
1010
```
1111

12+
## iOS Notes
13+
14+
iOS requires the following usage description be added and filled out for your app in `Info.plist`:
15+
16+
- `NSCameraUsageDescription` (`Privacy - Camera Usage Description`)
17+
- `NSPhotoLibraryAddUsageDescription` (`Privacy - Photo Library Additions Usage Description`)
18+
- `NSPhotoLibraryUsageDescription` (`Privacy - Photo Library Usage Description`)
19+
20+
Read about [Configuring `Info.plist`](https://capacitorjs.com/docs/ios/configuration#configuring-infoplist) in the [iOS Guide](https://capacitorjs.com/docs/ios) for more information on setting iOS permissions in Xcode
21+
22+
## Android Notes
23+
24+
This API requires the following permissions be added to your `AndroidManifest.xml`:
25+
26+
```xml
27+
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE"/>
28+
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
29+
```
30+
31+
The storage permissions are for reading/saving photo files.
32+
33+
Read about [Setting Permissions](https://capacitorjs.com/docs/android/configuration#setting-permissions) in the [Android Guide](https://capacitorjs.com/docs/android) for more information on setting Android permissions.
34+
35+
Additionally, because the Camera API launches a separate Activity to handle taking the photo, you should listen for `appRestoredResult` in the `App` plugin to handle any camera data that was sent in the case your app was terminated by the operating system while the Activity was running.
36+
37+
## PWA Notes
38+
39+
[PWA Elements](https://capacitorjs.com/docs/web/pwa-elements) are required for Camera plugin to work.
40+
41+
## Example
42+
43+
```typescript
44+
import { Camera, CameraResultType } from '@capacitor/camera';
45+
46+
const takePicture = async () {
47+
const image = await Camera.getPhoto({
48+
quality: 90,
49+
allowEditing: true,
50+
resultType: CameraResultType.Uri
51+
});
52+
53+
// image.webPath will contain a path that can be set as an image src.
54+
// You can access the original file using image.path, which can be
55+
// passed to the Filesystem API to read the raw data of the image,
56+
// if desired (or pass resultType: CameraResultType.Base64 to getPhoto)
57+
var imageUrl = image.webPath;
58+
59+
// Can be set to the src of an image now
60+
imageElement.src = imageUrl;
61+
};
62+
```
63+
1264
## API
1365

1466
<docgen-index>

clipboard/README.md

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,24 @@ npm install @capacitor/clipboard
99
npx cap sync
1010
```
1111

12+
## Example
13+
14+
```typescript
15+
import { Clipboard } from '@capacitor/clipboard';
16+
17+
const writeToClipboard = async () => {
18+
await Clipboard.write({
19+
string: "Hello World!"
20+
});
21+
};
22+
23+
const checkClipboard = async () => {
24+
const { type, value } = await Clipboard.read();
25+
26+
alert(`Got ${type} from clipboard: ${value}`);
27+
};
28+
```
29+
1230
## API
1331

1432
<docgen-index>

device/README.md

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,24 @@ npm install @capacitor/device
99
npx cap sync
1010
```
1111

12+
## Example
13+
14+
```typescript
15+
import { Device } from '@capacitor/device';
16+
17+
const logDeviceInfo = async () => {
18+
const info = await Device.getInfo();
19+
20+
console.log(info);
21+
};
22+
23+
const logBatteryInfo = async () => {
24+
const info = await Device.getBatteryInfo();
25+
26+
console.log(info);
27+
};
28+
```
29+
1230
## API
1331

1432
<docgen-index>

dialog/README.md

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,38 @@ npm install @capacitor/dialog
99
npx cap sync
1010
```
1111

12+
## Example
13+
14+
```typescript
15+
import { Dialog } from '@capacitor/dialog';
16+
17+
const showAlert = async () => {
18+
await Dialog.alert({
19+
title: 'Stop',
20+
message: 'this is an error',
21+
});
22+
};
23+
24+
const showConfirm = async () => {
25+
const { value } = await Dialog.confirm({
26+
title: 'Confirm',
27+
message: `Are you sure you'd like to press the red button?`,
28+
});
29+
30+
console.log('Confirmed:', value);
31+
};
32+
33+
const showPrompt = async () => {
34+
const { value, cancelled } = await Dialog.prompt({
35+
title: 'Hello',
36+
message: `What's your name?`,
37+
});
38+
39+
console.log('Name:', value);
40+
console.log('Cancelled:', cancelled);
41+
};
42+
```
43+
1244
## API
1345

1446
<docgen-index>

0 commit comments

Comments
 (0)