Skip to content

Commit

Permalink
wip: bump composable-architecture to 1.5.5, use native navigation and…
Browse files Browse the repository at this point in the history
… toolbar

also fixes showing build number and lowercasing repo urls
  • Loading branch information
ErrorErrorError committed Dec 13, 2023
1 parent 5e6be91 commit 9618bf1
Show file tree
Hide file tree
Showing 37 changed files with 667 additions and 916 deletions.
4 changes: 2 additions & 2 deletions App/Mochi.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -371,7 +371,7 @@
ASSETCATALOG_COMPILER_GLOBAL_ACCENT_COLOR_NAME = AccentColor;
ASSETCATALOG_COMPILER_INCLUDE_ALL_APPICON_ASSETS = YES;
CODE_SIGN_ENTITLEMENTS = Shared/mochi.entitlements;
CURRENT_PROJECT_VERSION = 1;
CURRENT_PROJECT_VERSION = 3;
DEAD_CODE_STRIPPING = YES;
DEVELOPMENT_ASSET_PATHS = ..;
DEVELOPMENT_TEAM = A6HC4Y86NJ;
Expand Down Expand Up @@ -411,7 +411,7 @@
ASSETCATALOG_COMPILER_GLOBAL_ACCENT_COLOR_NAME = AccentColor;
ASSETCATALOG_COMPILER_INCLUDE_ALL_APPICON_ASSETS = YES;
CODE_SIGN_ENTITLEMENTS = Shared/mochi.entitlements;
CURRENT_PROJECT_VERSION = 1;
CURRENT_PROJECT_VERSION = 3;
DEAD_CODE_STRIPPING = YES;
DEVELOPMENT_ASSET_PATHS = ..;
DEVELOPMENT_TEAM = A6HC4Y86NJ;
Expand Down
9 changes: 9 additions & 0 deletions App/Mochi.xcodeproj/xcshareddata/xcschemes/Mochi.xcscheme
Original file line number Diff line number Diff line change
Expand Up @@ -73,5 +73,14 @@
<ArchiveAction
buildConfiguration = "Release"
revealArchiveInOrganizer = "YES">
<PostActions>
<ExecutionAction
ActionType = "Xcode.IDEStandardExecutionActionsCore.ExecutionActionType.ShellScriptAction">
<ActionContent
title = "Run Script"
scriptText = "# Type a script or drag a script file from your workspace to insert its path.&#10;cd &quot;${PROJECT_DIR}&quot;; avgtool bump&#10;">
</ActionContent>
</ExecutionAction>
</PostActions>
</ArchiveAction>
</Scheme>
2 changes: 1 addition & 1 deletion App/Shared/MochiApp.swift
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ struct MochiApp: App {
SettingsFeature.View(
store: appDelegate.store.scope(
state: \.settings,
action: { .internal(.settings($0)) }
action: \.internal.settings
)
)
.themeable()
Expand Down
3 changes: 2 additions & 1 deletion Package.swift
Original file line number Diff line number Diff line change
Expand Up @@ -920,7 +920,7 @@ extension _Client {

struct ComposableArchitecture: PackageDependency {
var dependency: Package.Dependency {
.package(url: "https://github.com/pointfreeco/swift-composable-architecture", exact: "1.4.2")
.package(url: "https://github.com/pointfreeco/swift-composable-architecture", exact: "1.5.5")
}
}
//
Expand Down Expand Up @@ -1361,6 +1361,7 @@ struct Architecture: _Shared {
FoundationHelpers()
ComposableArchitecture()
LocalizableClient()
LoggerClient()
}
}
//
Expand Down
2 changes: 1 addition & 1 deletion Package/Sources/Dependencies/ComposableArchitecture.swift
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,6 @@

struct ComposableArchitecture: PackageDependency {
var dependency: Package.Dependency {
.package(url: "https://github.com/pointfreeco/swift-composable-architecture", exact: "1.4.2")
.package(url: "https://github.com/pointfreeco/swift-composable-architecture", exact: "1.5.5")
}
}
1 change: 1 addition & 0 deletions Package/Sources/Shared/Architecture.swift
Original file line number Diff line number Diff line change
Expand Up @@ -11,5 +11,6 @@ struct Architecture: _Shared {
FoundationHelpers()
ComposableArchitecture()
LocalizableClient()
LoggerClient()
}
}
3 changes: 2 additions & 1 deletion Sources/Clients/BuildClient/Client.swift
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,8 @@ public struct BuildKey: DependencyKey {
.flatMap { $0 as? String }
.flatMap { try? Semver($0) } ?? .init(0, 0, 0),
number: Bundle.main.object(forInfoDictionaryKey: "CFBundleVersion")
.flatMap { $0 as? Int }
.flatMap { $0 as? String }
.flatMap { Int($0) }
.flatMap { .init(rawValue: $0) } ?? .init(0)
)
}
Expand Down
4 changes: 4 additions & 0 deletions Sources/Clients/LocalizableClient/Client.swift
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,10 @@ extension LocalizableClient: DependencyKey {
public static let liveValue: LocalizableClient = .init(
localize: { String(localized: .init($0), bundle: .module) }
)

public static let previewValue: LocalizableClient = .init(localize: { $0 })

public static let testValue: LocalizableClient = .init(localize: unimplemented(".localize"))
}

