-
-
Notifications
You must be signed in to change notification settings - Fork 120
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
FEATURE - Home Screen Quick Actions (#78)
- Loading branch information
1 parent
4351728
commit 10d1d8d
Showing
8 changed files
with
247 additions
and
28 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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd"> | ||
<plist version="1.0"> | ||
<dict> | ||
<key>UIApplicationShortcutItems</key> | ||
<array> | ||
<dict> | ||
<key>UIApplicationShortcutItemIconSymbolName</key> | ||
<string>wrench.and.screwdriver.fill</string> | ||
<key>UIApplicationShortcutItemTitle</key> | ||
<string>New Maintenence</string> | ||
<key>UIApplicationShortcutItemType</key> | ||
<string>NewMaintenance</string> | ||
</dict> | ||
<dict> | ||
<key>UIApplicationShortcutItemIconSymbolName</key> | ||
<string>plus.circle.fill</string> | ||
<key>UIApplicationShortcutItemTitle</key> | ||
<string>Add Vehicle</string> | ||
<key>UIApplicationShortcutItemType</key> | ||
<string>AddVehicle</string> | ||
</dict> | ||
</array> | ||
</dict> | ||
</plist> |
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,56 @@ | ||
// | ||
// MainTabView.swift | ||
// Basic-Car-Maintenance | ||
// | ||
// Created by Omar Hegazy on 05/10/2023. | ||
// | ||
|
||
import SwiftUI | ||
|
||
enum TabSelection: Int { | ||
case dashboard = 0 | ||
case settings = 1 | ||
} | ||
|
||
@MainActor | ||
struct MainTabView: View { | ||
@Environment(ActionService.self) var actionService | ||
@Environment(\.scenePhase) var scenePhase | ||
@State var authenticationViewModel = AuthenticationViewModel() | ||
@State var selectedTab: TabSelection = .dashboard | ||
|
||
var body: some View { | ||
TabView(selection: $selectedTab) { | ||
DashboardView(authenticationViewModel: authenticationViewModel) | ||
.tag(TabSelection.dashboard) | ||
.tabItem { | ||
Label("Dashboard", systemImage: "list.dash.header.rectangle") | ||
} | ||
|
||
SettingsView(authenticationViewModel: authenticationViewModel) | ||
.tag(TabSelection.settings) | ||
.tabItem { | ||
Label("Settings", systemImage: "gear") | ||
} | ||
} | ||
.onChange(of: scenePhase) { _, newScenePhase in | ||
guard | ||
case .active = newScenePhase, | ||
let action = actionService.action | ||
else { return } | ||
|
||
// select the tab where the desired view is located to make sure | ||
// it is presented from the proper hierarchy. | ||
switch action { | ||
case .newMaintenance: | ||
selectedTab = .dashboard | ||
case .addVehicle: | ||
selectedTab = .settings | ||
} | ||
} | ||
} | ||
} | ||
|
||
#Preview { | ||
MainTabView() | ||
} |
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,31 @@ | ||
// | ||
// Action.swift | ||
// Basic-Car-Maintenance | ||
// | ||
// Created by Omar Hegazy on 05/10/2023. | ||
// | ||
|
||
import UIKit | ||
|
||
enum ActionType: String { | ||
case newMaintenance = "NewMaintenance" | ||
case addVehicle = "AddVehicle" | ||
} | ||
|
||
enum Action: Equatable { | ||
case newMaintenance | ||
case addVehicle | ||
|
||
init?(shortcutItem: UIApplicationShortcutItem) { | ||
guard let type = ActionType(rawValue: shortcutItem.type) else { | ||
return nil | ||
} | ||
|
||
switch type { | ||
case .newMaintenance: | ||
self = .newMaintenance | ||
case .addVehicle: | ||
self = .addVehicle | ||
} | ||
} | ||
} |
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