From 7b34ea1b1df26173bd76d332e54ae0546b47084e Mon Sep 17 00:00:00 2001
From: Oliver Wiese <oliver.wiese@fu-berlin.de>
Date: Fri, 3 Apr 2020 16:16:02 +0200
Subject: [PATCH] remove cycle bug

---
 enzevalos_iphone/SwiftUI/Inbox/Inbox.swift    |  5 ++--
 .../SwiftUI/Inbox/KeyRecordRow.swift          | 23 +++++++++++--------
 .../SwiftUI/SupportingViews/MailView.swift    | 13 ++++++-----
 3 files changed, 24 insertions(+), 17 deletions(-)

diff --git a/enzevalos_iphone/SwiftUI/Inbox/Inbox.swift b/enzevalos_iphone/SwiftUI/Inbox/Inbox.swift
index 077cdf12..06e10bf3 100644
--- a/enzevalos_iphone/SwiftUI/Inbox/Inbox.swift
+++ b/enzevalos_iphone/SwiftUI/Inbox/Inbox.swift
@@ -27,7 +27,7 @@ struct Inbox: View {
             SearchView(searchText: $searchText, searchField: $searchField, searchNow: $searchNow)
                 .padding(6)
             // Mails
-           // mailList
+            mailList
             // Toolbar
             HStack {
                 self.idButton
@@ -48,7 +48,8 @@ struct Inbox: View {
     private var mailList: some View {
         List (self.keyrecords.filter(filterKeyRecord), id: \.self){
             record in
-            KeyRecordRow(keyrecord: record, coord: self.coord)
+            //KeyRecordRow(keyrecord: record, coord: self.coord)
+            KeyRecordRow(keyrecord: record)
        }
        .resignKeyboardOnDragGesture() // hide keyboard when dragging
     }
diff --git a/enzevalos_iphone/SwiftUI/Inbox/KeyRecordRow.swift b/enzevalos_iphone/SwiftUI/Inbox/KeyRecordRow.swift
index 87ec4a25..2efe5c1a 100644
--- a/enzevalos_iphone/SwiftUI/Inbox/KeyRecordRow.swift
+++ b/enzevalos_iphone/SwiftUI/Inbox/KeyRecordRow.swift
@@ -9,15 +9,14 @@
 import SwiftUI
 
 struct KeyRecordRow: View {
+    private static let coord = AppDelegate.getAppDelegate().inboxCoordinator
 
     var keyrecord: KeyRecord
-    let coord: InboxCoordinator
     var first: PersistentMail?
     var second: PersistentMail?
     
-    init(keyrecord: KeyRecord, coord: InboxCoordinator) {
+   init(keyrecord: KeyRecord) {
         self.keyrecord = keyrecord
-        self.coord = coord
         first = keyrecord.firstMail
         second = keyrecord.secondMail
     }
@@ -49,13 +48,13 @@ struct KeyRecordRow: View {
         if let first = self.first {
             if let second = self.second {
                 return AnyView(VStack(alignment: .leading, spacing: spacing) {
-                        MailView(mail: first, coord: coord)
-                        MailView(mail: second, coord: coord)
+                        MailView(mail: first)
+                        MailView(mail: second)
                         .background(Stroke(offsetY: offset))
                 })
             } else {
                 return AnyView(VStack(alignment: .leading,spacing: spacing) {
-                    MailView(mail: first, coord: coord)
+                    MailView(mail: first)
                     Text(NSLocalizedString("NoFurtherMessages", comment: "No more Mails"))
                     .background(Stroke(offsetY: offset))
                 })
@@ -71,7 +70,9 @@ struct KeyRecordRow: View {
             .frame(width: 60, height: 60)
             .shadow(radius: 5)
             .onTapGesture {
-                self.coord.pushRecordView(record: self.keyrecord)
+                if let coord = KeyRecordRow.coord {
+                    coord.pushRecordView(record: self.keyrecord)
+                }
         }
     }
     
@@ -80,13 +81,17 @@ struct KeyRecordRow: View {
             .frame(maxWidth: 300, alignment: .leading)
             .lineLimit(1)
             .onTapGesture {
-                self.coord.pushRecordView(record: self.keyrecord)
+                if let coord = KeyRecordRow.coord {
+                    coord.pushRecordView(record: self.keyrecord)
+                }
         }
     }
     
     private var moreMails: some View {
         Button(action: {
-            self.coord.pushMailListView(record: self.keyrecord)
+            if let coord = KeyRecordRow.coord {
+                coord.pushMailListView(record: self.keyrecord)
+            }
         }, label: {
             Text(NSLocalizedString("MailView.MoreMails", comment: "More mails"))
             .foregroundColor(.gray)
diff --git a/enzevalos_iphone/SwiftUI/SupportingViews/MailView.swift b/enzevalos_iphone/SwiftUI/SupportingViews/MailView.swift
index 2aa2587e..8cac9ab0 100644
--- a/enzevalos_iphone/SwiftUI/SupportingViews/MailView.swift
+++ b/enzevalos_iphone/SwiftUI/SupportingViews/MailView.swift
@@ -11,13 +11,12 @@ import SwiftUI
 
 
 struct MailView: View {
+    private static let coord = AppDelegate.getAppDelegate().inboxCoordinator
+
     var mail: PersistentMail
-    let coord: InboxCoordinator // We need this to move to the mail.
-    
-    init(mail: PersistentMail, coord: InboxCoordinator) {
+
+    init(mail: PersistentMail){
         self.mail = mail
-        self.coord = coord
-        
     }
         
     var body: some View {
@@ -32,7 +31,9 @@ struct MailView: View {
             }
         }
         .onTapGesture {
-            self.coord.pushReadView(mail: self.mail)
+            if let coord = MailView.coord {
+                coord.pushReadView(mail: self.mail)
+            }
         }
     }
     
-- 
GitLab