Skip to content

Commit

Permalink
Merge pull request capacitor-community#133 from ryaa/fixed-paddingBot…
Browse files Browse the repository at this point in the history
…tom-param-is-not-working-under-iOS
  • Loading branch information
arielhernandezmusa authored Jun 6, 2021
2 parents 5c0f696 + 0994ecf commit 17f4295
Showing 1 changed file with 20 additions and 5 deletions.
25 changes: 20 additions & 5 deletions ios/Plugin/Plugin.swift
Original file line number Diff line number Diff line change
Expand Up @@ -23,16 +23,30 @@ public class CameraPreview: CAPPlugin {

@objc func rotated() {

let height = self.paddingBottom != nil ? self.height! - self.paddingBottom!: self.height!;

if UIDevice.current.orientation.isLandscape {
self.previewView.frame = CGRect(x: self.y!, y: self.x!, width: height, height: self.width!)
if(self.width! > self.height!) {
// we started in landscape
let height = self.paddingBottom != nil ? self.height! - self.paddingBottom!: self.height!;
self.previewView.frame = CGRect(x: self.x!, y: self.y!, width: self.width!, height: height)
} else {
// we started in portrait
let width = self.paddingBottom != nil ? self.width! - self.paddingBottom!: self.width!;
self.previewView.frame = CGRect(x: self.y!, y: self.x!, width: self.height!, height: width)
}
self.cameraController.previewLayer?.frame = self.previewView.frame
}

if UIDevice.current.orientation.isPortrait {
if (self.previewView != nil && self.x != nil && self.y != nil && self.width != nil && self.height != nil) {
self.previewView.frame = CGRect(x: self.x!, y: self.y!, width: self.width!, height: self.height!)
if(self.height! > self.width!) {
// we started in portrait
let height = self.paddingBottom != nil ? self.height! - self.paddingBottom!: self.height!;
self.previewView.frame = CGRect(x: self.x!, y: self.y!, width: self.width!, height: height)
} else {
// we started in landscape
let width = self.paddingBottom != nil ? self.width! - self.paddingBottom!: self.width!;
self.previewView.frame = CGRect(x: self.y!, y: self.x!, width: self.height!, height: width)
}
}
self.cameraController.previewLayer?.frame = self.previewView.frame
}
Expand Down Expand Up @@ -85,7 +99,8 @@ public class CameraPreview: CAPPlugin {
call.reject(error.localizedDescription)
return
}
self.previewView = UIView(frame: CGRect(x: self.x!, y: self.y!, width: self.width!, height: self.height!))
let height = self.paddingBottom != nil ? self.height! - self.paddingBottom!: self.height!;
self.previewView = UIView(frame: CGRect(x: 0, y: 0, width: self.width!, height: height))
self.webView.isOpaque = false
self.webView.backgroundColor = UIColor.clear
self.webView.scrollView.backgroundColor = UIColor.clear
Expand Down

0 comments on commit 17f4295

Please sign in to comment.