Pushing files

This commit is contained in:
Lochlan Wansbrough 2015-03-31 18:02:57 -07:00
parent 557fc86940
commit 296f190645
10 changed files with 517 additions and 0 deletions

61
Camera.ios.js Normal file
View File

@ -0,0 +1,61 @@
var React = require('React');
var NativeModules = require('NativeModules');
var ReactIOSViewAttributes = require('ReactIOSViewAttributes');
var StyleSheet = require('StyleSheet');
var createReactIOSNativeComponentClass = require('createReactIOSNativeComponentClass');
var PropTypes = require('ReactPropTypes');
var StyleSheetPropType = require('StyleSheetPropType');
var NativeMethodsMixin = require('NativeMethodsMixin');
var flattenStyle = require('flattenStyle');
var merge = require('merge');
var Camera = React.createClass({
propTypes: {
orientation: PropTypes.integer,
},
mixins: [NativeMethodsMixin],
viewConfig: {
uiViewClassName: 'UIView',
validAttributes: ReactIOSViewAttributes.UIView
},
getInitialState: function() {
return {
isAuthorized: false
};
},
componentWillMount: function() {
NativeModules.CameraManager.checkDeviceAuthorizationStatus((function(err, isAuthorized) {
this.state.isAuthorized = isAuthorized;
this.setState(this.state);
}).bind(this));
},
render: function() {
var style = flattenStyle([styles.base, this.props.style]);
var orientation = this.props.orientation;
var nativeProps = merge(this.props, {
style,
orientation: orientation,
});
return <RCTCamera {... nativeProps} />
},
});
var RCTCamera = createReactIOSNativeComponentClass({
validAttributes: merge(ReactIOSViewAttributes.UIView, { orientation: true }),
uiViewClassName: 'RCTCamera',
});
var styles = StyleSheet.create({
base: {
overflow: 'hidden'
},
});
module.exports = Camera;

11
RCTCamera.h Normal file
View File

@ -0,0 +1,11 @@
#import <UIKit/UIKit.h>
#import "ViewfinderView.h"
@class AVCaptureSession;
@interface RCTCamera : UIView
@property (nonatomic) AVCaptureSession *session;
@property (nonatomic) ViewfinderView *viewfinder;
@end

85
RCTCamera.m Normal file
View File

@ -0,0 +1,85 @@
#import "RCTCamera.h"
#import "RCTLog.h"
#import "ViewfinderView.h"
#import <AVFoundation/AVFoundation.h>
@implementation RCTCamera
- (void)setSrc:(NSString *)source
{
}
- (id)init
{
if ((self = [super init])) {
_viewfinder = [[ViewfinderView alloc] init];
AVCaptureSession *session = [[AVCaptureSession alloc] init];
[[self viewfinder] setSession:session];
[self addSubview:_viewfinder];
NSError *error = nil;
NSArray *devices = [AVCaptureDevice devicesWithMediaType:AVMediaTypeVideo];
AVCaptureDevice *captureDevice = [devices firstObject];
AVCaptureDevicePosition position = AVCaptureDevicePositionBack;
AVCaptureVideoOrientation interfaceOrientation = (AVCaptureVideoOrientation)UIInterfaceOrientationMaskLandscape;
for (AVCaptureDevice *device in devices)
{
if ([device position] == position)
{
captureDevice = device;
break;
}
}
AVCaptureDeviceInput *captureDeviceInput = [AVCaptureDeviceInput deviceInputWithDevice:captureDevice error:&error];
if (error)
{
NSLog(@"%@", error);
}
if ([session canAddInput:captureDeviceInput])
{
[session addInput:captureDeviceInput];
// [[(AVCaptureVideoPreviewLayer *)[[self viewfinder] layer] connection] setVideoOrientation:(AVCaptureVideoOrientation)interfaceOrientation];
[(AVCaptureVideoPreviewLayer *)[[self viewfinder] layer] setVideoGravity:AVLayerVideoGravityResizeAspectFill];
}
[session startRunning];
}
return self;
}
- (NSArray *)reactSubviews
{
NSArray *subviews = @[_viewfinder];
return subviews;
}
- (void)layoutSubviews
{
[super layoutSubviews];
_viewfinder.frame = self.bounds;
}
- (void)insertReactSubview:(UIView *)view atIndex:(NSInteger)atIndex
{
RCTLogError(@"Camera does not support subviews");
return;
}
- (void)removeReactSubview:(UIView *)subview
{
RCTLogError(@"Camera does not support subviews");
return;
}
@end

View File

