-
Notifications
You must be signed in to change notification settings - Fork 38
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #52 from novoda/feature/RM-49-convert-viewControll…
…ers-swiftui Feature/[RM-49] - Convert view controllers swiftui
- Loading branch information
Showing
5 changed files
with
48 additions
and
11 deletions.
There are no files selected for viewing
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
18 changes: 8 additions & 10 deletions
18
Rick-and-Morty/Rick And Morty/ViewControllers/TabBarController.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,18 +1,16 @@ | ||
import UIKit | ||
import SwiftUI | ||
|
||
class TabBarController: UITabBarController, UITabBarControllerDelegate { | ||
|
||
override func viewDidLoad() { | ||
// Rick tab index: 0 | ||
let rickNavController = self.viewControllers![0] as! UINavigationController | ||
let rickViewController = rickNavController.topViewController as! CharacterCollectionViewController | ||
rickViewController.charactersTitle = "Rick" | ||
rickViewController.characters = ricks | ||
|
||
// Morty tab index: 1 | ||
let mortyNavController = self.viewControllers![1] as! UINavigationController | ||
let mortyViewController = mortyNavController.topViewController as! CharacterCollectionViewController | ||
mortyViewController.charactersTitle = "Morty" | ||
mortyViewController.characters = morties | ||
let rickViewController = UIHostingController(rootView: CharactersView(characters: ricks, title: "Ricks")) | ||
rickViewController.tabBarItem = UITabBarItem(title: "Ricks", image: UIImage(named: "rick-icon"), tag: 1) | ||
|
||
let mortyViewController = UIHostingController(rootView: CharactersView(characters: morties, title: "Morties")) | ||
mortyViewController.tabBarItem = UITabBarItem(title: "Morties", image: UIImage(named: "morty-icon"), tag: 2) | ||
|
||
self.setViewControllers([rickViewController, mortyViewController], animated: false) | ||
} | ||
} |
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,30 @@ | ||
import SwiftUI | ||
|
||
struct CharactersView: View { | ||
let characters: [Character] | ||
let title: String | ||
|
||
var body: some View { | ||
NavigationView { | ||
ScrollView(.vertical) { | ||
VStack(alignment: .leading) { | ||
ForEach(characters, id: \.id) { character in | ||
CharacterCell(character: character, imagePosition: getImagePosition(character: character)) | ||
.frame(minWidth: 0, maxWidth: .infinity, minHeight: 0, maxHeight: 120) | ||
} | ||
} | ||
} | ||
.navigationBarTitle(title) | ||
} | ||
} | ||
|
||
func getImagePosition(character: Character) -> CharacterImagePosition { | ||
character is Rick ? .right : .left | ||
} | ||
} | ||
|
||
struct CharactersView_Previews: PreviewProvider { | ||
static var previews: some View { | ||
CharactersView(characters: ricks, title: "Ricks") | ||
} | ||
} |