Skip to content

Commit b9f32cd

Browse files
Merge pull request #40 from surfstudio/screen-stack-push-modification
Add pushCustomScreen
2 parents 3b826fd + f3b3d5f commit b9f32cd

8 files changed

Lines changed: 48 additions & 13 deletions

File tree

DebugScreen/Common/Models/Modules/ModuleType.swift

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,17 @@ enum ModuleType {
1313
/// Module to present alert with message
1414
case alert(model: AlertModel)
1515
/// Module to present any view controller by action button tap
16-
case customScreen(_ screen: UIViewController)
16+
case customScreen(_ screen: UIViewController, method: CustomScreenPresentationMethod)
1717
/// Module to open local file by selected filepath
1818
case fileViewer(model: FileViewerModel)
1919
/// Module to present information table screen.
2020
case infoTable(model: InfoTableModel)
2121
}
22+
23+
/// Defines how a custom screen should be presented from the debug menu
24+
enum CustomScreenPresentationMethod {
25+
/// Present modally over the current screen
26+
case present
27+
/// Push onto the debug screen navigation stack
28+
case push
29+
}

DebugScreen/Flows/DebugScreenCoordinator.swift

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,8 @@ final class DebugScreenCoordinator: BaseCoordinator {
2828
switch module {
2929
case .alert(let model):
3030
showAlert(with: model)
31-
case .customScreen(let screen):
32-
showCustomScreen(screen)
31+
case .customScreen(let screen, let method):
32+
showCustomScreen(screen, method: method)
3333
case .fileViewer(let model):
3434
showFile(with: model)
3535
case .infoTable(let model):
@@ -115,10 +115,15 @@ private extension DebugScreenCoordinator {
115115
router.push(view)
116116
}
117117

118-
func showCustomScreen(_ screen: UIViewController) {
119-
let view = BaseNavigationController(rootViewController: screen)
120-
view.modalPresentationStyle = .overFullScreen
121-
router.present(view)
118+
func showCustomScreen(_ screen: UIViewController, method: CustomScreenPresentationMethod) {
119+
switch method {
120+
case .present:
121+
let view = BaseNavigationController(rootViewController: screen)
122+
view.modalPresentationStyle = .overFullScreen
123+
router.present(view)
124+
case .push:
125+
router.push(screen)
126+
}
122127
}
123128

124129
func configureActionSheetItem(with model: Action) -> UIAlertAction {

DebugScreen/Services/DebugScreenPresenterService.swift

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -45,11 +45,19 @@ public final class DebugScreenPresenterService {
4545
openModule(.alert(model: model))
4646
}
4747

48-
/// Show custom view controller.
48+
/// Show custom view controller modally.
4949
/// Can be showed only when debug screen is open.
5050
/// - Parameter view: Screen to display.
51-
public func showCustomScreen(_ view: UIViewController) {
52-
openModule(.customScreen(view))
51+
public func presentCustomScreen(_ view: UIViewController) {
52+
openModule(.customScreen(view, method: .present))
53+
}
54+
55+
/// Push custom view controller onto the debug screen navigation stack.
56+
/// Provides a standard back button to return to the debug menu.
57+
/// Can be used only when debug screen is open.
58+
/// - Parameter view: Screen to display.
59+
public func pushCustomScreen(_ view: UIViewController) {
60+
openModule(.customScreen(view, method: .push))
5361
}
5462

5563
/// Open log file.

Example/DebugScreenExample/App/DebugScreenConfiguration/Builders/ActionsSectionBuilder.swift

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,14 +18,16 @@ final class ActionsSectionBuilder: SectionBuilder {
1818
let defaultAction = getAction(style: .secondary)
1919
let destructiveAction = getAction(style: .destructive)
2020
let openScreenAction = getOpenScreenAction()
21+
let pushScreenAction = getPushScreenAction()
2122

2223
let actionList = configureActionList()
2324

2425
blocks = [
2526
.actionList(model: actionList),
2627
.action(model: defaultAction),
2728
.action(model: destructiveAction),
28-
.action(model: openScreenAction)
29+
.action(model: openScreenAction),
30+
.action(model: pushScreenAction)
2931
]
3032

3133
return .init(title: L10n.Actions.header, blocks: blocks)
@@ -51,7 +53,15 @@ private extension ActionsSectionBuilder {
5153
func getOpenScreenAction() -> DebugScreenAction {
5254
let action: DebugScreenAction = .init(title: L10n.Actions.openScreenTitle) {
5355
let view = DestinationViewController()
54-
DebugScreenPresenterService.shared.showCustomScreen(view)
56+
DebugScreenPresenterService.shared.presentCustomScreen(view)
57+
}
58+
return action
59+
}
60+
61+
func getPushScreenAction() -> DebugScreenAction {
62+
let action: DebugScreenAction = .init(title: L10n.Actions.pushScreenTitle) {
63+
let view = DestinationViewController()
64+
DebugScreenPresenterService.shared.pushCustomScreen(view)
5565
}
5666
return action
5767
}

Example/DebugScreenExample/App/DebugScreenConfiguration/Builders/MenuItemsSectionBuilder.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ private extension MenuItemsSectionBuilder {
3535
showsDisclosure: true
3636
) {
3737
let view = DestinationViewController()
38-
DebugScreenPresenterService.shared.showCustomScreen(view)
38+
DebugScreenPresenterService.shared.presentCustomScreen(view)
3939
}
4040

4141
let multilineItem = DebugScreenMenuItem(

Example/DebugScreenExample/Library/Resources/Strings/Strings.swift

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,8 @@ internal enum L10n {
2727
internal static let header = L10n.tr("Localizable", "Actions.header")
2828
/// Открытие экрана
2929
internal static let openScreenTitle = L10n.tr("Localizable", "Actions.openScreenTitle")
30+
/// Пуш экрана
31+
internal static let pushScreenTitle = L10n.tr("Localizable", "Actions.pushScreenTitle")
3032
/// Вспомогательное
3133
internal static let secondaryTitle = L10n.tr("Localizable", "Actions.secondaryTitle")
3234
}

Example/DebugScreenExample/Library/Resources/Strings/en.lproj/Localizable.strings

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
"Actions.secondaryTitle" = "Secondary";
1313
"Actions.destructiveTitle" = "Destructive";
1414
"Actions.openScreenTitle" = "Open Screen";
15+
"Actions.pushScreenTitle" = "Push Screen";
1516

1617
// MARK: - ActionList
1718

Example/DebugScreenExample/Library/Resources/Strings/ru.lproj/Localizable.strings

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
"Actions.secondaryTitle" = "Вспомогательное";
1313
"Actions.destructiveTitle" = "Удаление";
1414
"Actions.openScreenTitle" = "Открытие экрана";
15+
"Actions.pushScreenTitle" = "Пуш экрана";
1516

1617
// MARK: - ActionList
1718

0 commit comments

Comments
 (0)