-
Notifications
You must be signed in to change notification settings - Fork 81
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Start of SwiftUI integration in generator (#61)
* Parameters update * Generated templates * Additions for hosting and swiftUI modules * Hosted SwiftUI templates fixed, native SwiftUI module hidden * Templates updated with empty lines fixes, StateObject switched to ObservedObject * Update README.md * Squashed commit of the following: commit 42ae805 Merge: 33bbb70 f953f84 Author: Filip Gulan <[email protected]> Date: Mon Oct 30 10:48:56 2023 +0100 Merge pull request #64 from l1Dan/master Replace the file header comment with '___FILEHEADER___' commit f953f84 Author: Leo Lee <[email protected]> Date: Sat Sep 2 13:57:15 2023 +0800 Replace the file header comment with '___FILEHEADER___' * New lines update,HostingNavigationController added, hiding navigation bar added to viewIsAppearing because of ios 15 issues * headers added, readme updated, default value added in demo project * Readme update --------- Co-authored-by: ilucijabalja <[email protected]>
- Loading branch information
1 parent
fcdda2b
commit b6ef9e7
Showing
115 changed files
with
802 additions
and
219 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
3 changes: 2 additions & 1 deletion
3
Templates/Resources/Templates/___FILEBASENAME___Formatter.swift.erb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,9 @@ | ||
//___FILEHEADER___ | ||
// This file was generated by the 🐍 VIPER generator | ||
// | ||
|
||
<% if [email protected]_swift_ui_view %> | ||
import UIKit | ||
<% end -%> | ||
<% if @template.generate_io -%> | ||
import RxSwift | ||
import RxCocoa | ||
|
9 changes: 8 additions & 1 deletion
9
Templates/Resources/Templates/___FILEBASENAME___Interfaces.swift.erb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,24 +1,31 @@ | ||
//___FILEHEADER___ | ||
// This file was generated by the 🐍 VIPER generator | ||
// | ||
|
||
<% if [email protected]_swift_ui_view %> | ||
import UIKit | ||
<% end -%> | ||
<% if @template.generate_io -%> | ||
import RxSwift | ||
import RxCocoa | ||
<% end -%> | ||
|
||
<% if @template.generate_ui_kit_wireframe -%> | ||
protocol ___VARIABLE_moduleName___WireframeInterface: WireframeInterface { | ||
} | ||
<% end -%> | ||
<% if [email protected]_using_hosted_vc && [email protected]_swift_ui_view -%> | ||
|
||
protocol ___VARIABLE_moduleName___ViewInterface: ViewInterface { | ||
} | ||
<% end -%> | ||
<% if [email protected]_swift_ui_view -%> | ||
|
||
protocol ___VARIABLE_moduleName___PresenterInterface: PresenterInterface { | ||
<% if @template.generate_io -%> | ||
func configure(with output: ___VARIABLE_moduleName___.ViewOutput) -> ___VARIABLE_moduleName___.ViewInput | ||
<% end -%> | ||
} | ||
<% end -%> | ||
<% if @complexity.generate_formatter -%> | ||
|
||
protocol ___VARIABLE_moduleName___FormatterInterface: FormatterInterface { | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -8,42 +8,51 @@ import RxSwift | |
import RxCocoa | ||
<% end -%> | ||
|
||
final class ___VARIABLE_moduleName___Presenter { | ||
final class ___VARIABLE_moduleName___Presenter<%= @template.generate_swift_ui_view ? ': ObservableObject' : '' %> { | ||
<% if @template.generate_swift_ui_wireframe -%> | ||
|
||
final class Navigation: ObservableObject { | ||
|
||
} | ||
<%- end -%> | ||
|
||
// MARK: - Private properties - | ||
|
||
<% if @template.generate_vc -%> | ||
private unowned let view: ___VARIABLE_moduleName___ViewInterface | ||
<% end -%> | ||
<% if @complexity.generate_formatter -%> | ||
private let formatter: ___VARIABLE_moduleName___FormatterInterface | ||
<% end -%> | ||
<% if @complexity.generate_interactor -%> | ||
private let interactor: ___VARIABLE_moduleName___InteractorInterface | ||
<% end -%> | ||
<% if @template.generate_ui_kit_wireframe -%> | ||
private let wireframe: ___VARIABLE_moduleName___WireframeInterface | ||
<% else -%> | ||
private let navigation: Navigation | ||
<% end -%> | ||
|
||
// MARK: - Lifecycle - | ||
|
||
init( | ||
view: ___VARIABLE_moduleName___ViewInterface, | ||
<%- if @complexity.generate_formatter -%> | ||
<%= @complexity.generate_formatter ? 'formatter: ___VARIABLE_moduleName___FormatterInterface,' : '' %> | ||
<%- end -%> | ||
<%- if @complexity.generate_interactor -%> | ||
<%= @complexity.generate_interactor ? 'interactor: ___VARIABLE_moduleName___InteractorInterface,' : '' %> | ||
<%- end -%> | ||
wireframe: ___VARIABLE_moduleName___WireframeInterface | ||
) { | ||
init(<%= @template.generate_vc ? 'view: ___VARIABLE_moduleName___ViewInterface, ' : '' %><%= @complexity.generate_formatter ? 'formatter: ___VARIABLE_moduleName___FormatterInterface, ' : '' %><%= @complexity.generate_interactor ? 'interactor: ___VARIABLE_moduleName___InteractorInterface, ' : '' %><%= @template.generate_ui_kit_wireframe ? 'wireframe: ___VARIABLE_moduleName___WireframeInterface' : '' %><%= @template.generate_swift_ui_wireframe ? 'navigation: Navigation' : '' %>) { | ||
<%- if @template.generate_vc -%> | ||
self.view = view | ||
<%- end -%> | ||
<%- if @complexity.generate_formatter -%> | ||
self.formatter = formatter | ||
<%- end -%> | ||
<%- if @complexity.generate_interactor -%> | ||
self.interactor = interactor | ||
<%- end -%> | ||
<%- if @template.generate_ui_kit_wireframe -%> | ||
self.wireframe = wireframe | ||
<%- else -%> | ||
self.navigation = navigation | ||
<%- end -%> | ||
} | ||
} | ||
|
||
<% if [email protected]_using_hosted_vc && [email protected]_swift_ui_view %> | ||
// MARK: - Extensions - | ||
|
||
extension ___VARIABLE_moduleName___Presenter: ___VARIABLE_moduleName___PresenterInterface { | ||
|
@@ -62,3 +71,4 @@ extension ___VARIABLE_moduleName___Presenter: ___VARIABLE_moduleName___Presenter | |
|
||
<%- end -%> | ||
} | ||
<% end -%> |
14 changes: 14 additions & 0 deletions
14
Templates/Resources/Templates/___FILEBASENAME___View.swift.erb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
//___FILEHEADER___ | ||
// This file was generated by the 🐍 VIPER generator | ||
// | ||
|
||
import SwiftUI | ||
|
||
struct ___VARIABLE_moduleName___View: View { | ||
|
||
@ObservedObject var presenter: ___VARIABLE_moduleName___Presenter | ||
|
||
var body: some View { | ||
Text(/*@START_MENU_TOKEN@*/"Hello, World!"/*@END_MENU_TOKEN@*/) | ||
} | ||
} |
22 changes: 22 additions & 0 deletions
22
Templates/Resources/Templates/___FILEBASENAME___WireframeSwiftUI.swift.erb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
//___FILEHEADER___ | ||
// This file was generated by the 🐍 VIPER generator | ||
// | ||
|
||
import SwiftUI | ||
|
||
struct ___VARIABLE_moduleName___Wireframe: View { | ||
|
||
@StateObject var navigation = ___VARIABLE_moduleName___Presenter.Navigation() | ||
|
||
var body: some View { | ||
<%- if @complexity.generate_formatter -%> | ||
let formatter = ___VARIABLE_moduleName___Formatter() | ||
<%- end -%> | ||
<%- if @complexity.generate_interactor -%> | ||
let interactor = ___VARIABLE_moduleName___Interactor() | ||
<%- end -%> | ||
let presenter = ___VARIABLE_moduleName___Presenter(<%= @complexity.generate_formatter ? 'formatter: formatter, ' : '' %><%= @complexity.generate_interactor ? 'interactor: interactor, ' : '' %>navigation: navigation) | ||
|
||
___VARIABLE_moduleName___View(presenter: presenter) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 2 additions & 0 deletions
2
...VIPER Interfaces/FormatterInterface.swift → ...faces.xctemplate/FormatterInterface.swift
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,5 @@ | ||
//___FILEHEADER___ | ||
|
||
protocol FormatterInterface: AnyObject { | ||
} | ||
|
||
|
9 changes: 9 additions & 0 deletions
9
...R Templates/Base SwiftUI Hosted Interfaces.xctemplate/HostingNavigationConfigurable.swift
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
//___FILEHEADER___ | ||
|
||
import UIKit | ||
|
||
protocol HostingNavigationConfigurable: AnyObject { | ||
|
||
var shouldHideNavigationBar: Bool { get } | ||
|
||
} |
28 changes: 28 additions & 0 deletions
28
...PER Templates/Base SwiftUI Hosted Interfaces.xctemplate/HostingNavigationController.swift
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
//___FILEHEADER___ | ||
|
||
import UIKit | ||
|
||
/// Navigation controller that should be used only in combination with the ``LazyHostingViewController``. | ||
/// | ||
/// It overrides the ``setNavigationBarHidden(_:animated:)`` method in a way where it will always ask | ||
/// the currently pushed view controller for its preference stored in the ``HostingNavigationConfigurable/shouldHideNavigationBar`` | ||
/// parameter, ignoring any actual parameters passed to it. | ||
/// | ||
/// This is done in such a way because at some point during the layout process SwiftUI also | ||
/// tries to change the current navigation bar visibility even thouh it shouldn't. | ||
class HostingNavigationController: UINavigationController { | ||
|
||
override func setNavigationBarHidden(_ hidden: Bool, animated: Bool) { | ||
guard let hostingChild = children.last as? HostingNavigationConfigurable | ||
else { | ||
// In case the last pushed controller is not a HostingNavigationConfigurable, | ||
// we can simply call super here since we're not dealing with SwiftUI | ||
// but with regular UIKit. | ||
super.setNavigationBarHidden(hidden, animated: animated) | ||
return | ||
} | ||
|
||
super.setNavigationBarHidden(hostingChild.shouldHideNavigationBar, animated: animated) | ||
} | ||
|
||
} |
2 changes: 2 additions & 0 deletions
2
...IPER Interfaces/InteractorInterface.swift → ...aces.xctemplate/InteractorInterface.swift
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,5 @@ | ||
//___FILEHEADER___ | ||
|
||
protocol InteractorInterface: AnyObject { | ||
} | ||
|
||
|
Oops, something went wrong.