Skip to content

Commit

Permalink
Merge branch 'feature/example-app-improvements' into develop
Browse files Browse the repository at this point in the history
  • Loading branch information
SwiftedMind committed Jan 13, 2023
2 parents 33302c7 + 699f5bf commit b4fe666
Show file tree
Hide file tree
Showing 104 changed files with 3,238 additions and 706 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
9531A73C29681866009D7688 /* Preview Assets.xcassets */ = {isa = PBXFileReference; lastKnownFileType = folder.assetcatalog; path = "Preview Assets.xcassets"; sourceTree = "<group>"; };
9531A74329681889009D7688 /* Puddles */ = {isa = PBXFileReference; lastKnownFileType = wrapper; name = Puddles; path = ../..; sourceTree = "<group>"; };
958AF81C296AF6E9004F8E61 /* README.md */ = {isa = PBXFileReference; lastKnownFileType = net.daringfireball.markdown; path = README.md; sourceTree = "<group>"; };
958AF81D296DF035004F8E61 /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist; path = Info.plist; sourceTree = "<group>"; };
9594A765296819B700063CE7 /* Root.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Root.swift; sourceTree = "<group>"; };
9594A76729681A2300063CE7 /* Home.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Home.swift; sourceTree = "<group>"; };
9594A76B29681AA500063CE7 /* HomeView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = HomeView.swift; sourceTree = "<group>"; };
Expand Down Expand Up @@ -77,14 +78,14 @@
9531A73429681866009D7688 /* PuddlesExampleiOS */ = {
isa = PBXGroup;
children = (
958AF81D296DF035004F8E61 /* Info.plist */,
9531A73529681866009D7688 /* ExampleApp.swift */,
958AF81C296AF6E9004F8E61 /* README.md */,
9594A7802968BF1100063CE7 /* Helper */,
9594A7782968B3D100063CE7 /* Models */,
9594A7752968A2F200063CE7 /* Services */,
9594A764296819A900063CE7 /* Coordinators */,
9594A76A29681A8400063CE7 /* Share Components */,
9594A76929681A7E00063CE7 /* Views */,
9594A7802968BF1100063CE7 /* Helper */,
9531A73929681866009D7688 /* Assets.xcassets */,
9531A73B29681866009D7688 /* Preview Content */,
);
Expand Down Expand Up @@ -123,13 +124,6 @@
path = Views;
sourceTree = "<group>";
};
9594A76A29681A8400063CE7 /* Share Components */ = {
isa = PBXGroup;
children = (
);
path = "Share Components";
sourceTree = "<group>";
};
9594A7752968A2F200063CE7 /* Services */ = {
isa = PBXGroup;
children = (
Expand Down Expand Up @@ -377,6 +371,7 @@
DEVELOPMENT_TEAM = 7F6BJZY5B3;
ENABLE_PREVIEWS = YES;
GENERATE_INFOPLIST_FILE = YES;
INFOPLIST_FILE = PuddlesExampleiOS/Info.plist;
INFOPLIST_KEY_UIApplicationSceneManifest_Generation = YES;
INFOPLIST_KEY_UIApplicationSupportsIndirectInputEvents = YES;
INFOPLIST_KEY_UILaunchScreen_Generation = YES;
Expand Down Expand Up @@ -409,6 +404,7 @@
DEVELOPMENT_TEAM = 7F6BJZY5B3;
ENABLE_PREVIEWS = YES;
GENERATE_INFOPLIST_FILE = YES;
INFOPLIST_FILE = PuddlesExampleiOS/Info.plist;
INFOPLIST_KEY_UIApplicationSceneManifest_Generation = YES;
INFOPLIST_KEY_UIApplicationSupportsIndirectInputEvents = YES;
INFOPLIST_KEY_UILaunchScreen_Generation = YES;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,8 @@ struct Home: Coordinator {
let searchResults: HomeView.SearchResultsLoadingState
@State var searchQuery: String = ""

@State var showSheet: Bool = false

var entryView: some View {
HomeView(
interface: viewInterface,
Expand All @@ -45,22 +47,34 @@ struct Home: Coordinator {
.navigationTitle("Events")
}

func navigation() -> some NavigationPattern {
func handleDeeplink(url: URL) -> DeepLinkPropagation {
print("received »\(url)«")

viewInterface.sendAction(.searchQueryUpdated("ABCD Test"))
showSheet = true

return .hasFinished
}

func navigation() -> some NavigationPattern {
Sheet(isActive: $showSheet) {
Text("OK")
}
}

func interfaces() -> some InterfaceObservation {
AsyncInterfaceObserver(viewInterface) { action in
await handleViewAction(action)
InterfaceObserver(viewInterface) { action in
handleViewAction(action)
}
}

func handleViewAction(_ action: HomeView.Action) async {
func handleViewAction(_ action: HomeView.Action) {
switch action {
case .eventTapped:
print("Event Tapped")
case .searchQueryUpdated(query: let query):
searchQuery = query

// Pass through action to own interface.
// The instance responsible for providing searchResults needs to decide on debouncing/throttling etc.
interface.sendAction(.searchQueryUpdated(query))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,13 @@ struct Root: Coordinator {
}
}

// To test deep linking, enter the following into a console:
// xcrun simctl openurl booted "puddles://com.something"
func handleDeeplink(url: URL) -> DeepLinkPropagation {
print("received »\(url)«")
return .shouldContinue
}

func start() async {
do {
self.events = .loading
Expand All @@ -55,20 +62,22 @@ struct Root: Coordinator {
}

func interfaces() -> some InterfaceObservation {
AsyncInterfaceObserver(homeInterface) { action in
await handleHomeAction(action)
InterfaceObserver(homeInterface) { action in
handleHomeAction(action)
}
AsyncChannelObserver(helper.searchChannel) { channel in
for await query in channel.debounce(for: .seconds(0-5)) {
for await query in channel.debounce(for: .seconds(0.5)) {
searchEvents(query: query)
}
}
}

func handleHomeAction(_ action: Home.Action) async {
func handleHomeAction(_ action: Home.Action) {
switch action {
case .searchQueryUpdated(let query):
await helper.searchChannel.send(query)
Task {
await helper.searchChannel.send(query)
}
}
}

Expand Down
2 changes: 2 additions & 0 deletions Examples/PuddlesExampleiOS/PuddlesExampleiOS/ExampleApp.swift
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
//

import SwiftUI
import Puddles

@main
struct ExampleApp: App {
Expand All @@ -30,6 +31,7 @@ struct ExampleApp: App {
WindowGroup {
Root()
.environmentObject(services)
.deepLinkRoot()
}
}
}
19 changes: 19 additions & 0 deletions Examples/PuddlesExampleiOS/PuddlesExampleiOS/Info.plist
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
<?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>CFBundleURLTypes</key>
<array>
<dict>
<key>CFBundleTypeRole</key>
<string>Editor</string>
<key>CFBundleURLName</key>
<string>puddlesexample</string>
<key>CFBundleURLSchemes</key>
<array>
<string>puddles</string>
</array>
</dict>
</array>
</dict>
</plist>
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@

import SwiftUI
import Puddles
import Combine

struct HomeView: View {
@ObservedObject var interface: Interface<Action>
Expand Down Expand Up @@ -78,7 +77,6 @@ struct HomeView: View {
Button(event.name) {

}

}
.listStyle(.insetGrouped)
}
Expand Down Expand Up @@ -116,7 +114,7 @@ extension HomeView {
struct HomeView_Previews: PreviewProvider {
static var previews: some View {
NavigationView {
Preview(HomeView.init, state: .mock) { action, state in
Preview(HomeView.init, state: .mock) { action, $state in
switch action {
case .eventTapped:
state.events = .loaded(state.events.value! + [.random])
Expand Down
Loading

0 comments on commit b4fe666

Please sign in to comment.