Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for iPad split screen #76

Draft
wants to merge 2 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 18 additions & 1 deletion iOS/BattleBuddy/Info.plist
Original file line number Diff line number Diff line change
Expand Up @@ -60,14 +60,31 @@
<key>NSAllowsArbitraryLoadsInWebContent</key>
<true/>
</dict>
<key>UIApplicationSceneManifest</key>
<dict>
<key>UIApplicationSupportsMultipleScenes</key>
<true/>
<key>UISceneConfigurations</key>
<dict>
<key>UIWindowSceneSessionRoleApplication</key>
<array>
<dict>
<key>UISceneConfigurationName</key>
<string>Default Configuration</string>
<key>UISceneDelegateClassName</key>
<string>$(PRODUCT_MODULE_NAME).SceneDelegate</string>
</dict>
</array>
</dict>
</dict>
<key>UILaunchStoryboardName</key>
<string>LaunchScreen</string>
<key>UIRequiredDeviceCapabilities</key>
<array>
<string>armv7</string>
</array>
<key>UIRequiresFullScreen</key>
<true/>
<false/>
<key>UIStatusBarStyle</key>
<string>UIStatusBarStyleDefault</string>
<key>UISupportedInterfaceOrientations</key>
Expand Down
107 changes: 95 additions & 12 deletions iOS/BattleBuddy/Source/Infrastructure/AppDelegate.swift
Original file line number Diff line number Diff line change
Expand Up @@ -14,22 +14,74 @@ import Crashlytics

@UIApplicationMain
class AppDelegate: UIResponder, UIApplicationDelegate, SessionDelegate {

var window: UIWindow?
let tabBarController = BaseTabBarController()
let dependencyManager = DependencyManagerImpl.shared
var hasSessionFinishedLaunching: Bool = false

override init() {
super.init()

dependencyManager.assembleDependencies(self)
}

func applicationDidFinishLaunching(_ application: UIApplication) {
// UIApplicationDelegate

func applicationDidFinishLaunching(_ application: UIApplication) {
if #available(iOS 13.0, *) {
setupApplication()
return
}

self.window = UIWindow.init(frame: UIScreen.main.bounds)
self.window?.backgroundColor = UIColor.Theme.background
self.window?.rootViewController = LoadingViewController()
defer { self.window?.makeKeyAndVisible() }

setupApplication()
}

func applicationDidBecomeActive(_ application: UIApplication) {
// dependencyManager.twitchManager().refreshTwitchInfo() TODO: UPDATE FOR NEW TWITCH API
dependencyManager.metadataManager().updateGlobalMetadata { (globalMetadata) -> Void in }
}

@available(iOS 13.0, *)
func sceneDidBecomeActive(_ scene: UIScene) {
// dependencyManager.twitchManager().refreshTwitchInfo() TODO: UPDATE FOR NEW TWITCH API
dependencyManager.metadataManager().updateGlobalMetadata { (globalMetadata) -> Void in }
}

// SessionDelegate

func sessionDidFinishLoading() {
reloadRootViewController()
dependencyManager.feedbackManager().promptForReviewIfNecessary()

hasSessionFinishedLaunching = true
}

// Internal

func reloadRootViewController() {
if #available(iOS 13.0, *) {
for scene in UIApplication.shared.connectedScenes {
guard let sceneDelegate = scene.delegate as? SceneDelegate else {
continue
}

sceneDelegate.reloadRootViewController()
}
} else {
self.tabBarController.setup()
self.window?.rootViewController = self.tabBarController
}
}

// Private

private func setupApplication() {
// If we're running unit tests, bail out here as we don't want any
// more real app-launch stuff to be processed.
guard NSClassFromString("XCTestCase") == nil else { return }
Expand All @@ -38,15 +90,52 @@ class AppDelegate: UIResponder, UIApplicationDelegate, SessionDelegate {
dependencyManager.accountManager().initializeSession()
Fabric.with([Crashlytics.self])
}
}

// SessionDelegate