@ -0,0 +1,248 @@
// !$*UTF8*$!
{
archiveVersion = 1;
classes = {
};
objectVersion = 46;
objects = {
/* Begin PBXBuildFile section */
4107014D1ACB732B00C6AA39 /* RCTCamera.m in Sources */ = {isa = PBXBuildFile; fileRef = 410701481ACB732B00C6AA39 /* RCTCamera.m */; };
4107014E1ACB732B00C6AA39 /* RCTCameraManager.m in Sources */ = {isa = PBXBuildFile; fileRef = 4107014A1ACB732B00C6AA39 /* RCTCameraManager.m */; };
4107014F1ACB732B00C6AA39 /* ViewfinderView.m in Sources */ = {isa = PBXBuildFile; fileRef = 4107014C1ACB732B00C6AA39 /* ViewfinderView.m */; };
/* End PBXBuildFile section */
/* Begin PBXCopyFilesBuildPhase section */
4107012D1ACB723B00C6AA39 /* CopyFiles */ = {
isa = PBXCopyFilesBuildPhase;
buildActionMask = 2147483647;
dstPath = "include/$(PRODUCT_NAME)";
dstSubfolderSpec = 16;
files = (
);
runOnlyForDeploymentPostprocessing = 0;
};
/* End PBXCopyFilesBuildPhase section */
/* Begin PBXFileReference section */
4107012F1ACB723B00C6AA39 /* libRCTCamera.a */ = {isa = PBXFileReference; explicitFileType = archive.ar; includeInIndex = 0; path = libRCTCamera.a; sourceTree = BUILT_PRODUCTS_DIR; };
410701471ACB732B00C6AA39 /* RCTCamera.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = RCTCamera.h; sourceTree = "<group>"; };
410701481ACB732B00C6AA39 /* RCTCamera.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = RCTCamera.m; sourceTree = "<group>"; };
410701491ACB732B00C6AA39 /* RCTCameraManager.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = RCTCameraManager.h; sourceTree = "<group>"; };
4107014A1ACB732B00C6AA39 /* RCTCameraManager.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = RCTCameraManager.m; sourceTree = "<group>"; };
4107014B1ACB732B00C6AA39 /* ViewfinderView.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = ViewfinderView.h; sourceTree = "<group>"; };
4107014C1ACB732B00C6AA39 /* ViewfinderView.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = ViewfinderView.m; sourceTree = "<group>"; };
/* End PBXFileReference section */
/* Begin PBXFrameworksBuildPhase section */
4107012C1ACB723B00C6AA39 /* Frameworks */ = {
isa = PBXFrameworksBuildPhase;
buildActionMask = 2147483647;
files = (
);
runOnlyForDeploymentPostprocessing = 0;
};
/* End PBXFrameworksBuildPhase section */
/* Begin PBXGroup section */
410701241ACB719800C6AA39 = {
isa = PBXGroup;
children = (
410701471ACB732B00C6AA39 /* RCTCamera.h */,
410701481ACB732B00C6AA39 /* RCTCamera.m */,
410701491ACB732B00C6AA39 /* RCTCameraManager.h */,
4107014A1ACB732B00C6AA39 /* RCTCameraManager.m */,
4107014B1ACB732B00C6AA39 /* ViewfinderView.h */,
4107014C1ACB732B00C6AA39 /* ViewfinderView.m */,
410701301ACB723B00C6AA39 /* Products */,
);
sourceTree = "<group>";
};
410701301ACB723B00C6AA39 /* Products */ = {
isa = PBXGroup;
children = (
4107012F1ACB723B00C6AA39 /* libRCTCamera.a */,
);
name = Products;
sourceTree = "<group>";
};
/* End PBXGroup section */
/* Begin PBXNativeTarget section */
4107012E1ACB723B00C6AA39 /* RCTCamera */ = {
isa = PBXNativeTarget;
buildConfigurationList = 410701411ACB723B00C6AA39 /* Build configuration list for PBXNativeTarget "RCTCamera" */;
buildPhases = (
4107012B1ACB723B00C6AA39 /* Sources */,
4107012C1ACB723B00C6AA39 /* Frameworks */,
4107012D1ACB723B00C6AA39 /* CopyFiles */,
);
buildRules = (
);
dependencies = (
);
name = RCTCamera;
productName = RCTCamera;
productReference = 4107012F1ACB723B00C6AA39 /* libRCTCamera.a */;
productType = "com.apple.product-type.library.static";
};
/* End PBXNativeTarget section */
/* Begin PBXProject section */
410701251ACB719800C6AA39 /* Project object */ = {
isa = PBXProject;
attributes = {
LastUpgradeCheck = 0620;
TargetAttributes = {
4107012E1ACB723B00C6AA39 = {
CreatedOnToolsVersion = 6.2;
};
};
};
buildConfigurationList = 410701281ACB719800C6AA39 /* Build configuration list for PBXProject "RCTCamera" */;
compatibilityVersion = "Xcode 3.2";
developmentRegion = English;
hasScannedForEncodings = 0;
knownRegions = (
en,
);
mainGroup = 410701241ACB719800C6AA39;
productRefGroup = 410701301ACB723B00C6AA39 /* Products */;
projectDirPath = "";
projectRoot = "";
targets = (
4107012E1ACB723B00C6AA39 /* RCTCamera */,
);
};
/* End PBXProject section */
/* Begin PBXSourcesBuildPhase section */
4107012B1ACB723B00C6AA39 /* Sources */ = {
isa = PBXSourcesBuildPhase;
buildActionMask = 2147483647;
files = (
4107014E1ACB732B00C6AA39 /* RCTCameraManager.m in Sources */,
4107014D1ACB732B00C6AA39 /* RCTCamera.m in Sources */,
4107014F1ACB732B00C6AA39 /* ViewfinderView.m in Sources */,
);
runOnlyForDeploymentPostprocessing = 0;
};
/* End PBXSourcesBuildPhase section */
/* Begin XCBuildConfiguration section */
410701291ACB719800C6AA39 /* Debug */ = {
isa = XCBuildConfiguration;
buildSettings = {
};
name = Debug;
};
4107012A1ACB719800C6AA39 /* Release */ = {
isa = XCBuildConfiguration;
buildSettings = {
};
name = Release;
};
410701421ACB723B00C6AA39 /* Debug */ = {
isa = XCBuildConfiguration;
buildSettings = {
ALWAYS_SEARCH_USER_PATHS = NO;
CLANG_CXX_LANGUAGE_STANDARD = "gnu++0x";
CLANG_CXX_LIBRARY = "libc++";
CLANG_ENABLE_MODULES = YES;
CLANG_ENABLE_OBJC_ARC = YES;
CLANG_WARN_BOOL_CONVERSION = YES;
CLANG_WARN_CONSTANT_CONVERSION = YES;
CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR;
CLANG_WARN_EMPTY_BODY = YES;
CLANG_WARN_ENUM_CONVERSION = YES;
CLANG_WARN_INT_CONVERSION = YES;
CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR;
CLANG_WARN_UNREACHABLE_CODE = YES;
CLANG_WARN__DUPLICATE_METHOD_MATCH = YES;
COPY_PHASE_STRIP = NO;
ENABLE_STRICT_OBJC_MSGSEND = YES;
GCC_C_LANGUAGE_STANDARD = gnu99;
GCC_DYNAMIC_NO_PIC = NO;
GCC_OPTIMIZATION_LEVEL = 0;
GCC_PREPROCESSOR_DEFINITIONS = (
"DEBUG=1",
"$(inherited)",
);
GCC_SYMBOLS_PRIVATE_EXTERN = NO;
GCC_WARN_64_TO_32_BIT_CONVERSION = YES;
GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR;
GCC_WARN_UNDECLARED_SELECTOR = YES;
GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE;
GCC_WARN_UNUSED_FUNCTION = YES;
GCC_WARN_UNUSED_VARIABLE = YES;
IPHONEOS_DEPLOYMENT_TARGET = 8.2;
MTL_ENABLE_DEBUG_INFO = YES;
ONLY_ACTIVE_ARCH = YES;
OTHER_LDFLAGS = "-ObjC";
PRODUCT_NAME = "$(TARGET_NAME)";
SDKROOT = iphoneos;
SKIP_INSTALL = YES;
};
name = Debug;
};
410701431ACB723B00C6AA39 /* Release */ = {
isa = XCBuildConfiguration;
buildSettings = {
ALWAYS_SEARCH_USER_PATHS = NO;
CLANG_CXX_LANGUAGE_STANDARD = "gnu++0x";
CLANG_CXX_LIBRARY = "libc++";
CLANG_ENABLE_MODULES = YES;
CLANG_ENABLE_OBJC_ARC = YES;
CLANG_WARN_BOOL_CONVERSION = YES;
CLANG_WARN_CONSTANT_CONVERSION = YES;
CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR;
CLANG_WARN_EMPTY_BODY = YES;
CLANG_WARN_ENUM_CONVERSION = YES;
CLANG_WARN_INT_CONVERSION = YES;
CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR;
CLANG_WARN_UNREACHABLE_CODE = YES;
CLANG_WARN__DUPLICATE_METHOD_MATCH = YES;
COPY_PHASE_STRIP = NO;
ENABLE_NS_ASSERTIONS = NO;
ENABLE_STRICT_OBJC_MSGSEND = YES;
GCC_C_LANGUAGE_STANDARD = gnu99;
GCC_WARN_64_TO_32_BIT_CONVERSION = YES;
GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR;
GCC_WARN_UNDECLARED_SELECTOR = YES;
GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE;
GCC_WARN_UNUSED_FUNCTION = YES;
GCC_WARN_UNUSED_VARIABLE = YES;
IPHONEOS_DEPLOYMENT_TARGET = 8.2;
MTL_ENABLE_DEBUG_INFO = NO;
OTHER_LDFLAGS = "-ObjC";
PRODUCT_NAME = "$(TARGET_NAME)";
SDKROOT = iphoneos;
SKIP_INSTALL = YES;
VALIDATE_PRODUCT = YES;
};
name = Release;
};
/* End XCBuildConfiguration section */
/* Begin XCConfigurationList section */
410701281ACB719800C6AA39 /* Build configuration list for PBXProject "RCTCamera" */ = {
isa = XCConfigurationList;
buildConfigurations = (
410701291ACB719800C6AA39 /* Debug */,
4107012A1ACB719800C6AA39 /* Release */,
);
defaultConfigurationIsVisible = 0;
defaultConfigurationName = Release;
};
410701411ACB723B00C6AA39 /* Build configuration list for PBXNativeTarget "RCTCamera" */ = {
isa = XCConfigurationList;
buildConfigurations = (
410701421ACB723B00C6AA39 /* Debug */,
410701431ACB723B00C6AA39 /* Release */,
);
defaultConfigurationIsVisible = 0;
};
/* End XCConfigurationList section */
};
rootObject = 410701251ACB719800C6AA39 /* Project object */;
}

