From 544f4d680444cea3858d66130cc2a115e15deef5 Mon Sep 17 00:00:00 2001
From: Mustafa Merza <mustafa.merza95@gmail.com>
Date: Sun, 18 Aug 2024 21:49:45 +0300
Subject: [PATCH] - Fixed signing the single page when it is not displayed.

---
 .../EditViewController.swift                  | 23 +++++--------------
 .../MultiPageScanSession.swift                |  2 ++
 2 files changed, 8 insertions(+), 17 deletions(-)

diff --git a/MiniScanner/Modules/EditViewController/EditViewController.swift b/MiniScanner/Modules/EditViewController/EditViewController.swift
index aaf37c2..19fc55e 100644
--- a/MiniScanner/Modules/EditViewController/EditViewController.swift
+++ b/MiniScanner/Modules/EditViewController/EditViewController.swift
@@ -486,28 +486,17 @@ extension EditViewController {
         activityIndicator.startAnimating()
         
         Task {
-            if !banner.signAllDoc {
-                
-                let selectedIndex = banner.pagerView.currentIndex
-                
-                await applySignatureToScannedItem(at: selectedIndex)
-                
-                await MainActor.run {
-                    banner.pagerView.reloadData(at: selectedIndex)
-                }
-            } else {
+            
+            for (index, item) in items.enumerated() {
                 
-                for (index, _) in items.enumerated() {
-                    
+                if item.hasSignature {
                     await applySignatureToScannedItem(at: index)
                 }
-                
-                await MainActor.run {
-                    banner.pagerView.reloadData()
-                }
             }
             
             await MainActor.run {
+                banner.pagerView.reloadData()
+                
                 activityIndicator.stopAnimating()
             }
         }
@@ -868,7 +857,7 @@ extension EditViewController: BannerViewDelegate {
     func deleteSignAt(index: Int) {
         scanSession.scannedItems[index].removeSign()
         
-        let signaturesCount = scanSession.scannedItems.filter { $0.signtureImage != nil }.count
+        let signaturesCount = scanSession.scannedItems.filter { $0.hasSignature }.count
         
         if signaturesCount == 0 {
             screenMode = .normal
diff --git a/MiniScanner/Supporting Files/Frameworks/CustomWeScan/MultiPageSession/MultiPageScanSession.swift b/MiniScanner/Supporting Files/Frameworks/CustomWeScan/MultiPageSession/MultiPageScanSession.swift
index 8f66bc4..9ea942b 100644
--- a/MiniScanner/Supporting Files/Frameworks/CustomWeScan/MultiPageSession/MultiPageScanSession.swift	
+++ b/MiniScanner/Supporting Files/Frameworks/CustomWeScan/MultiPageSession/MultiPageScanSession.swift	
@@ -55,6 +55,8 @@ public class ScannedItem: Codable, Identifiable {
         return folderUrl.appendingPathComponent(name)
     }
     
+    var hasSignature: Bool { signtureImage != nil }
+    
     var signtureImage: UIImage?
     var signaturePosition: CGPoint?
     var size: CGSize?
-- 
GitLab