Skip to content

Commit

Permalink
feat(Example): Basic TweetReply implementation
Browse files Browse the repository at this point in the history
  • Loading branch information
maximkrouk committed Dec 31, 2023
1 parent c08cc89 commit 178e9d9
Show file tree
Hide file tree
Showing 14 changed files with 401 additions and 60 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
<?xml version="1.0" encoding="UTF-8"?>
<Scheme
LastUpgradeVersion = "1500"
version = "1.7">
<BuildAction
parallelizeBuildables = "YES"
buildImplicitDependencies = "YES">
<BuildActionEntries>
<BuildActionEntry
buildForTesting = "YES"
buildForRunning = "YES"
buildForProfiling = "YES"
buildForArchiving = "YES"
buildForAnalyzing = "YES">
<BuildableReference
BuildableIdentifier = "primary"
BlueprintIdentifier = "LocalExtensions"
BuildableName = "LocalExtensions"
BlueprintName = "LocalExtensions"
ReferencedContainer = "container:">
</BuildableReference>
</BuildActionEntry>
</BuildActionEntries>
</BuildAction>
<TestAction
buildConfiguration = "Debug"
selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB"
selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB"
shouldUseLaunchSchemeArgsEnv = "YES"
shouldAutocreateTestPlan = "YES">
</TestAction>
<LaunchAction
buildConfiguration = "Debug"
selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB"
selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB"
launchStyle = "0"
useCustomWorkingDirectory = "NO"
ignoresPersistentStateOnLaunch = "NO"
debugDocumentVersioning = "YES"
debugServiceExtension = "internal"
allowLocationSimulation = "YES">
</LaunchAction>
<ProfileAction
buildConfiguration = "Release"
shouldUseLaunchSchemeArgsEnv = "YES"
savedToolIdentifier = ""
useCustomWorkingDirectory = "NO"
debugDocumentVersioning = "YES">
<MacroExpansion>
<BuildableReference
BuildableIdentifier = "primary"
BlueprintIdentifier = "LocalExtensions"
BuildableName = "LocalExtensions"
BlueprintName = "LocalExtensions"
ReferencedContainer = "container:">
</BuildableReference>
</MacroExpansion>
</ProfileAction>
<AnalyzeAction
buildConfiguration = "Debug">
</AnalyzeAction>
<ArchiveAction
buildConfiguration = "Release"
revealArchiveInOrganizer = "YES">
</ArchiveAction>
</Scheme>
20 changes: 20 additions & 0 deletions Example/Package.swift
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,10 @@ let package = Package(
url: "https://github.com/capturecontext/composable-architecture-extensions.git",
branch: "observation-beta"
),
.package(
url: "https://github.com/capturecontext/combine-extensions.git",
.upToNextMinor(from: "0.1.0")
),
.package(
url: "https://github.com/pointfreeco/swift-dependencies.git",
.upToNextMajor(from: "1.0.0")
Expand All @@ -37,6 +41,10 @@ let package = Package(
name: "LocalExtensions",
product: .library(.static),
dependencies: [
.product(
name: "CombineExtensions",
package: "combine-extensions"
),
.product(
name: "FoundationExtensions",
package: "swift-foundation-extensions"
Expand Down Expand Up @@ -140,6 +148,16 @@ let package = Package(
]
),

.target(
name: "TweetReplyFeature",
product: .library(.static),
dependencies: [
.target("TweetFeature"),
.dependency("_ComposableArchitecture"),
.localExtensions,
]
),

.target(
name: "CurrentUserProfileFeature",
product: .library(.static),
Expand All @@ -156,6 +174,7 @@ let package = Package(
name: "DatabaseSchema",
product: .library(.static),
dependencies: [
.dependency("_Dependencies"),
.localExtensions
]
),
Expand Down Expand Up @@ -243,6 +262,7 @@ let package = Package(
.target("APIClient"),
.target("TweetFeature"),
.target("TweetsListFeature"),
.target("TweetReplyFeature"),
.dependency("_ComposableArchitecture"),
.localExtensions,
]
Expand Down
4 changes: 1 addition & 3 deletions Example/Sources/AppFeature/Bootstrap/SceneDelegate.swift
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,7 @@ public class SceneDelegate: UIResponder, UIWindowSceneDelegate {
let window = UIWindow(windowScene: scene)
self.window = window

window.rootViewController = UINavigationController(
rootViewController: controller
)
window.rootViewController = controller

window.makeKeyAndVisible()

Expand Down
2 changes: 2 additions & 0 deletions Example/Sources/AppUI/Colors/ColorTheme.swift
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,9 @@ public struct ColorTheme {
}

extension ColorTheme {
#warning("Find a way to update current value for SUI and Cocoa")
public static var current: ColorTheme {
// Won't be updated in Cocoa
Environment(\.colorTheme).wrappedValue
}

Expand Down
8 changes: 4 additions & 4 deletions Example/Sources/FeedTabFeature/FeedTabController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,11 @@ import TweetsFeedFeature
public final class FeedTabController: ComposableViewControllerOf<FeedTabFeature> {
let contentController: TweetsFeedController = .init()

@ComposableStackDestination
var feedControllers: [StackElementID: TweetsFeedController]
@ComposableStackDestination<TweetsFeedController>
var feedControllers

@ComposableStackDestination({ _ in .init(rootView: nil) })
var profileControllers: [StackElementID: ComposableHostingController<UserProfileView>]
@ComposableViewStackDestination<UserProfileView>
var profileControllers

public override func viewDidLoad() {
super.viewDidLoad()
Expand Down
43 changes: 25 additions & 18 deletions Example/Sources/MainFeature/MainViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -13,26 +13,33 @@ public final class MainViewController: ComposableTabBarControllerOf<MainFeature>
public override func _init() {
super._init()

let feedNavigation = UINavigationController(
rootViewController: feedTabController.configured { $0
.title("Example")
.set { $0.tabBarItem = .init(
title: "Feed",
image: UIImage(systemName: "house"),
selectedImage: UIImage(systemName: "house.fill")
) }
}
)

let profileNavigation = UINavigationController(
rootViewController: profileTabController.configured { $0
.set { $0.tabBarItem = .init(
title: "Profile",
image: UIImage(systemName: "person"),
selectedImage: UIImage(systemName: "person.fill")
) }
}
)

feedNavigation.navigationBar.prefersLargeTitles = true

setViewControllers(
[
UINavigationController(
rootViewController: feedTabController.configured { $0
.set { $0.tabBarItem = .init(
title: "Feed",
image: UIImage(systemName: "house"),
selectedImage: UIImage(systemName: "house.fill")
) }
}
),
UINavigationController(
rootViewController: profileTabController.configured { $0
.set { $0.tabBarItem = .init(
title: "Profile",
image: UIImage(systemName: "person"),
selectedImage: UIImage(systemName: "person.fill")
) }
}
)
feedNavigation,
profileNavigation
],
animated: false
)
Expand Down
17 changes: 0 additions & 17 deletions Example/Sources/ProfileFeedFeature/ProfileFeedView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -24,20 +24,3 @@ public struct ProfileFeedView: ComposableView {
}
}
}

#Preview {
NavigationStack {
ProfileFeedView(Store(
initialState: .init(
tweets: [
.mock(),
.mock(),
.mock(),
.mock(),
.mock()
]
),
reducer: ProfileFeedFeature.init
))
}
}
29 changes: 23 additions & 6 deletions Example/Sources/TweetDetailFeature/TweetDetailController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,18 @@ import Combine
import CombineExtensions
import Capture
import CombineNavigation
import TweetReplyFeature

@RoutingController
public final class TweetDetailController: ComposableViewControllerOf<TweetDetailFeature> {
let host = ComposableHostingController<TweetDetailView>(rootView: nil)
let host = ComposableHostingController<TweetDetailView>()

@ComposableTreeDestination
var detailController: TweetDetailController?

@ComposableViewTreeDestination<TweetReplyView>
var tweetReplyController

public override func viewDidLoad() {
super.viewDidLoad()
self.addChild(host)
Expand All @@ -30,9 +34,15 @@ public final class TweetDetailController: ComposableViewControllerOf<TweetDetail
public override func scope(_ store: Store?) {
host.setStore(store)

#warning("Use present")
_tweetReplyController.setStore(store?.scope(
state: \.destination?.tweetReply,
action: \.destination.presented.tweetReply
))

_detailController.setStore(store?.scope(
state: \.detail,
action: \.detail.presented
state: \.destination?.detail,
action: \.destination.presented.detail
))
}

Expand All @@ -41,9 +51,16 @@ public final class TweetDetailController: ComposableViewControllerOf<TweetDetail
into cancellables: inout Set<AnyCancellable>
) {
navigationDestination(
isPresented: \.detail.isNotNil,
destination: $detailController,
popAction: .detail(.dismiss)
state: \State.$destination,
switch: { destinations, route in
switch route {
case .tweetReply:
destinations.$tweetReplyController
case .detail:
destinations.$detailController
}
},
popAction: .destination(.dismiss)
)
.store(in: &cancellables)
}
Expand Down
Loading

0 comments on commit 178e9d9

Please sign in to comment.