Skip to content
This repository has been archived by the owner on Aug 11, 2020. It is now read-only.

Commit

Permalink
Scanning crashes on Windows phone on device rotation
Browse files Browse the repository at this point in the history
Fixes scanning in portrait orientation, this fixes #172, this fixes #202
Updated preview CSS to fix portrait mode
  • Loading branch information
Sergey Shakhnazarov authored and Vladimir Kotikov committed Jun 15, 2016
1 parent 45ec98f commit c3bcd87
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 7 deletions.
28 changes: 22 additions & 6 deletions src/windows/BarcodeScannerProxy.js
Original file line number Diff line number Diff line change
Expand Up @@ -212,6 +212,26 @@ BarcodeReader.prototype.stop = function () {
this._cancelled = true;
};

function degreesToRotation(degrees) {
switch (degrees) {
// portrait
case 90:
return Windows.Media.Capture.VideoRotation.clockwise90Degrees;
// landscape
case 0:
return Windows.Media.Capture.VideoRotation.none;
// portrait-flipped
case 270:
return Windows.Media.Capture.VideoRotation.clockwise270Degrees;
// landscape-flipped
case 180:
return Windows.Media.Capture.VideoRotation.clockwise180Degrees;
default:
// Falling back to portrait default
return Windows.Media.Capture.VideoRotation.clockwise90Degrees;
}
}

module.exports = {

/**
Expand All @@ -235,8 +255,6 @@ module.exports = {
return;
}

var ROTATION_KEY = "C380465D-2271-428C-9B83-ECEA3B4A85C1";

var displayInformation = (evt && evt.target) || Windows.Graphics.Display.DisplayInformation.getForCurrentView();
var currentOrientation = displayInformation.currentOrientation;

Expand All @@ -245,10 +263,8 @@ module.exports = {
// Lookup up the rotation degrees.
var rotDegree = videoPreviewRotationLookup(currentOrientation, previewMirroring);

// rotate the preview video
var videoEncodingProperties = capture.videoDeviceController.getMediaStreamProperties(Windows.Media.Capture.MediaStreamType.videoPreview);
videoEncodingProperties.properties.insert(ROTATION_KEY, rotDegree);
return capture.videoDeviceController.setMediaStreamPropertiesAsync(Windows.Media.Capture.MediaStreamType.videoPreview, videoEncodingProperties);
capture.setPreviewRotation(degreesToRotation(rotDegree));
return WinJS.Promise.as();
}

/**
Expand Down
8 changes: 7 additions & 1 deletion src/windows/assets/plugin-barcodeScanner.css
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,12 @@
}

.barcode-scanner-preview {
width: 100%;
width: auto;
height: calc(100% - 70px);
position: absolute;
top: calc(50% - 35px);
left: 50%;
transform: translateX(-50%) translateY(-50%);
}

.barcode-scanner-mark {
Expand All @@ -36,6 +40,8 @@
z-index: 9999999;
text-align: center;
user-select: none;
position: absolute;
bottom: 0px;
}

.app-bar-action {
Expand Down

0 comments on commit c3bcd87

Please sign in to comment.