From 0994ecf3c1d41fe0c0a4139e8f52fb5815a1e181 Mon Sep 17 00:00:00 2001 From: Alex Ryltsov Date: Sun, 9 May 2021 07:46:51 +0300 Subject: [PATCH] fix: #131 paddingBottom param is not working properly under iOS --- ios/Plugin/Plugin.swift | 27 +++++++++++++++++++++------ 1 file changed, 21 insertions(+), 6 deletions(-) diff --git a/ios/Plugin/Plugin.swift b/ios/Plugin/Plugin.swift index 56b24628..4089b5de 100644 --- a/ios/Plugin/Plugin.swift +++ b/ios/Plugin/Plugin.swift @@ -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 } @@ -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