Skip to content

Commit 693732b

Browse files
committed
representable, hosting vc
1 parent c018201 commit 693732b

File tree

10 files changed

+247
-49
lines changed

10 files changed

+247
-49
lines changed

Example/SwiftBloc.xcodeproj/project.pbxproj

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,11 @@
1111
047A7BB925ED733700228011 /* BlocContentView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 047A7BB825ED733700228011 /* BlocContentView.swift */; };
1212
047A7BBB25ED735800228011 /* MainView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 047A7BBA25ED735800228011 /* MainView.swift */; };
1313
047EC4D025EAEE860004C90C /* CounterCubit.swift in Sources */ = {isa = PBXBuildFile; fileRef = 047EC4CF25EAEE860004C90C /* CounterCubit.swift */; };
14+
04875B252631C9A10061239D /* Web.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = 04875B242631C9A10061239D /* Web.storyboard */; };
15+
04875B292631C9D70061239D /* WebViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 04875B282631C9D70061239D /* WebViewController.swift */; };
16+
04875B2D2631CB2B0061239D /* WebView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 04875B2C2631CB2B0061239D /* WebView.swift */; };
17+
04875B312631D2800061239D /* SuccessView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 04875B302631D2800061239D /* SuccessView.swift */; };
18+
04875B352631D2DA0061239D /* SuccessViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 04875B342631D2DA0061239D /* SuccessViewController.swift */; };
1419
04B45D1926164D1F0050F1D6 /* Pods_SwiftBloc_Example.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 0D9208F1CC2C0172BFA8D1E4 /* Pods_SwiftBloc_Example.framework */; };
1520
04B45D3026164E710050F1D6 /* Tests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 607FACEB1AFB9204008FA782 /* Tests.swift */; };
1621
04EB15FB25EAC7E8008E0030 /* SceneDelegate.swift in Sources */ = {isa = PBXBuildFile; fileRef = 04EB15FA25EAC7E8008E0030 /* SceneDelegate.swift */; };
@@ -38,6 +43,11 @@
3843
047A7BB825ED733700228011 /* BlocContentView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = BlocContentView.swift; sourceTree = "<group>"; };
3944
047A7BBA25ED735800228011 /* MainView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = MainView.swift; sourceTree = "<group>"; };
4045
047EC4CF25EAEE860004C90C /* CounterCubit.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = CounterCubit.swift; sourceTree = "<group>"; };
46+
04875B242631C9A10061239D /* Web.storyboard */ = {isa = PBXFileReference; lastKnownFileType = file.storyboard; path = Web.storyboard; sourceTree = "<group>"; };
47+
04875B282631C9D70061239D /* WebViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = WebViewController.swift; sourceTree = "<group>"; };
48+
04875B2C2631CB2B0061239D /* WebView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = WebView.swift; sourceTree = "<group>"; };
49+
04875B302631D2800061239D /* SuccessView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SuccessView.swift; sourceTree = "<group>"; };
50+
04875B342631D2DA0061239D /* SuccessViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SuccessViewController.swift; sourceTree = "<group>"; };
4151
04B45D0D26164BD50050F1D6 /* SwiftBloc_Example.entitlements */ = {isa = PBXFileReference; lastKnownFileType = text.plist.entitlements; path = SwiftBloc_Example.entitlements; sourceTree = "<group>"; };
4252
04EB15FA25EAC7E8008E0030 /* SceneDelegate.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = SceneDelegate.swift; sourceTree = "<group>"; };
4353
0D9208F1CC2C0172BFA8D1E4 /* Pods_SwiftBloc_Example.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; includeInIndex = 0; path = Pods_SwiftBloc_Example.framework; sourceTree = BUILT_PRODUCTS_DIR; };
@@ -100,6 +110,18 @@
100110
name = Bloc;
101111
sourceTree = "<group>";
102112
};
113+
04875B232631C9900061239D /* Web */ = {
114+
isa = PBXGroup;
115+
children = (
116+
04875B242631C9A10061239D /* Web.storyboard */,
117+
04875B282631C9D70061239D /* WebViewController.swift */,
118+
04875B2C2631CB2B0061239D /* WebView.swift */,
119+
04875B302631D2800061239D /* SuccessView.swift */,
120+
04875B342631D2DA0061239D /* SuccessViewController.swift */,
121+
);
122+
name = Web;
123+
sourceTree = "<group>";
124+
};
103125
607FACC71AFB9204008FA782 = {
104126
isa = PBXGroup;
105127
children = (
@@ -126,6 +148,7 @@
126148
607FACD21AFB9204008FA782 /* Example for SwiftBloc */ = {
127149
isa = PBXGroup;
128150
children = (
151+
04875B232631C9900061239D /* Web */,
129152
047A7BBD25ED7B6400228011 /* Bloc */,
130153
047A7BBC25ED7B5700228011 /* Cubit */,
131154
607FACD51AFB9204008FA782 /* AppDelegate.swift */,
@@ -290,6 +313,7 @@
290313
files = (
291314
607FACE01AFB9204008FA782 /* LaunchScreen.xib in Resources */,
292315
607FACDD1AFB9204008FA782 /* Images.xcassets in Resources */,
316+
04875B252631C9A10061239D /* Web.storyboard in Resources */,
293317
);
294318
runOnlyForDeploymentPostprocessing = 0;
295319
};
@@ -391,11 +415,15 @@
391415
files = (
392416
043EE4E125EC1C9500FAE1E8 /* CounterBloc.swift in Sources */,
393417
047A7BBB25ED735800228011 /* MainView.swift in Sources */,
418+
04875B312631D2800061239D /* SuccessView.swift in Sources */,
419+
04875B352631D2DA0061239D /* SuccessViewController.swift in Sources */,
394420
047EC4D025EAEE860004C90C /* CounterCubit.swift in Sources */,
395421
047A7BB925ED733700228011 /* BlocContentView.swift in Sources */,
396422
607FACD81AFB9204008FA782 /* CubitContentView.swift in Sources */,
397423
607FACD61AFB9204008FA782 /* AppDelegate.swift in Sources */,
424+
04875B2D2631CB2B0061239D /* WebView.swift in Sources */,
398425
04EB15FB25EAC7E8008E0030 /* SceneDelegate.swift in Sources */,
426+
04875B292631C9D70061239D /* WebViewController.swift in Sources */,
399427
);
400428
runOnlyForDeploymentPostprocessing = 0;
401429
};

Example/SwiftBloc/BlocContentView.swift

Lines changed: 24 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -13,30 +13,33 @@ struct BlocContentView: View {
1313
@State var isAlertCalled = false
1414

1515
var body: some View {
16-
BlocView(builder: { (bloc) in
17-
VStack {
18-
if bloc.state.count > 5 {
19-
LimitView()
20-
} else {
21-
OperationView()
16+
NavigationView {
17+
BlocView(builder: { (bloc) in
18+
VStack {
19+
if bloc.state.count > 5 {
20+
LimitView()
21+
} else {
22+
OperationView()
23+
}
24+
}
25+
.alert(isPresented: self.$isAlertCalled) {
26+
Alert(
27+
title: Text("Hi"),
28+
message: Text("Message"),
29+
dismissButton: .cancel {
30+
bloc.add(event: .increment)
31+
}
32+
)
2233
}
23-
}
24-
.alert(isPresented: self.$isAlertCalled) {
25-
Alert(
26-
title: Text("Hi"),
27-
message: Text("Message"),
28-
dismissButton: .cancel {
29-
bloc.add(event: .increment)
34+
}, action: { (bloc) in
35+
if bloc.state.count < -1 {
36+
DispatchQueue.main.async {
37+
self.isAlertCalled = true
3038
}
31-
)
32-
}
33-
}, action: { (bloc) in
34-
if bloc.state.count < -1 {
35-
DispatchQueue.main.async {
36-
self.isAlertCalled = true
3739
}
38-
}
39-
}, base: CounterBloc())
40+
}, base: CounterBloc())
41+
.navigationBarTitle(Text("Bloc"), displayMode: .inline)
42+
}
4043
}
4144
}
4245

Example/SwiftBloc/CubitContentView.swift

Lines changed: 18 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -11,21 +11,24 @@ import SwiftUI
1111

1212
struct CubitContentView: View {
1313
var body: some View {
14-
BlocView(builder: { (cubit) in
15-
VStack {
16-
Button(action: {
17-
cubit.increment()
18-
}, label: {
19-
Text("Increment")
20-
})
21-
Button(action: {
22-
cubit.decrement()
23-
}, label: {
24-
Text("Decrement")
25-
})
26-
Text("Count: \(cubit.state)")
27-
}
28-
}, base: CounterCubit())
14+
NavigationView {
15+
BlocView(builder: { (cubit) in
16+
VStack {
17+
Button(action: {
18+
cubit.increment()
19+
}, label: {
20+
Text("Increment")
21+
})
22+
Button(action: {
23+
cubit.decrement()
24+
}, label: {
25+
Text("Decrement")
26+
})
27+
Text("Count: \(cubit.state)")
28+
}
29+
}, base: CounterCubit())
30+
.navigationBarTitle(Text("Cubit"), displayMode: .inline)
31+
}
2932
}
3033
}
3134

Example/SwiftBloc/MainView.swift

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -11,21 +11,22 @@ import SwiftBloc
1111

1212
struct MainView: View {
1313
var body: some View {
14-
NavigationView {
15-
TabView {
16-
CubitContentView()
14+
TabView {
15+
CubitContentView()
1716
.tabItem {
18-
Text("Cubit")
1917
Image(systemName: "arrow.counterclockwise")
18+
Text("Cubit")
2019
}
21-
.navigationBarTitle("Cubit")
22-
BlocContentView()
20+
BlocContentView()
2321
.tabItem {
24-
Text("Bloc")
2522
Image(systemName: "cube")
23+
Text("Bloc")
24+
}
25+
WebView()
26+
.tabItem {
27+
Image(systemName: "message")
28+
Text("Web")
2629
}
27-
.navigationBarTitle("Bloc")
28-
}
2930
}
3031
}
3132
}

Example/SwiftBloc/SceneDelegate.swift

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,10 +19,9 @@ class SceneDelegate: UIResponder, UIWindowSceneDelegate {
1919
) {
2020
let contentView = MainView()
2121
if let windowScene = scene as? UIWindowScene {
22-
let window = UIWindow(windowScene: windowScene)
23-
window.rootViewController = UIHostingController(rootView: contentView)
24-
self.window = window
25-
window.makeKeyAndVisible()
22+
window = UIWindow(windowScene: windowScene)
23+
window?.rootViewController = UIHostingController(rootView: contentView)
24+
window?.makeKeyAndVisible()
2625
}
2726
}
2827
}

Example/SwiftBloc/SuccessView.swift

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
//
2+
// SuccessView.swift
3+
// SwiftBloc_Example
4+
//
5+
// Created by Kachalov, Victor on 22.04.21.
6+
// Copyright © 2021 CocoaPods. All rights reserved.
7+
//
8+
9+
import SwiftUI
10+
11+
struct SuccessView: View {
12+
var body: some View {
13+
Text("I am an amazing SwiftUI Text")
14+
}
15+
}
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
//
2+
// SuccessViewController.swift
3+
// SwiftBloc_Example
4+
//
5+
// Created by Kachalov, Victor on 22.04.21.
6+
// Copyright © 2021 CocoaPods. All rights reserved.
7+
//
8+
9+
import SwiftUI
10+
11+
final class SuccessViewController: UIHostingController<SuccessView> {
12+
required init?(coder aDecoder: NSCoder) {
13+
super.init(coder: aDecoder, rootView: SuccessView())
14+
}
15+
}

Example/SwiftBloc/Web.storyboard

Lines changed: 94 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,94 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<document type="com.apple.InterfaceBuilder3.CocoaTouch.Storyboard.XIB" version="3.0" toolsVersion="17701" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" useTraitCollections="YES" useSafeAreas="YES" colorMatched="YES">
3+
<device id="retina6_1" orientation="portrait" appearance="light"/>
4+
<dependencies>
5+
<deployment identifier="iOS"/>
6+
<plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="17703"/>
7+
<capability name="Safe area layout guides" minToolsVersion="9.0"/>
8+
<capability name="System colors in document resources" minToolsVersion="11.0"/>
9+
<capability name="documents saved in the Xcode 8 format" minToolsVersion="8.0"/>
10+
</dependencies>
11+
<scenes>
12+
<!--UIViewControllerRepresentable-->
13+
<scene sceneID="1sH-G9-UAw">
14+
<objects>
15+
<viewController storyboardIdentifier="WebViewController" id="Ehu-Ay-Ln0" customClass="WebViewController" customModule="SwiftBloc_Example" customModuleProvider="target" sceneMemberID="viewController">
16+
<view key="view" contentMode="scaleToFill" id="JIb-L9-0eb">
17+
<rect key="frame" x="0.0" y="0.0" width="414" height="896"/>
18+
<autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/>
19+
<subviews>
20+
<wkWebView contentMode="scaleToFill" translatesAutoresizingMaskIntoConstraints="NO" id="fQN-lX-TRd">
21+
<rect key="frame" x="0.0" y="88" width="414" height="774"/>
22+
<color key="backgroundColor" red="0.36078431372549019" green="0.38823529411764707" blue="0.40392156862745099" alpha="1" colorSpace="custom" customColorSpace="sRGB"/>
23+
<wkWebViewConfiguration key="configuration">
24+
<audiovisualMediaTypes key="mediaTypesRequiringUserActionForPlayback" none="YES"/>
25+
<wkPreferences key="preferences"/>
26+
</wkWebViewConfiguration>
27+
</wkWebView>
28+
</subviews>
29+
<viewLayoutGuide key="safeArea" id="VdB-9K-hfL"/>
30+
<color key="backgroundColor" systemColor="systemBackgroundColor"/>
31+
<constraints>
32+
<constraint firstItem="fQN-lX-TRd" firstAttribute="trailing" secondItem="VdB-9K-hfL" secondAttribute="trailing" id="BtN-YI-6T0"/>
33+
<constraint firstItem="fQN-lX-TRd" firstAttribute="bottom" secondItem="VdB-9K-hfL" secondAttribute="bottom" id="KA5-Tp-r3A"/>
34+
<constraint firstItem="fQN-lX-TRd" firstAttribute="leading" secondItem="VdB-9K-hfL" secondAttribute="leading" id="KR2-MW-xv2"/>
35+
<constraint firstItem="fQN-lX-TRd" firstAttribute="top" secondItem="VdB-9K-hfL" secondAttribute="top" id="eOS-MP-VUM"/>
36+
</constraints>
37+
</view>
38+
<navigationItem key="navigationItem" title="UIViewControllerRepresentable" id="CPB-Sj-LFT">
39+
<barButtonItem key="rightBarButtonItem" title="Item" image="paperplane" catalog="system" id="OUE-a0-kQh">
40+
<connections>
41+
<segue destination="Qyc-F2-ef0" kind="show" id="8wq-y5-PDA"/>
42+
</connections>
43+
</barButtonItem>
44+
</navigationItem>
45+
<connections>
46+
<outlet property="webView" destination="fQN-lX-TRd" id="hOo-Hs-EbW"/>
47+
</connections>
48+
</viewController>
49+
<placeholder placeholderIdentifier="IBFirstResponder" id="4wM-ro-qVs" userLabel="First Responder" customClass="UIResponder" sceneMemberID="firstResponder"/>
50+
</objects>
51+
<point key="canvasLocation" x="1073.913043478261" y="89.732142857142847"/>
52+
</scene>
53+
<!--Success View Controller-->
54+
<scene sceneID="ASx-zo-3Vw">
55+
<objects>
56+
<viewController id="Qyc-F2-ef0" customClass="SuccessViewController" customModule="SwiftBloc_Example" customModuleProvider="target" sceneMemberID="viewController">
57+
<view key="view" contentMode="scaleToFill" id="sf2-3f-TwK">
58+
<rect key="frame" x="0.0" y="0.0" width="414" height="896"/>
59+
<autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/>
60+
<viewLayoutGuide key="safeArea" id="Sgk-xH-ovG"/>
61+
<color key="backgroundColor" systemColor="systemBackgroundColor"/>
62+
</view>
63+
<navigationItem key="navigationItem" id="Hnj-8G-fhW"/>
64+
</viewController>
65+
<placeholder placeholderIdentifier="IBFirstResponder" id="kee-6a-Jyv" userLabel="First Responder" customClass="UIResponder" sceneMemberID="firstResponder"/>
66+
</objects>
67+
<point key="canvasLocation" x="1912" y="90"/>
68+
</scene>
69+
<!--Navigation Controller-->
70+
<scene sceneID="pPn-su-NhF">
71+
<objects>
72+
<navigationController storyboardIdentifier="NavigationWebViewController" automaticallyAdjustsScrollViewInsets="NO" id="ENf-3r-RzJ" sceneMemberID="viewController">
73+
<toolbarItems/>
74+
<navigationBar key="navigationBar" contentMode="scaleToFill" id="qEI-n8-byV">
75+
<rect key="frame" x="0.0" y="44" width="414" height="44"/>
76+
<autoresizingMask key="autoresizingMask"/>
77+
</navigationBar>
78+
<nil name="viewControllers"/>
79+
<connections>
80+
<segue destination="Ehu-Ay-Ln0" kind="relationship" relationship="rootViewController" id="iaH-Dv-oTq"/>
81+
</connections>
82+
</navigationController>
83+
<placeholder placeholderIdentifier="IBFirstResponder" id="Lxu-GZ-372" userLabel="First Responder" customClass="UIResponder" sceneMemberID="firstResponder"/>
84+
</objects>
85+
<point key="canvasLocation" x="163.768115942029" y="89.732142857142847"/>
86+
</scene>
87+
</scenes>
88+
<resources>
89+
<image name="paperplane" catalog="system" width="128" height="118"/>
90+
<systemColor name="systemBackgroundColor">
91+
<color white="1" alpha="1" colorSpace="custom" customColorSpace="genericGamma22GrayColorSpace"/>
92+
</systemColor>
93+
</resources>
94+
</document>

Example/SwiftBloc/WebView.swift

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
//
2+
// WebView.swift
3+
// SwiftBloc_Example
4+
//
5+
// Created by Kachalov, Victor on 22.04.21.
6+
// Copyright © 2021 CocoaPods. All rights reserved.
7+
//
8+
9+
import SwiftUI
10+
11+
struct WebView: UIViewControllerRepresentable {
12+
typealias UIViewControllerType = UIViewController
13+
14+
func makeUIViewController(context: Context) -> UIViewController {
15+
let storyboard = UIStoryboard(name: "Web", bundle: Bundle.main)
16+
return storyboard.instantiateViewController(withIdentifier: "NavigationWebViewController")
17+
}
18+
19+
func updateUIViewController(_ uiViewController: UIViewController, context: Context) {}
20+
}
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
//
2+
// WebViewController.swift
3+
// SwiftBloc_Example
4+
//
5+
// Created by Kachalov, Victor on 22.04.21.
6+
// Copyright © 2021 CocoaPods. All rights reserved.
7+
//
8+
9+
import UIKit
10+
import WebKit
11+
12+
final class WebViewController: UIViewController {
13+
@IBOutlet weak var webView: WKWebView!
14+
15+
override func viewDidLoad() {
16+
let url = URL(string: "https://www.google.com")
17+
let request = URLRequest(url: url!)
18+
webView.load(request)
19+
}
20+
}

0 commit comments

Comments
 (0)