Skip to content

Commit

Permalink
feat(windows): updated for react-native-windows 0.62 (react-native-ca…
Browse files Browse the repository at this point in the history
…mera#2882)

Build:
* Updated ReactNativeCameraCPP projects to use the new RNW lib props/targets provided in 0.62 for easier upgrades
* Added new ReactNativeCameraCPP solution and readme with instructions for building locally
* Added ReactNativeCameraCPP61 solution and project to maintain 0.61 support

ReactNativeCameraCPP RNCamera component:
* Added properties: defaultVideoQuality, mirrorVideo, autoFocus, whiteBalance, cameraId
* Removed deprecated properties: torchMode
* Expanded Type constant (front/back) to include other Windows types (Unknown, Top, Bottom, Left, Right)

ReactNativeCamperaCPP RNCamera module:
* Cleaned up async error handling:
    * Uncaught exceptions no longer crash the app, instead returning the error via the promise reject as expected
    * Passed in options and promises are now properly captured so as to not get deleted before async operations are completed
* Fixed issue when passed in option values are doubles instead of integers
* Moved all possible processing off of the UI thread
* Fixed device enumeration by id/type to support non-integrated cameras
* Piped out CaptureTarget constants for "target" option (memory, disk, cameraRoll, temp)
* Added BarCodeType constant stubs
* Added FaceDetection constants stubs
* Added VideoCodec constants for "codec" option (H264, HEVC, WMV)
* takePicture:
    * Added options: target, quality, doNotSave, base64, width, mirrorImage, exif, writeExif
    * Added result properties: width, height, base64, exif
    * Fixed issue where EXIF data was being stripped from photos
* record:
    * Added options: target, mute, quality, maxDuration, videoBitrate, codec
    * Added result properties: codec
* stopRecording: Added implementation
* isRecording: Added implementation
* pausePreview: Added implementation
* resumePreview: Added implementation
* getCameraIds: Added implementation
  • Loading branch information
jonthysell authored Jul 17, 2020
1 parent d62da5f commit 93e6581
Show file tree
Hide file tree
Showing 27 changed files with 2,884 additions and 1,438 deletions.
366 changes: 188 additions & 178 deletions docs/installation.md

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions src/RNCamera.js
Original file line number Diff line number Diff line change
Expand Up @@ -364,6 +364,7 @@ export default class Camera extends React.Component<PropsType, StateType> {
GoogleVisionBarcodeDetection: CameraManager.GoogleVisionBarcodeDetection,
FaceDetection: CameraManager.FaceDetection,
CameraStatus,
CaptureTarget: CameraManager.CaptureTarget,
RecordAudioPermissionStatus: RecordAudioPermissionStatusEnum,
VideoStabilization: CameraManager.VideoStabilization,
Orientation: {
Expand Down
92 changes: 92 additions & 0 deletions windows/.clang-format
Original file line number Diff line number Diff line change
@@ -0,0 +1,92 @@
---
AccessModifierOffset: -1
AlignAfterOpenBracket: AlwaysBreak
AlignConsecutiveAssignments: false
AlignConsecutiveDeclarations: false
AlignEscapedNewlinesLeft: true
AlignOperands: false
AlignTrailingComments: false
AllowAllParametersOfDeclarationOnNextLine: false
AllowShortBlocksOnASingleLine: false
AllowShortCaseLabelsOnASingleLine: false
AllowShortFunctionsOnASingleLine: Empty
AllowShortIfStatementsOnASingleLine: false
AllowShortLoopsOnASingleLine: false
AlwaysBreakAfterReturnType: None
AlwaysBreakBeforeMultilineStrings: true
AlwaysBreakTemplateDeclarations: true
BinPackArguments: false
BinPackParameters: false
BraceWrapping:
AfterClass: false
AfterControlStatement: false
AfterEnum: false
AfterFunction: false
AfterNamespace: false
AfterObjCDeclaration: false
AfterStruct: false
AfterUnion: false
BeforeCatch: false
BeforeElse: false
IndentBraces: false
BreakBeforeBinaryOperators: None
BreakBeforeBraces: Attach
BreakBeforeTernaryOperators: true
BreakConstructorInitializersBeforeComma: false
BreakAfterJavaFieldAnnotations: false
BreakStringLiterals: false
ColumnLimit: 120
CommentPragmas: '^ IWYU pragma:'
ConstructorInitializerAllOnOneLineOrOnePerLine: true
ConstructorInitializerIndentWidth: 4
ContinuationIndentWidth: 4
Cpp11BracedListStyle: true
DerivePointerAlignment: false
DisableFormat: false
ForEachMacros: [ FOR_EACH_RANGE, FOR_EACH, ]
IncludeBlocks: Preserve
IncludeCategories:
- Regex: 'pch.h'
Priority: -1
- Regex: '.*\.g\..*'
Priority: 1
- Regex: '^<.*\.h(pp)?>'
Priority: 2
- Regex: '^<.*'
Priority: 3
- Regex: '.*'
Priority: 4
IndentCaseLabels: true
IndentWidth: 2
IndentWrappedFunctionNames: false
KeepEmptyLinesAtTheStartOfBlocks: false
MacroBlockBegin: ''
MacroBlockEnd: ''
MaxEmptyLinesToKeep: 1
NamespaceIndentation: None
ObjCBlockIndentWidth: 2
ObjCSpaceAfterProperty: true
ObjCSpaceBeforeProtocolList: true
PenaltyBreakBeforeFirstCallParameter: 1
PenaltyBreakComment: 300
PenaltyBreakFirstLessLess: 120
PenaltyBreakString: 1000
PenaltyExcessCharacter: 1000000
PenaltyReturnTypeOnItsOwnLine: 200
PointerAlignment: Right
ReflowComments: true
SortIncludes: true
SpaceAfterCStyleCast: false
SpaceBeforeAssignmentOperators: true
SpaceBeforeParens: ControlStatements
SpaceInEmptyParentheses: false
SpacesBeforeTrailingComments: 1
SpacesInAngles: false
SpacesInContainerLiterals: true
SpacesInCStyleCastParentheses: false
SpacesInParentheses: false
SpacesInSquareBrackets: false
Standard: Cpp11
TabWidth: 8
UseTab: Never
...
16 changes: 15 additions & 1 deletion windows/.gitignore
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
*AppPackages*
*BundleArtifacts*
*ReactAssets*

#OS junk files
[Tt]humbs.db
Expand Down Expand Up @@ -36,6 +35,17 @@ ipch/
[Rr]elease*/
Ankh.NoLoad

# Visual C++ cache files
ipch/
*.aps
*.ncb
*.opendb
*.opensdf
*.sdf
*.cachefile
*.VC.db
*.VC.VC.opendb

#MonoDevelop
*.pidb
*.userprefs
Expand Down Expand Up @@ -76,3 +86,7 @@ packages/
*.DotSettings
.vs/
*project.lock.json

#Files generated by the VS build
**/Generated Files/**

33 changes: 33 additions & 0 deletions windows/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
# React Native Camera (Windows)

React Native Camera is currently maintained for React Native Windows (RNW) >= 0.61.

There are two implementations of `react-native-camera` in this folder:

1. _ReactNativeCameraCPP_ is the currently maintained implementation:
1. Use _ReactNativeCameraCPP_ for RNW >= 0.62.
2. Use _ReactNativeCameraCPP61_ for RNW 0.61.
2. _RNCamera_ is a legacy implementation for `[email protected]`. It is no longer maintained.

## Why all the different versions?

RNW was originally implemented in C#, where development stopped at version 0.59. _RNCamera_ is the version of React Native Camera written in C# against that (now "legacy") RNW.

RNW was then rebuilt from scratch in C++, and version 0.61 was the first release to support native community modules. _ReactNativeCameraCPP_ is the version of React Native Camera written in C++ against the current RNW.

RNW 0.62 brought a variety of build improvements, but now requires both Visual Studio 2019 and a newer Windows SDK. So while the native module APIs are 99% forward-compatible, it's currently necessary to maintain a separate `ReactNativeCameraCPP61.vcxproj` project for RNW 0.61 users. The `ReactNativeCameraCPP.vcxproj` project targets RNW >= 0.62 users.

# Local Development Setup (RNW >= 0.62)

In order to work on _ReactNativeCameraCPP_, you'll need to install the [Windows Development Dependencies](https://microsoft.github.io/react-native-windows/docs/rnw-dependencies).

In addition, `react-native-camera` targets React Native 0.59 and doesn't include React Native Windows as a dependency. So in order to build _ReactNativeCameraCPP_ locally you'll need to temporarily upgrade the development dependencies:

```
yarn upgrade react-native@^0.62.2
yarn add react-native-windows@^0.62.0 --dev
```

Now you should be able to open `ReactNativeCameraCPP.sln` in Visual Studio and build the project.

> _Note:_ In order to test your code changes don't break RNW 0.61, you'll want to do the above steps but targeting RN/RNW 0.61, and using `ReactNativeCameraCPP61.sln`.
Loading

0 comments on commit 93e6581

Please sign in to comment.