func sessionDidFinishLoading() {
reloadRootViewController()
dependencyManager.feedbackManager().promptForReviewIfNecessary()
@available(iOS 13.0, *)
class SceneDelegate: UIResponder, UISceneDelegate {

var window: UIWindow?

// UISceneDelegate

func scene(_ scene: UIScene, willConnectTo session: UISceneSession, options connectionOptions: UIScene.ConnectionOptions) {
guard let windowScene = (scene as? UIWindowScene) else { return }

let window = UIWindow(windowScene: windowScene)
self.window = window
defer { window.makeKeyAndVisible() }

window.backgroundColor = UIColor.Theme.background

if
let appDelegate = UIApplication.shared.delegate as? AppDelegate,
appDelegate.hasSessionFinishedLaunching
{
reloadRootViewController()
} else {
window.rootViewController = LoadingViewController()
}
}

// Internal

func reloadRootViewController() {
guard let window = window else {
return
}

let tabBarController = BaseTabBarController()
tabBarController.setup()
window.rootViewController = tabBarController
}
}


fileprivate extension BaseTabBarController {

func setup() {
let itemsVC = ItemsMenuViewController()
itemsVC.title = "items".local()
itemsVC.tabBarItem.image = UIImage(named: "items")
Expand All @@ -62,12 +151,6 @@ class AppDelegate: UIResponder, UIApplicationDelegate, SessionDelegate {
moreVC.tabBarItem.image = UIImage(named: "more")
let moreNC = BaseNavigationController(rootViewController: moreVC)

self.tabBarController.setViewControllers([itemsNC, learnNC, moreNC], animated: false)
self.window?.rootViewController = self.tabBarController
}

func applicationDidBecomeActive(_ application: UIApplication) {
// dependencyManager.twitchManager().refreshTwitchInfo() TODO: UPDATE FOR NEW TWITCH API
dependencyManager.metadataManager().updateGlobalMetadata { (globalMetadata) -> Void in }
setViewControllers([itemsNC, learnNC, moreNC], animated: false)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import UIKit

protocol DependencyManager {
static var shared: DependencyManager { get }
func assembleDependencies(_ appDelegate: AppDelegate)
func assembleDependencies(_ appDelegate: SessionDelegate)
func pushNotificationManager() -> PushNotificationManager
func accountManager() -> AccountManager
func databaseManager() -> DatabaseManager
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ class DependencyManagerImpl: DependencyManager {
var deviceMngr: DeviceManager?
var localeMngr: LocaleManager?

func assembleDependencies(_ appDelegate: AppDelegate) {
func assembleDependencies(_ appDelegate: SessionDelegate) {
// Firebase handles sessions, accounts, storage, and metadata
let firebase = FirebaseManager(sessionDelegate: appDelegate)
pushNotificationMngr = firebase
Expand Down
6 changes: 3 additions & 3 deletions iOS/Podfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -207,8 +207,8 @@ SPEC REPOS:
SPEC CHECKSUMS:
Alamofire: ae5c501addb7afdbb13687d7f2f722c78734c2d3
BoringSSL-GRPC: db8764df3204ccea016e1c8dd15d9a9ad63ff318
Crashlytics: 2dfd686bcb918dc10ee0e76f7f853fe42c7bd552
Fabric: 706c8b8098fff96c33c0db69cbf81f9c551d0d74
Crashlytics: d3e5090419ddee1003192c98ac0e6dfdb1dba266
Fabric: ea977e3cd9c20425516d3dafd3bf8c941c51223f
Firebase: c35912a5c160193dc423f260dac3f167a1a795ab
FirebaseAnalytics: 843c7f64a8f9c79f0d03281197ebe7bb1d58d477
FirebaseAnalyticsInterop: d48b6ab67bcf016a05e55b71fc39c61c0cb6b7f3
Expand Down Expand Up @@ -239,4 +239,4 @@ SPEC CHECKSUMS:

PODFILE CHECKSUM: 2a1a1bb9323cfcc2df93630a749109aa521a46e0

COCOAPODS: 1.9.3
COCOAPODS: 1.11.2