mirror of
https://github.com/NativeScript/NativeScript.git
synced 2025-08-16 03:31:45 +08:00
BCL: updated camera for iOS and camera definitions
This commit is contained in:
11
camera/Readme.md
Normal file
11
camera/Readme.md
Normal file
@ -0,0 +1,11 @@
|
||||
Sample usage:
|
||||
```
|
||||
var camera = require("camera");
|
||||
|
||||
camera.takePicture({"cameraPosition": camera.CameraPosition.BACK, "flashMode": camera.FlashMode.ON}).then(function (image) {
|
||||
console.log('pic taken - width: ' + image.width + ", height: " + image.height);
|
||||
}).fail(function (error) {
|
||||
console.log('pic canceled');
|
||||
});
|
||||
|
||||
```
|
@ -5,9 +5,9 @@ export enum CameraPosition {
|
||||
}
|
||||
|
||||
export enum FlashMode {
|
||||
OFF = -1,
|
||||
AUTO = 0, // default
|
||||
ON = 1,
|
||||
OFF = 2
|
||||
}
|
||||
|
||||
export interface Options {
|
||||
|
11
camera/camera.d.ts
vendored
11
camera/camera.d.ts
vendored
@ -23,6 +23,10 @@ declare module "camera" {
|
||||
* Specifies a camera flash mode.
|
||||
*/
|
||||
enum FlashMode {
|
||||
/**
|
||||
* The camera flash is disabled.
|
||||
*/
|
||||
OFF = -1,
|
||||
/**
|
||||
* Flash will be fired automatically when required.
|
||||
*/
|
||||
@ -31,14 +35,10 @@ declare module "camera" {
|
||||
* The camera flash is enabled.
|
||||
*/
|
||||
ON = 1,
|
||||
/**
|
||||
* The camera flash is disabled.
|
||||
*/
|
||||
OFF = 2
|
||||
}
|
||||
|
||||
/**
|
||||
* Camera options for capture an image.
|
||||
* Camera options for capture an image. Currently not guaranteed to be used on Android
|
||||
*/
|
||||
interface Options {
|
||||
/**
|
||||
@ -55,6 +55,7 @@ declare module "camera" {
|
||||
// TODO most of hardware related parts need to handle onPause and onResume of the calling activities
|
||||
|
||||
/**
|
||||
* TODO replace it with promise methods only and remove this class
|
||||
* This class provides access to the device camera and photo libraries.
|
||||
*/
|
||||
class CameraManager {
|
||||
|
@ -2,6 +2,11 @@
|
||||
import imageSource = require("image-source");
|
||||
import types = require("camera/camera-types");
|
||||
|
||||
// merge the exports of the types module with the exports of this file
|
||||
import merger = require("utils/module-merge");
|
||||
declare var exports;
|
||||
merger.merge(types, exports);
|
||||
|
||||
var imagePickerController;
|
||||
|
||||
export class CameraManager {
|
||||
@ -69,6 +74,19 @@ export var takePicture = function (options?: types.Options): promises.Promise<im
|
||||
imagePickerController.sourceType = UIKit.UIImagePickerControllerSourceType.UIImagePickerControllerSourceTypeCamera;
|
||||
imagePickerController.modalPresentationStyle = UIKit.UIModalPresentationStyle.UIModalPresentationCurrentContext;
|
||||
|
||||
if (options && ("undefined" !== typeof options.cameraPosition) && (types.CameraPosition.FRONT === options.cameraPosition)) {
|
||||
imagePickerController.cameraDevice = UIKit.UIImagePickerControllerCameraDevice.UIImagePickerControllerCameraDeviceFront;
|
||||
}
|
||||
|
||||
if (options && ("undefined" !== typeof options.flashMode)) {
|
||||
if (types.FlashMode.OFF === options.flashMode) {
|
||||
imagePickerController.cameraFlashMode = UIKit.UIImagePickerControllerCameraFlashMode.UIImagePickerControllerCameraFlashModeOff;
|
||||
}
|
||||
else if (types.FlashMode.ON === options.flashMode) {
|
||||
imagePickerController.cameraFlashMode = UIKit.UIImagePickerControllerCameraFlashMode.UIImagePickerControllerCameraFlashModeOn;
|
||||
}
|
||||
}
|
||||
|
||||
topViewController().presentViewControllerAnimatedCompletion(imagePickerController, true, null);
|
||||
|
||||
return d.promise();
|
||||
|
Reference in New Issue
Block a user