Skip to content

Commit a4fb97e

Browse files
chore: Integrate demos (#217)
1 parent 47b9a34 commit a4fb97e

File tree

538 files changed

+29488
-524
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

538 files changed

+29488
-524
lines changed
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
//
2+
// AppDelegate.swift
3+
// CategoriesHits
4+
//
5+
// Created by Vladislav Fitc on 19/11/2021.
6+
//
7+
8+
import UIKit
9+
10+
@main
11+
class AppDelegate: UIResponder, UIApplicationDelegate {
12+
13+
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {
14+
// Override point for customization after application launch.
15+
return true
16+
}
17+
18+
// MARK: UISceneSession Lifecycle
19+
20+
func application(_ application: UIApplication, configurationForConnecting connectingSceneSession: UISceneSession, options: UIScene.ConnectionOptions) -> UISceneConfiguration {
21+
// Called when a new scene session is being created.
22+
// Use this method to select a configuration to create the new scene with.
23+
return UISceneConfiguration(name: "Default Configuration", sessionRole: connectingSceneSession.role)
24+
}
25+
26+
func application(_ application: UIApplication, didDiscardSceneSessions sceneSessions: Set<UISceneSession>) {
27+
// Called when the user discards a scene session.
28+
// If any sessions were discarded while the application was not running, this will be called shortly after application:didFinishLaunchingWithOptions.
29+
// Use this method to release any resources that were specific to the discarded scenes, as they will not return.
30+
}
31+
32+
33+
}
34+
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
{
2+
"colors" : [
3+
{
4+
"idiom" : "universal"
5+
}
6+
],
7+
"info" : {
8+
"author" : "xcode",
9+
"version" : 1
10+
}
11+
}
Lines changed: 98 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,98 @@
1+
{
2+
"images" : [
3+
{
4+
"idiom" : "iphone",
5+
"scale" : "2x",
6+
"size" : "20x20"
7+
},
8+
{
9+
"idiom" : "iphone",
10+
"scale" : "3x",
11+
"size" : "20x20"
12+
},
13+
{
14+
"idiom" : "iphone",
15+
"scale" : "2x",
16+
"size" : "29x29"
17+
},
18+
{
19+
"idiom" : "iphone",
20+
"scale" : "3x",
21+
"size" : "29x29"
22+
},
23+
{
24+
"idiom" : "iphone",
25+
"scale" : "2x",
26+
"size" : "40x40"
27+
},
28+
{
29+
"idiom" : "iphone",
30+
"scale" : "3x",
31+
"size" : "40x40"
32+
},
33+
{
34+
"idiom" : "iphone",
35+
"scale" : "2x",
36+
"size" : "60x60"
37+
},
38+
{
39+
"idiom" : "iphone",
40+
"scale" : "3x",
41+
"size" : "60x60"
42+
},
43+
{
44+
"idiom" : "ipad",
45+
"scale" : "1x",
46+
"size" : "20x20"
47+
},
48+
{
49+
"idiom" : "ipad",
50+
"scale" : "2x",
51+
"size" : "20x20"
52+
},
53+
{
54+
"idiom" : "ipad",
55+
"scale" : "1x",
56+
"size" : "29x29"
57+
},
58+
{
59+
"idiom" : "ipad",
60+
"scale" : "2x",
61+
"size" : "29x29"
62+
},
63+
{
64+
"idiom" : "ipad",
65+
"scale" : "1x",
66+
"size" : "40x40"
67+
},
68+
{
69+
"idiom" : "ipad",
70+
"scale" : "2x",
71+
"size" : "40x40"
72+
},
73+
{
74+
"idiom" : "ipad",
75+
"scale" : "1x",
76+
"size" : "76x76"
77+
},
78+
{
79+
"idiom" : "ipad",
80+
"scale" : "2x",
81+
"size" : "76x76"
82+
},
83+
{
84+
"idiom" : "ipad",
85+
"scale" : "2x",
86+
"size" : "83.5x83.5"
87+
},
88+
{
89+
"idiom" : "ios-marketing",
90+
"scale" : "1x",
91+
"size" : "1024x1024"
92+
}
93+
],
94+
"info" : {
95+
"author" : "xcode",
96+
"version" : 1
97+
}
98+
}
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
{
2+
"info" : {
3+
"author" : "xcode",
4+
"version" : 1
5+
}
6+
}
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
2+
<document type="com.apple.InterfaceBuilder3.CocoaTouch.Storyboard.XIB" version="3.0" toolsVersion="13122.16" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" launchScreen="YES" useTraitCollections="YES" useSafeAreas="YES" colorMatched="YES" initialViewController="01J-lp-oVM">
3+
<dependencies>
4+
<plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="13104.12"/>
5+
<capability name="Safe area layout guides" minToolsVersion="9.0"/>
6+
<capability name="documents saved in the Xcode 8 format" minToolsVersion="8.0"/>
7+
</dependencies>
8+
<scenes>
9+
<!--View Controller-->
10+
<scene sceneID="EHf-IW-A2E">
11+
<objects>
12+
<viewController id="01J-lp-oVM" sceneMemberID="viewController">
13+
<view key="view" contentMode="scaleToFill" id="Ze5-6b-2t3">
14+
<rect key="frame" x="0.0" y="0.0" width="375" height="667"/>
15+
<autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/>
16+
<color key="backgroundColor" xcode11CocoaTouchSystemColor="systemBackgroundColor" cocoaTouchSystemColor="whiteColor"/>
17+
<viewLayoutGuide key="safeArea" id="6Tk-OE-BBY"/>
18+
</view>
19+
</viewController>
20+
<placeholder placeholderIdentifier="IBFirstResponder" id="iYj-Kq-Ea1" userLabel="First Responder" sceneMemberID="firstResponder"/>
21+
</objects>
22+
<point key="canvasLocation" x="53" y="375"/>
23+
</scene>
24+
</scenes>
25+
</document>
Lines changed: 152 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,152 @@
1+
//
2+
// SearchResultsController.swift
3+
// CategoriesHits
4+
//
5+
// Created by Vladislav Fitc on 19/11/2021.
6+
//
7+
8+
import Foundation
9+
import InstantSearch
10+
import UIKit
11+
12+
extension CategoriesHits {
13+
14+
class SearchResultsController: UITableViewController {
15+
16+
var didSelectSuggestion: ((String) -> Void)?
17+
18+
enum Section: Int, CaseIterable {
19+
case categories
20+
case hits
21+
22+
var title: String {
23+
switch self {
24+
case .categories:
25+
return "Categories"
26+
case .hits:
27+
return "Products"
28+
}
29+
}
30+
31+
var cellReuseIdentifier: String {
32+
switch self {
33+
case .categories:
34+
return "categories"
35+
case .hits:
36+
return "hits"
37+
}
38+
}
39+
40+
init?(section: Int) {
41+
self.init(rawValue: section)
42+
}
43+
44+
init?(indexPath: IndexPath) {
45+
self.init(section: indexPath.section)
46+
}
47+
48+
}
49+
50+
weak var categoriesInteractor: FacetListInteractor? {
51+
didSet {
52+
oldValue?.onResultsUpdated.cancelSubscription(for: tableView)
53+
guard let interactor = categoriesInteractor else { return }
54+
interactor.onResultsUpdated.subscribe(with: tableView) { tableView, _ in
55+
tableView.reloadData()
56+
}.onQueue(.main)
57+
}
58+
}
59+
60+
weak var hitsInteractor: HitsInteractor<Hit<Product>>? {
61+
didSet {
62+
oldValue?.onResultsUpdated.cancelSubscription(for: tableView)
63+
guard let interactor = hitsInteractor else { return }
64+
interactor.onResultsUpdated.subscribe(with: tableView) { tableView, _ in
65+
tableView.reloadData()
66+
}.onQueue(.main)
67+
}
68+
}
69+
70+
override func viewDidLoad() {
71+
super.viewDidLoad()
72+
tableView.register(CategoryTableViewCell.self, forCellReuseIdentifier: Section.categories.cellReuseIdentifier)
73+
tableView.register(ProductTableViewCell.self, forCellReuseIdentifier: Section.hits.cellReuseIdentifier)
74+
}
75+
76+
override func numberOfSections(in tableView: UITableView) -> Int {
77+
return Section.allCases.count
78+
}
79+
80+
override func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
81+
guard let section = Section(rawValue: section) else { return 0 }
82+
switch section {
83+
case .categories:
84+
return categoriesInteractor?.items.count ?? 0
85+
case .hits:
86+
return hitsInteractor?.numberOfHits() ?? 0
87+
}
88+
}
89+
90+
override func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
91+
guard let section = Section(rawValue: indexPath.section) else { return UITableViewCell() }
92+
93+
let cell: UITableViewCell
94+
95+
switch section {
96+
case .categories:
97+
cell = tableView.dequeueReusableCell(withIdentifier: Section.categories.cellReuseIdentifier, for: indexPath)
98+
if
99+
let categoryCell = cell as? CategoryTableViewCell,
100+
let category = categoriesInteractor?.items[indexPath.row] {
101+
categoryCell.setup(with: category)
102+
}
103+
case .hits:
104+
cell = tableView.dequeueReusableCell(withIdentifier: Section.hits.cellReuseIdentifier, for: indexPath)
105+
if
106+
let productTableViewCell = cell as? ProductTableViewCell,
107+
let hit = hitsInteractor?.hit(atIndex: indexPath.row) {
108+
productTableViewCell.setup(with: hit)
109+
}
110+
}
111+
112+
return cell
113+
}
114+
115+
override func tableView(_ tableView: UITableView, titleForHeaderInSection section: Int) -> String? {
116+
guard let section = Section(rawValue: section) else { return nil }
117+
switch section {
118+
case .categories where categoriesInteractor?.items.count ?? 0 == 0:
119+
return nil
120+
case .hits where hitsInteractor?.numberOfHits() ?? 0 == 0:
121+
return nil
122+
default:
123+
return section.title
124+
}
125+
}
126+
127+
override func tableView(_ tableView: UITableView, heightForRowAt indexPath: IndexPath) -> CGFloat {
128+
guard let section = Section(indexPath: indexPath) else { return 0 }
129+
switch section {
130+
case .categories:
131+
return 44
132+
case .hits:
133+
return 100
134+
}
135+
}
136+
137+
override func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
138+
guard let section = Section(rawValue: indexPath.section) else { return }
139+
switch section {
140+
case .hits:
141+
// Handle hit selection
142+
break
143+
144+
case .categories:
145+
// Handle category selection
146+
break
147+
}
148+
}
149+
150+
}
151+
152+
}

0 commit comments

Comments
 (0)