4
RCTCameraManager.h Normal file
View File

@ -0,0 +1,4 @@
#import "RCTViewManager.h"
@interface RCTCameraManager : RCTViewManager
@end

27
RCTCameraManager.m Normal file
View File

@ -0,0 +1,27 @@
#import "RCTCameraManager.h"
#import "RCTCamera.h"
#import "RCTBridge.h"
#import <AVFoundation/AVFoundation.h>
@implementation RCTCameraManager
@synthesize bridge = _bridge;
- (UIView *)view
{
return [[RCTCamera alloc] init];
}
RCT_EXPORT_VIEW_PROPERTY(orientation, NSInteger);
- (void)checkDeviceAuthorizationStatus:(RCTResponseSenderBlock) callback
{
RCT_EXPORT();
NSString *mediaType = AVMediaTypeVideo;
[AVCaptureDevice requestAccessForMediaType:mediaType completionHandler:^(BOOL granted) {
callback(@[[NSNull null], @(granted)]);
}];
}
@end

41
README.md Normal file
View File

@ -0,0 +1,41 @@
# react-native-camera
-----------
A camera viewport for React Native. This module is currently in the very early stages of development and does not support image capture at this time, though it is coming.
## Getting started
1. Fetch from NPM: `npm install react-native-camera --save`
2. In XCode, right click `Libraries` and `Add Files to ______`
3. Add `libRCTCamera.a` to `Build Phases -> Link Binary With Libraries`
## Usage
All you need is to `require` the `react-native-camera` module and then use the
`<Camera/>` tag.
```
var React = require('react-native');
var {
AppRegistry,
StyleSheet,
Text,
View,
} = React;
var Camera = require('react-native-camera');
var cameraApp = React.createClass({
render: function() {
return (
<View>
<Camera style={{height: 200, width: 200}}/>
</View>
);
}
});
AppRegistry.registerComponent('cameraApp', () => cameraApp);
```
------------
Thanks to Brent Vatne (@brentvatne) for the `react-native-video` module which provided me with a great example of how to set up this module.

9
ViewfinderView.h Normal file
View File

@ -0,0 +1,9 @@
#import <UIKit/UIKit.h>
@class AVCaptureSession;
@interface ViewfinderView : UIView
@property (nonatomic) AVCaptureSession *session;
@end

21
ViewfinderView.m Normal file
View File

@ -0,0 +1,21 @@
#import "ViewfinderView.h"
#import <AVFoundation/AVFoundation.h>
@implementation ViewfinderView
+ (Class)layerClass
{
return [AVCaptureVideoPreviewLayer class];
}
- (AVCaptureSession *)session
{
return [(AVCaptureVideoPreviewLayer *)[self layer] session];
}
- (void)setSession:(AVCaptureSession *)session
{
[(AVCaptureVideoPreviewLayer *)[self layer] setSession:session];
}
@end

10
package.json Normal file
View File

@ -0,0 +1,10 @@
{
"name": "react-native-camera",
"version": "0.0.1",
"description": "A <Camera> element for React Native",
"main": "Camera.ios.js",
"author": "Lochlan Wansbrough <lochie@live.com> (http://lwansbrough.com)",
"dependencies": {
"react-native": "^0.3.1"
}
}