Skip to content

Commit

Permalink
Adds react-native-windows UWP support (react-native-camera#862)
Browse files Browse the repository at this point in the history
* Adds react-native-windows UWP support

This adds basic support for capturing photos and videos from either the front or back panel cameras, with some support for video quality, orientation, etc. This also uses ZXing.Net to support barcode scanning from the video preview frames. It also supports torch and flash modes. Videos and photos saved to disk (or camera roll / temporary folder) also supports some file metadata (e.g., lat/long).

There are a number of features that have not yet been implemented:
- Support `playSoundOnCapture` for default shutter sounds
- Add orientation metadata properties on photo / video files
- Support all barcode formats in ZXing.Net
- Additional file metadata (like description)
- Photo quality settings with `quality` and `jpegQuality`
- Image post-processing with `mirrorImage` and `fixOrientation`
- Support event listeners for `onZoomChanged` & `onFocusChanged`
- Device authorization checks as supported on iOS

* Updating NuGet packages for RNCamera UWP project

* Minor fixes for legacy RCTCamera implementation

* hack(CameraForView): default camera to any when panel info not available
  • Loading branch information
rozele authored and sibelius committed Dec 3, 2018
1 parent dd843bd commit 1c62749
Show file tree
Hide file tree
Showing 17 changed files with 1,987 additions and 0 deletions.
9 changes: 9 additions & 0 deletions src/Camera.js
Original file line number Diff line number Diff line change
Expand Up @@ -230,6 +230,7 @@ export default class Camera extends Component {
this.cameraBarCodeReadListener = Platform.select({
ios: NativeAppEventEmitter.addListener('CameraBarCodeRead', this._onBarCodeRead),
android: DeviceEventEmitter.addListener('CameraBarCodeReadAndroid', this._onBarCodeRead),
windows: DeviceEventEmitter.addListener('CameraBarCodeReadWindows', this._onBarCodeRead),
});
}
}
Expand Down Expand Up @@ -315,6 +316,10 @@ export default class Camera extends Component {
...options,
};

if (Platform.OS === 'windows') {
options['view'] = this._cameraHandle;
}

if (options.mode === Camera.constants.CaptureMode.video) {
options.totalSeconds = options.totalSeconds > -1 ? options.totalSeconds : -1;
options.preferredTimeScale = options.preferredTimeScale || 30;
Expand Down Expand Up @@ -367,6 +372,10 @@ export default class Camera extends Component {
return CameraManager.hasFlash({
type: props.type,
});
} else if (Platform.OS === 'windows') {
return CameraManager.hasFlash({
view: this._cameraHandle,
});
}
return CameraManager.hasFlash();
}
Expand Down
78 changes: 78 additions & 0 deletions windows/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
*AppPackages*
*BundleArtifacts*
*ReactAssets*

#OS junk files
[Tt]humbs.db
*.DS_Store

#Visual Studio files
*.[Oo]bj
*.user
*.aps
*.pch
*.vspscc
*.vssscc
*_i.c
*_p.c
*.ncb
*.suo
*.tlb
*.tlh
*.bak
*.[Cc]ache
*.ilk
*.log
*.lib
*.sbr
*.sdf
*.opensdf
*.opendb
*.unsuccessfulbuild
ipch/
[Oo]bj/
[Bb]in
[Dd]ebug*/
[Rr]elease*/
Ankh.NoLoad

#MonoDevelop
*.pidb
*.userprefs

#Tooling
_ReSharper*/
*.resharper
[Tt]est[Rr]esult*
*.sass-cache

#Project files
[Bb]uild/

#Subversion files
.svn

# Office Temp Files
~$*

# vim Temp Files
*~

#NuGet
packages/
*.nupkg

#ncrunch
*ncrunch*
*crunch*.local.xml

# visual studio database projects
*.dbmdl

#Test files
*.testsettings

#Other files
*.DotSettings
.vs/
*project.lock.json
9 changes: 9 additions & 0 deletions windows/.npmignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@

