Skip to content

Commit

Permalink
Add Features build file, update deployment target to 17.6, refactor s…
Browse files Browse the repository at this point in the history
…creen navigation structure, and improve app icon retrieval logic.
  • Loading branch information
alexejn committed Aug 18, 2024
1 parent 45d6f2e commit ce19ceb
Show file tree
Hide file tree
Showing 25 changed files with 556 additions and 216 deletions.
11 changes: 9 additions & 2 deletions Demo/ViewURL/DemoScreens.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
4F0221E12C5A7A62009EA375 /* Login.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4F0221E02C5A7A62009EA375 /* Login.swift */; };
4F0221E42C5A7BE4009EA375 /* ChoseTheme.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4F0221E32C5A7BE4009EA375 /* ChoseTheme.swift */; };
4F0221E62C5A857C009EA375 /* SongListView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4F0221E52C5A857C009EA375 /* SongListView.swift */; };
4F124F7E2C7024D30076FADC /* Features in Frameworks */ = {isa = PBXBuildFile; productRef = 4F124F7D2C7024D30076FADC /* Features */; };
4F8C89842C3D814200036416 /* Settings.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4F8C89832C3D814200036416 /* Settings.swift */; };
4F94ED052C38765800CDE243 /* MusicApp.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4F94ED042C38765800CDE243 /* MusicApp.swift */; };
4F94ED072C38765800CDE243 /* Library.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4F94ED062C38765800CDE243 /* Library.swift */; };
Expand Down Expand Up @@ -57,6 +58,7 @@
buildActionMask = 2147483647;
files = (
4FFC71C22C5C04B500586EF6 /* Features in Frameworks */,
4F124F7E2C7024D30076FADC /* Features in Frameworks */,
);
runOnlyForDeploymentPostprocessing = 0;
};
Expand Down Expand Up @@ -147,6 +149,7 @@
name = DemoScreens;
packageProductDependencies = (
4FFC71C12C5C04B500586EF6 /* Features */,
4F124F7D2C7024D30076FADC /* Features */,
);
productName = ViewURL;
productReference = 4F94ED012C38765800CDE243 /* DemoScreens.app */;
Expand Down Expand Up @@ -362,7 +365,7 @@
INFOPLIST_KEY_UILaunchScreen_Generation = YES;
INFOPLIST_KEY_UISupportedInterfaceOrientations_iPad = "UIInterfaceOrientationPortrait UIInterfaceOrientationPortraitUpsideDown UIInterfaceOrientationLandscapeLeft UIInterfaceOrientationLandscapeRight";
INFOPLIST_KEY_UISupportedInterfaceOrientations_iPhone = "UIInterfaceOrientationPortrait UIInterfaceOrientationLandscapeLeft UIInterfaceOrientationLandscapeRight";
IPHONEOS_DEPLOYMENT_TARGET = 17.0;
IPHONEOS_DEPLOYMENT_TARGET = 17.6;
LD_RUNPATH_SEARCH_PATHS = (
"$(inherited)",
"@executable_path/Frameworks",
Expand Down Expand Up @@ -393,7 +396,7 @@
INFOPLIST_KEY_UILaunchScreen_Generation = YES;
INFOPLIST_KEY_UISupportedInterfaceOrientations_iPad = "UIInterfaceOrientationPortrait UIInterfaceOrientationPortraitUpsideDown UIInterfaceOrientationLandscapeLeft UIInterfaceOrientationLandscapeRight";
INFOPLIST_KEY_UISupportedInterfaceOrientations_iPhone = "UIInterfaceOrientationPortrait UIInterfaceOrientationLandscapeLeft UIInterfaceOrientationLandscapeRight";
IPHONEOS_DEPLOYMENT_TARGET = 17.0;
IPHONEOS_DEPLOYMENT_TARGET = 17.6;
LD_RUNPATH_SEARCH_PATHS = (
"$(inherited)",
"@executable_path/Frameworks",
Expand Down Expand Up @@ -431,6 +434,10 @@
/* End XCConfigurationList section */

/* Begin XCSwiftPackageProductDependency section */
4F124F7D2C7024D30076FADC /* Features */ = {
isa = XCSwiftPackageProductDependency;
productName = Features;
};
4FFC71C12C5C04B500586EF6 /* Features */ = {
isa = XCSwiftPackageProductDependency;
productName = Features;
Expand Down

This file was deleted.

87 changes: 49 additions & 38 deletions Demo/ViewURL/ViewURL/Screens/Library.swift
Original file line number Diff line number Diff line change
Expand Up @@ -16,54 +16,65 @@ struct LibraryView {
@State var nativeSheet = false

var screenBody: some View {
NavigationView {
if searchText.isEmpty {
List {
NavigationLink("Info") {
InfoScreen()
}
NavigationStack{
Group {
if searchText.isEmpty {
List {
NavigationLink("Info") {
InfoScreen()
}

Button("fullscreen") {
Screens.current.fullscreen(InfoScreen(), modifier: .closeButton)
}
Button("fullscreen") {
Screens.current.fullscreen(InfoScreen(), modifier: .closeButton)
}

Button("fullscreen-action") {
Screens.action(.fullscreen, screen: InfoScreen())
}
Button("fullscreen-action") {
Screens.action(.fullscreen, screen: InfoScreen())
}

Button("Sheet-Info") {
Screens.current.sheet(InfoScreen(), modifier: .closeButton)
}
Button("Sheet-Info") {
Screens.current.sheet(InfoScreen(), modifier: .closeButton)
}

Button("Sheet-Song") {
Screens.current.sheet(SongView(song: .duHast), modifier: .closeButton)
}
Button("Native Sheet") {
nativeSheet.toggle()
}
NavigationLink("Song") {
SongView(song: .duHast)
}

Section("Green") {
SongListView(songs: [.duHast, .someSong])
}
.environment(\.color, .green)
Button("Push-Song") {
Screens.current.push(SongView(song: .duHast))
}

Section("Red") {
SongListView(songs: [.elPoblema])
}
.environment(\.color, .red)
Button("Sheet-Song") {
Screens.current.sheet(SongView(song: .duHast), modifier: .closeButton)
}
Button("Native Sheet") {
nativeSheet.toggle()
}

Section("Green") {
SongListView(songs: [.duHast, .someSong])
}
.environment(\.color, .green)

Section("Red") {
SongListView(songs: [.elPoblema])
}
.environment(\.color, .red)

Section("Blue") {
SongListView(songs: app.all.filter { $0.author == .morgenstern })
Section("Blue") {
SongListView(songs: app.all.filter { $0.author == .morgenstern })
}
.environment(\.color, .blue)
}
.environment(\.color, .blue)
.searchable(text: $searchText, prompt: "Search")
.sheet(isPresented: $nativeSheet, content: {
SongView(song: .duHast)
})
} else {
SearchScreen(searchText: $searchText)
}
.searchable(text: $searchText, prompt: "Search")
.sheet(isPresented: $nativeSheet, content: {
SongView(song: .duHast)
})
} else {
SearchScreen(searchText: $searchText)
}
.screenNavigationDestination
}

}
Expand Down
3 changes: 2 additions & 1 deletion Demo/ViewURL/ViewURL/Screens/Song.swift
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ struct SongView {
}

var screenBody: some View {
NavigationStack {
ScreenStack {
if song == .empty {
Text("Song not found")
} else {
Expand All @@ -61,6 +61,7 @@ struct SongView {
.padding()
.background(color.opacity(0.2))
.navigationTitle(song.title)
.screenNavigationDestination
}
}
.screen(tag: song.title)
Expand Down
14 changes: 12 additions & 2 deletions Sources/BrowserMessages/AppInfo.swift
Original file line number Diff line number Diff line change
Expand Up @@ -34,10 +34,20 @@ public extension AppInfo {

info.bundleID = Bundle.main.bundleIdentifier ?? ""
info.name = Bundle.main.infoDictionary?["CFBundleName"] as? String ?? ""
let image = UIImage(systemName: "wifi")
info.logo = image?.jpegData(compressionQuality: 1)

if let image = getCurrentAppIcon() {
info.logo = image.jpegData(compressionQuality: 1)
}
return info
}

static func getCurrentAppIcon() -> UIImage? {
guard let iconsDictionary = Bundle.main.infoDictionary?["CFBundleIcons"] as? [String:Any],
let primaryIconsDictionary = iconsDictionary["CFBundlePrimaryIcon"] as? [String:Any],
let iconFiles = primaryIconsDictionary["CFBundleIconFiles"] as? [String],
let lastIcon = iconFiles.last else { return nil }
return UIImage(named: lastIcon)
}
}
#endif

84 changes: 0 additions & 84 deletions Sources/BrowserMessages/AppLiveState.swift
Original file line number Diff line number Diff line change
Expand Up @@ -6,75 +6,6 @@
import Foundation
import SwiftUI

public struct NodeStackInfo: Codable, Hashable {
public let stackID: ViewController.ID
public let index: Int

public init(stackID: ViewController.ID, index: Int) {
self.stackID = stackID
self.index = index
}
}

public typealias ScreenID = UUID

public struct ScreeSize: Codable, Hashable, CustomStringConvertible {
public let width: Double
public let height: Double

public init(width: Double, height: Double) {
self.width = width
self.height = height
}

public init(size: CGSize) {
self.width = size.width
self.height = size.height
}

public var description: String {
"\(Int(width))x\(Int(height))"
}
}

public struct ScreenLiveInfo: Hashable, Codable {
public let staticID: ScreenStaticID
public let screenID: ScreenID
public let tag: String?
public let children: [ScreenID]
public let size: ScreeSize
public let parentScreenID: ScreenID?
public let state: ScreenState
public let stack: NodeStackInfo?
public let info: String
public var type: String { staticID.type }
public var file: String { staticID.file }

public let alias: String?

public init(screenID: ScreenID,
staticID: ScreenStaticID,
alias: String?,
tag: String?,
parentScreenID: ScreenID?,
state: ScreenState,
size: ScreeSize,
stack: NodeStackInfo?,
children: [ScreenID] = [],
info: String) {
self.screenID = screenID
self.staticID = staticID
self.alias = alias
self.tag = tag
self.parentScreenID = parentScreenID
self.state = state
self.size = size
self.stack = stack
self.info = info
self.children = children
}
}

public struct AppLiveState: Codable {
public var screens: [ScreenLiveInfo]
public let currentFeatureNodeID: ViewController.ID?
Expand All @@ -95,18 +26,3 @@ public struct AppLiveState: Codable {
self.current = current
}
}

public struct ScreenShoot: Codable {
public let screenID: ScreenID
public let data: Data

public init(screenID: ScreenID, data: Data) {
self.screenID = screenID
self.data = data
}
}


public extension UUID {
static var zero = UUID(uuidString: "00000000-0000-0000-0000-000000000000")!
}
4 changes: 4 additions & 0 deletions Sources/BrowserMessages/BrowserMessage.swift
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ public enum BrowserMessage {
case appLiveState(AppLiveState)
case screensStaticInfo([ScreenStaticInfo])
case screenURLError(ScreenURL, String)
case error(String)
case screenEvent(ScreenEvent)

public var debugDescription: String {
switch self {
Expand All @@ -24,6 +26,8 @@ public enum BrowserMessage {
case .screenShoot: "screenShoot"
case .screen: "screen"
case .screensStaticInfo: "screensStaticInfo"
case .screenEvent(let event): event.description
case let .error(error): "Error: \(error)"
case let .screenURLError(url, error): "Failed to open \(url). Error: \(error)"
}
}
Expand Down
43 changes: 43 additions & 0 deletions Sources/BrowserMessages/ScreenEvent.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
//
// Created by Alexey Nenastyev on 18.8.24.
// Copyright © 2024 Alexey Nenastyev (github.com/alexejn). All Rights Reserved.
import Foundation

public struct ScreenEvent: CustomStringConvertible, Codable {
let screenStaticID: ScreenStaticID
let id: ScreenID
let kind: Kind

public enum Kind: Codable, CustomStringConvertible {
case didAppear
case didDisappear
case willSheet(ScreenStaticID)
case willFullscreen(ScreenStaticID)
case willPush(ScreenStaticID)

public var description: String {
switch self {
case .didAppear:
return "didAppear"
case .didDisappear:
return "didDisappear"
case .willSheet(let screeID):
return "willSheet \(screeID)"
case .willFullscreen(let screeID):
return "willFullscreen \(screeID)"
case .willPush(let screeID):
return "willPush \(screeID)"
}
}
}

public init(id: ScreenID, staticID: ScreenStaticID, kind: Kind) {
self.screenStaticID = staticID
self.kind = kind
self.id = id
}

public var description: String {
"Screen \(screenStaticID.type)-\(id) \(kind)"
}
}
12 changes: 12 additions & 0 deletions Sources/BrowserMessages/ScreenID.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
//
// Created by Alexey Nenastyev on 18.8.24.
// Copyright © 2024 Alexey Nenastyev (github.com/alexejn). All Rights Reserved.


import Foundation

public typealias ScreenID = UInt32

public extension UUID {
static var zero = UUID(uuidString: "00000000-0000-0000-0000-000000000000")!
}
Loading

0 comments on commit ce19ceb

Please sign in to comment.