extension DependencyValues {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ extension JSContext {

let jsURL = try fileClient.retrieveModuleDirectory(module.mainJSFile)
try evaluateScript(String(contentsOf: jsURL))
evaluateScript("const Instance = new source.default()")
evaluateScript("const Instance = new source.default();")
}
}

Expand Down
6 changes: 3 additions & 3 deletions Sources/Clients/RepoClient/Live.swift
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import DatabaseClient
import Dependencies
import FileClient
import Foundation
import LoggerClient
import Semaphore
import SharedModels

Expand Down Expand Up @@ -145,8 +146,7 @@ private class ModulesDownloadManager {
}

guard response.mimeType == "text/javascript" || response.mimeType == "application/javascript" else {
print("Unknown mime type of file \(response.mimeType ?? "Unknown")")
throw RepoClient.Error.failedToDownloadModule
throw RepoClient.Error.invalidMimeTypeForModule(received: response.mimeType ?? "Unknown")
}

guard let directory = URL(
Expand All @@ -169,7 +169,7 @@ private class ModulesDownloadManager {
}
}
} catch {
print(error)
logger.error("\(error.localizedDescription)")
states.value[repoModuleId] = .failed((error as? RepoClient.Error) ?? .failedToDownloadModule)
}
return nil
Expand Down
1 change: 1 addition & 0 deletions Sources/Clients/RepoClient/Models.swift
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ public extension RepoClient {
enum Error: Swift.Error, Equatable, Sendable {
case failedToFindRepo
case failedToDownloadModule
case invalidMimeTypeForModule(received: String)
case failedToDownloadRepo
case failedToAddRepo
case failedToInstallModule
Expand Down
6 changes: 3 additions & 3 deletions Sources/Clients/UserSettingsClient/Theme.swift
Original file line number Diff line number Diff line change
Expand Up @@ -66,9 +66,9 @@ public enum Theme: Codable, Sendable, Hashable, Identifiable, CaseIterable {
)
#else
.init(
red: 0x0A / 0xFF,
green: 0x0A / 0xFF,
blue: 0x0A / 0xFF
red: 0x10 / 0xFF,
green: 0x10 / 0xFF,
blue: 0x10 / 0xFF
)
#endif
}
Expand Down
2 changes: 1 addition & 1 deletion Sources/Features/App/AppFeature.swift
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ public struct AppFeature: Feature {
self.selected = selected
}

public enum Tab: String, CaseIterable, Sendable, Localizable {
public enum Tab: String, CaseIterable, Sendable, Localizable, Hashable {
case discover = "Discover"
case repos = "Repos"
case settings = "Settings"
Expand Down
132 changes: 44 additions & 88 deletions Sources/Features/App/iOS/AppFeatureView+iOS.swift
Original file line number Diff line number Diff line change
Expand Up @@ -24,45 +24,57 @@ extension AppFeature.View: View {
@MainActor
public var body: some View {
WithViewStore(store, observe: \.selected) { viewStore in
ZStack {
switch viewStore.state {
case .discover:
DiscoverFeature.View(
store: store.scope(
state: \.discover,
action: Action.InternalAction.discover
)
)
case .repos:
ReposFeature.View(
store: store.scope(
state: \.repos,
action: Action.InternalAction.repos
)
)
case .settings:
SettingsFeature.View(
store: store.scope(
state: \.settings,
action: Action.InternalAction.settings
)
)
TabView(
selection: viewStore.binding(
get: \.`self`,
send: { .didSelectTab($0) }
)
) {
ForEach(Self.State.Tab.allCases, id: \.self) { (tab: Self.State.Tab) in
Group {
switch tab {
case .discover:
DiscoverFeature.View(
store: store.scope(
state: \.discover,
action: \.internal.discover
)
)
.tint(nil)
case .repos:
ReposFeature.View(
store: store.scope(
state: \.repos,
action: \.internal.repos
)
)
.tint(nil)
case .settings:
SettingsFeature.View(
store: store.scope(
state: \.settings,
action: \.internal.settings
)
)
.tint(nil)
}
}
.tabItem {
Label(tab.localized, systemImage: viewStore.state == tab ? tab.selected : tab.image)
}
.tag(tab)
}
}
.inset(for: \.bottomNavigation, alignment: .bottom) {
navbar(viewStore.state)
}
.ignoresSafeArea(.keyboard, edges: .all)
}
.onAppear {
store.send(.view(.didAppear))
// Set tint of tab item
.tint(viewStore.state.colorAccent)
}
.onAppear { store.send(.view(.didAppear)) }
.overlay {
WithViewStore(store, observe: \.videoPlayer != nil) { isVisible in
IfLetStore(
store.scope(
state: \.$videoPlayer,
action: { .internal(.videoPlayer($0)) }
action: \.internal.videoPlayer
),
then: { VideoPlayerFeature.View(store: $0) }
)
Expand All @@ -73,68 +85,12 @@ extension AppFeature.View: View {
}
.themeable()
}

@MainActor
func navbar(_ selected: Self.State.Tab) -> some View {
HStack(alignment: .top, spacing: 0) {
ForEach(State.Tab.allCases, id: \.rawValue) { tab in
Button {
store.send(.view(.didSelectTab(tab)))
} label: {
VStack(spacing: 2) {
RoundedRectangle(cornerRadius: 12)
.frame(width: tab == selected ? 18 : 0, height: 4)
.transition(.scale.combined(with: .opacity))
.opacity(tab == selected ? 1.0 : 0.0)

Image(systemName: tab == selected ? tab.selected : tab.image)
.resizable()
.aspectRatio(contentMode: .fit)
.font(.system(size: 20, weight: .semibold))
.frame(height: 18)
.padding(.top, 8)

Text(tab.localized)
.font(.system(size: 10, weight: .medium))
}
.foregroundColor(tab == selected ? tab.colorAccent : .gray)
.frame(maxWidth: .infinity)
.background(
Rectangle()
.foregroundColor(tab.colorAccent.opacity(tab == selected ? 0.08 : 0.0))
.ignoresSafeArea(.all)
.edgesIgnoringSafeArea(.all)
.blur(radius: 24)
)
.contentShape(Rectangle())
}
.buttonStyle(.scaled)
.contentShape(Rectangle())
.animation(.easeInOut(duration: 0.2), value: tab == selected)
}
.frame(maxWidth: .infinity)
}
.frame(maxWidth: .infinity, alignment: .bottom)
.background {
Rectangle()
.fill(.regularMaterial)
.ignoresSafeArea()
.edgesIgnoringSafeArea(.all)
}
.overlay(alignment: .top) {
Color.gray.opacity(0.2)
.frame(height: 0.5)
.frame(maxWidth: .infinity)
.ignoresSafeArea()
.edgesIgnoringSafeArea(.all)
}
}
}

#Preview {
AppFeature.View(
store: .init(
initialState: .init(),
initialState: .init(selected: .settings),
reducer: { AppFeature() }
)
)
Expand Down
6 changes: 3 additions & 3 deletions Sources/Features/App/macOS/AppFeatureView+macOS.swift
Original file line number Diff line number Diff line change
Expand Up @@ -36,14 +36,14 @@ extension AppFeature.View: View {
DiscoverFeature.View(
store: store.scope(
state: \.discover,
action: Action.InternalAction.discover
action: \.internal.discover
)
)
case .repos:
ReposFeature.View(
store: store.scope(
state: \.repos,
action: Action.InternalAction.repos
action: \.internal.repos
)
)
case .settings:
Expand All @@ -65,7 +65,7 @@ extension AppFeature.View: View {
.window(
store: store.scope(
state: \.$videoPlayer,
action: Action.InternalAction.videoPlayer
action: \.internal.videoPlayer
),
content: VideoPlayerFeature.View.init
)
Expand Down
5 changes: 1 addition & 4 deletions Sources/Features/Discover/DiscoverFeature+Reducer.swift
Original file line number Diff line number Diff line change
Expand Up @@ -40,10 +40,7 @@ extension DiscoverFeature {
state.path.append(.playlistDetails(.init(content: .init(repoModuleId: id, playlist: playlist))))

case .view(.didTapSearchButton):
state.search = SearchFeature.State(
searchFieldFocused: true,
repoModuleId: state.section.module?.module.id
)
state.search = SearchFeature.State(repoModuleId: state.section.module?.module.id)

case let .internal(.selectedModule(selection)):
if let selection {
Expand Down
Loading

0 comments on commit 9618bf1

Please sign in to comment.