# Make sure we don't publish build artifacts to NPM
ARM/
Debug/
x64/
x86/
bin/
obj/
.vs/
115 changes: 115 additions & 0 deletions windows/RNCamera.sln
Original file line number Diff line number Diff line change
@@ -0,0 +1,115 @@
Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio 15
VisualStudioVersion = 15.0.26730.3
MinimumVisualStudioVersion = 10.0.40219.1
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "RNCamera", "RNCamera\RNCamera.csproj", "{F11038F0-88E5-11E7-BA7C-E36C7490591A}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ReactNative", "..\node_modules\react-native-windows\ReactWindows\ReactNative\ReactNative.csproj", "{C7673AD5-E3AA-468C-A5FD-FA38154E205C}"
EndProject
Project("{D954291E-2A0B-460D-934E-DC6B0785DB48}") = "ReactNative.Shared", "..\node_modules\react-native-windows\ReactWindows\ReactNative.Shared\ReactNative.Shared.shproj", "{EEA8B852-4D07-48E1-8294-A21AB5909FE5}"
EndProject
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "ChakraBridge", "..\node_modules\react-native-windows\ReactWindows\ChakraBridge\ChakraBridge.vcxproj", "{4B72C796-16D5-4E3A-81C0-3E36F531E578}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ReactNativeWebViewBridge", "..\node_modules\react-native-windows\ReactWindows\ReactNativeWebViewBridge\ReactNativeWebViewBridge.csproj", "{7596216B-669C-41F8-86DA-F3637F6545C0}"
EndProject
Project("{D954291E-2A0B-460D-934E-DC6B0785DB48}") = "Facebook.Yoga.Shared", "..\node_modules\react-native-windows\Yoga\csharp\Facebook.Yoga\Facebook.Yoga.Shared.shproj", "{91C42D32-291D-4B72-90B4-551663D60B8B}"
EndProject
Global
GlobalSection(SharedMSBuildProjectFiles) = preSolution
..\node_modules\react-native-windows\Yoga\csharp\Facebook.Yoga\Facebook.Yoga.Shared.projitems*{91c42d32-291d-4b72-90b4-551663d60b8b}*SharedItemsImports = 13
..\node_modules\react-native-windows\ReactWindows\ReactNative.Shared\ReactNative.Shared.projitems*{c7673ad5-e3aa-468c-a5fd-fa38154e205c}*SharedItemsImports = 4
..\node_modules\react-native-windows\Yoga\csharp\Facebook.Yoga\Facebook.Yoga.Shared.projitems*{c7673ad5-e3aa-468c-a5fd-fa38154e205c}*SharedItemsImports = 4
..\node_modules\react-native-windows\ReactWindows\ReactNative.Shared\ReactNative.Shared.projitems*{eea8b852-4d07-48e1-8294-a21ab5909fe5}*SharedItemsImports = 13
EndGlobalSection
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|ARM = Debug|ARM
Debug|x64 = Debug|x64
Debug|x86 = Debug|x86
Development|ARM = Development|ARM
Development|x64 = Development|x64
Development|x86 = Development|x86
Release|ARM = Release|ARM
Release|x64 = Release|x64
Release|x86 = Release|x86
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{F11038F0-88E5-11E7-BA7C-E36C7490591A}.Debug|ARM.ActiveCfg = Debug|ARM
{F11038F0-88E5-11E7-BA7C-E36C7490591A}.Debug|ARM.Build.0 = Debug|ARM
{F11038F0-88E5-11E7-BA7C-E36C7490591A}.Debug|x64.ActiveCfg = Debug|x64
{F11038F0-88E5-11E7-BA7C-E36C7490591A}.Debug|x64.Build.0 = Debug|x64
{F11038F0-88E5-11E7-BA7C-E36C7490591A}.Debug|x86.ActiveCfg = Debug|x86
{F11038F0-88E5-11E7-BA7C-E36C7490591A}.Debug|x86.Build.0 = Debug|x86
{F11038F0-88E5-11E7-BA7C-E36C7490591A}.Development|ARM.ActiveCfg = Development|ARM
{F11038F0-88E5-11E7-BA7C-E36C7490591A}.Development|ARM.Build.0 = Development|ARM
{F11038F0-88E5-11E7-BA7C-E36C7490591A}.Development|x64.ActiveCfg = Development|x64
{F11038F0-88E5-11E7-BA7C-E36C7490591A}.Development|x64.Build.0 = Development|x64
{F11038F0-88E5-11E7-BA7C-E36C7490591A}.Development|x86.ActiveCfg = Development|x86
{F11038F0-88E5-11E7-BA7C-E36C7490591A}.Development|x86.Build.0 = Development|x86
{F11038F0-88E5-11E7-BA7C-E36C7490591A}.Release|ARM.ActiveCfg = Release|ARM
{F11038F0-88E5-11E7-BA7C-E36C7490591A}.Release|ARM.Build.0 = Release|ARM
{F11038F0-88E5-11E7-BA7C-E36C7490591A}.Release|x64.ActiveCfg = Release|x64
{F11038F0-88E5-11E7-BA7C-E36C7490591A}.Release|x64.Build.0 = Release|x64
{F11038F0-88E5-11E7-BA7C-E36C7490591A}.Release|x86.ActiveCfg = Release|x86
{F11038F0-88E5-11E7-BA7C-E36C7490591A}.Release|x86.Build.0 = Release|x86
{C7673AD5-E3AA-468C-A5FD-FA38154E205C}.Debug|ARM.ActiveCfg = Debug|ARM
{C7673AD5-E3AA-468C-A5FD-FA38154E205C}.Debug|ARM.Build.0 = Debug|ARM
{C7673AD5-E3AA-468C-A5FD-FA38154E205C}.Debug|x64.ActiveCfg = Debug|x64
{C7673AD5-E3AA-468C-A5FD-FA38154E205C}.Debug|x64.Build.0 = Debug|x64
{C7673AD5-E3AA-468C-A5FD-FA38154E205C}.Debug|x86.ActiveCfg = Debug|x86
{C7673AD5-E3AA-468C-A5FD-FA38154E205C}.Debug|x86.Build.0 = Debug|x86
{C7673AD5-E3AA-468C-A5FD-FA38154E205C}.Development|ARM.ActiveCfg = Debug|ARM
{C7673AD5-E3AA-468C-A5FD-FA38154E205C}.Development|ARM.Build.0 = Debug|ARM
{C7673AD5-E3AA-468C-A5FD-FA38154E205C}.Development|x64.ActiveCfg = Debug|x64
{C7673AD5-E3AA-468C-A5FD-FA38154E205C}.Development|x64.Build.0 = Debug|x64
{C7673AD5-E3AA-468C-A5FD-FA38154E205C}.Development|x86.ActiveCfg = Debug|x86
{C7673AD5-E3AA-468C-A5FD-FA38154E205C}.Development|x86.Build.0 = Debug|x86
{C7673AD5-E3AA-468C-A5FD-FA38154E205C}.Release|ARM.ActiveCfg = Release|ARM
{C7673AD5-E3AA-468C-A5FD-FA38154E205C}.Release|ARM.Build.0 = Release|ARM
{C7673AD5-E3AA-468C-A5FD-FA38154E205C}.Release|x64.ActiveCfg = Release|x64
{C7673AD5-E3AA-468C-A5FD-FA38154E205C}.Release|x64.Build.0 = Release|x64
{C7673AD5-E3AA-468C-A5FD-FA38154E205C}.Release|x86.ActiveCfg = Release|x86
{C7673AD5-E3AA-468C-A5FD-FA38154E205C}.Release|x86.Build.0 = Release|x86
{4B72C796-16D5-4E3A-81C0-3E36F531E578}.Debug|ARM.ActiveCfg = Debug|ARM
{4B72C796-16D5-4E3A-81C0-3E36F531E578}.Debug|ARM.Build.0 = Debug|ARM
{4B72C796-16D5-4E3A-81C0-3E36F531E578}.Debug|x64.ActiveCfg = Debug|x64
{4B72C796-16D5-4E3A-81C0-3E36F531E578}.Debug|x64.Build.0 = Debug|x64
{4B72C796-16D5-4E3A-81C0-3E36F531E578}.Debug|x86.ActiveCfg = Debug|Win32
{4B72C796-16D5-4E3A-81C0-3E36F531E578}.Debug|x86.Build.0 = Debug|Win32
{4B72C796-16D5-4E3A-81C0-3E36F531E578}.Development|ARM.ActiveCfg = Debug|ARM
{4B72C796-16D5-4E3A-81C0-3E36F531E578}.Development|ARM.Build.0 = Debug|ARM
{4B72C796-16D5-4E3A-81C0-3E36F531E578}.Development|x64.ActiveCfg = Debug|x64
{4B72C796-16D5-4E3A-81C0-3E36F531E578}.Development|x64.Build.0 = Debug|x64
{4B72C796-16D5-4E3A-81C0-3E36F531E578}.Development|x86.ActiveCfg = Debug|Win32
{4B72C796-16D5-4E3A-81C0-3E36F531E578}.Development|x86.Build.0 = Debug|Win32
{4B72C796-16D5-4E3A-81C0-3E36F531E578}.Release|ARM.ActiveCfg = Release|ARM
{4B72C796-16D5-4E3A-81C0-3E36F531E578}.Release|ARM.Build.0 = Release|ARM
{4B72C796-16D5-4E3A-81C0-3E36F531E578}.Release|x64.ActiveCfg = Release|x64
{4B72C796-16D5-4E3A-81C0-3E36F531E578}.Release|x64.Build.0 = Release|x64
{4B72C796-16D5-4E3A-81C0-3E36F531E578}.Release|x86.ActiveCfg = Release|Win32
{4B72C796-16D5-4E3A-81C0-3E36F531E578}.Release|x86.Build.0 = Release|Win32
{7596216B-669C-41F8-86DA-F3637F6545C0}.Debug|ARM.ActiveCfg = Debug|ARM
{7596216B-669C-41F8-86DA-F3637F6545C0}.Debug|ARM.Build.0 = Debug|ARM
{7596216B-669C-41F8-86DA-F3637F6545C0}.Debug|x64.ActiveCfg = Debug|x64
{7596216B-669C-41F8-86DA-F3637F6545C0}.Debug|x64.Build.0 = Debug|x64
{7596216B-669C-41F8-86DA-F3637F6545C0}.Debug|x86.ActiveCfg = Debug|x86
{7596216B-669C-41F8-86DA-F3637F6545C0}.Debug|x86.Build.0 = Debug|x86
{7596216B-669C-41F8-86DA-F3637F6545C0}.Development|ARM.ActiveCfg = Debug|ARM
{7596216B-669C-41F8-86DA-F3637F6545C0}.Development|ARM.Build.0 = Debug|ARM
{7596216B-669C-41F8-86DA-F3637F6545C0}.Development|x64.ActiveCfg = Debug|x64
{7596216B-669C-41F8-86DA-F3637F6545C0}.Development|x64.Build.0 = Debug|x64
{7596216B-669C-41F8-86DA-F3637F6545C0}.Development|x86.ActiveCfg = Debug|x86
{7596216B-669C-41F8-86DA-F3637F6545C0}.Development|x86.Build.0 = Debug|x86
{7596216B-669C-41F8-86DA-F3637F6545C0}.Release|ARM.ActiveCfg = Release|ARM
{7596216B-669C-41F8-86DA-F3637F6545C0}.Release|ARM.Build.0 = Release|ARM
{7596216B-669C-41F8-86DA-F3637F6545C0}.Release|x64.ActiveCfg = Release|x64
{7596216B-669C-41F8-86DA-F3637F6545C0}.Release|x64.Build.0 = Release|x64
{7596216B-669C-41F8-86DA-F3637F6545C0}.Release|x86.ActiveCfg = Release|x86
{7596216B-669C-41F8-86DA-F3637F6545C0}.Release|x86.Build.0 = Release|x86
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {B259F75D-E772-4C88-973E-F0EF45B3F422}
EndGlobalSection
EndGlobal
39 changes: 39 additions & 0 deletions windows/RNCamera/BarcodeFormatExtensions.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
using System;
using ZXing;

namespace RNCamera
{
static class BarcodeFormatExtensions
{
public static string GetName(this BarcodeFormat barcodeFormat)
{
switch (barcodeFormat)
{
case BarcodeFormat.AZTEC:
return "aztec";
case BarcodeFormat.CODE_39:
return "code39";
case BarcodeFormat.CODE_93:
return "code93";
case BarcodeFormat.CODE_128:
return "code128";
case BarcodeFormat.DATA_MATRIX:
return "datamatrix";
case BarcodeFormat.EAN_8:
return "ean8";
case BarcodeFormat.EAN_13:
return "ean13";
case BarcodeFormat.ITF:
return "interleaved2of5";
case BarcodeFormat.PDF_417:
return "pdf417";
case BarcodeFormat.QR_CODE:
return "qr";
case BarcodeFormat.UPC_E:
return "upce";
default:
throw new NotImplementedException();
}
}
}
}
Loading

0 comments on commit 1c62749

Please sign in to comment.