From 45b202001c2926804f9b051ebd75fa68227f6bc0 Mon Sep 17 00:00:00 2001 From: Pavel Anokhov Date: Tue, 3 Jul 2018 15:37:02 +0300 Subject: [PATCH] NodesEditor: Loading default nodes fixed. --- .../NodesEditor/NodesListViewController.swift | 26 +++++++++++++++---- 1 file changed, 21 insertions(+), 5 deletions(-) diff --git a/Adamant/Stories/NodesEditor/NodesListViewController.swift b/Adamant/Stories/NodesEditor/NodesListViewController.swift index 8cbfe8664..5979d9368 100644 --- a/Adamant/Stories/NodesEditor/NodesListViewController.swift +++ b/Adamant/Stories/NodesEditor/NodesListViewController.swift @@ -74,6 +74,7 @@ class NodesListViewController: FormViewController { // Properties private var nodes = [Node]() + private var didResetNodesOnDissapear = false // MARK: - Lifecycle @@ -143,12 +144,17 @@ class NodesListViewController: FormViewController { override func viewWillDisappear(_ animated: Bool) { super.viewWillDisappear(animated) - // Top, not presented, and no nodes - reset to default and show alert if let top = navigationController?.topViewController, top == self && presentedViewController == nil && nodes.count == 0 { - let nodes = nodesSource.defaultNodes - nodesSource.nodes = nodes - nodesSource.saveNodes() - dialogService.showSuccess(withMessage: String.adamantLocalized.nodesList.defaultNodesWasLoaded) + didResetNodesOnDissapear = true + loadDefaultNodes(showAlert: true) + } + } + + override func viewDidDisappear(_ animated: Bool) { + super.viewDidDisappear(animated) + + if navigationController == nil && nodes.count == 0 && !didResetNodesOnDissapear { + loadDefaultNodes(showAlert: true) } } @@ -298,6 +304,16 @@ extension NodesListViewController { nodesSource.nodes = nodes nodesSource.saveNodes() } + + func loadDefaultNodes(showAlert: Bool) { + let nodes = nodesSource.defaultNodes + nodesSource.nodes = nodes + nodesSource.saveNodes() + + if showAlert { + dialogService.showSuccess(withMessage: String.adamantLocalized.nodesList.defaultNodesWasLoaded) + } + } }