Skip to content

Commit

Permalink
fix: capacitor-community#131 paddingBottom param is not working prope…
Browse files Browse the repository at this point in the history
…rly under iOS
  • Loading branch information
ryaa committed May 9, 2021
1 parent ac63599 commit 0994ecf
Showing 1 changed file with 21 additions and 6 deletions.
27 changes: 21 additions & 6 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 && height != nil) {
self.previewView.frame = CGRect(x: self.x!, y: self.y!, width: self.width!, height: height!)
if (self.previewView != nil && self.x != nil && self.y != nil && self.width != nil && self.height != nil) {
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 0994ecf

Please sign in to comment.