Skip to content

Commit

Permalink
Create SwiftUI Example
Browse files Browse the repository at this point in the history
  • Loading branch information
AndrewSB committed Mar 7, 2021
1 parent 4cf2da1 commit 86da4c7
Show file tree
Hide file tree
Showing 3 changed files with 83 additions and 3 deletions.
8 changes: 6 additions & 2 deletions Example/Example.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
38F0C20820C89D1600FF8DD3 /* InboxCell.swift in Sources */ = {isa = PBXBuildFile; fileRef = 38F0C20720C89D1600FF8DD3 /* InboxCell.swift */; };
38FCF9D6219F797600A47350 /* READMEPreviewViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 38FCF9D5219F797600A47350 /* READMEPreviewViewController.swift */; };
468A8728251C8AC20018D007 /* ButtonAnimationExample.swift in Sources */ = {isa = PBXBuildFile; fileRef = 468A8727251C8AC20018D007 /* ButtonAnimationExample.swift */; };
46E4094E252996D900D238A8 /* SwiftUIExample.swift in Sources */ = {isa = PBXBuildFile; fileRef = 46E4094D252996D900D238A8 /* SwiftUIExample.swift */; };
/* End PBXBuildFile section */

/* Begin PBXCopyFilesBuildPhase section */
Expand Down Expand Up @@ -71,6 +72,7 @@
38F0C20720C89D1600FF8DD3 /* InboxCell.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = InboxCell.swift; sourceTree = "<group>"; };
38FCF9D5219F797600A47350 /* READMEPreviewViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = READMEPreviewViewController.swift; sourceTree = "<group>"; };
468A8727251C8AC20018D007 /* ButtonAnimationExample.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ButtonAnimationExample.swift; sourceTree = "<group>"; };
46E4094D252996D900D238A8 /* SwiftUIExample.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SwiftUIExample.swift; sourceTree = "<group>"; };
/* End PBXFileReference section */

/* Begin PBXFrameworksBuildPhase section */
Expand Down Expand Up @@ -111,6 +113,7 @@
3821ADE320F5359800DE0D1D /* CommonTableViewController.swift */,
3821ADE020F534DA00DE0D1D /* InputAccessoryExampleViewController.swift */,
3821ADDF20F534DA00DE0D1D /* SubviewExampleViewController.swift */,
46E4094D252996D900D238A8 /* SwiftUIExample.swift */,
468A8726251C8AAB0018D007 /* Community Examples */,
38F0C1FC20C89C8700FF8DD3 /* InputBarExamples */,
38F0C20920C89D2D00FF8DD3 /* Cells */,
Expand Down Expand Up @@ -255,6 +258,7 @@
38C888C6202051B3000F2E2F /* ImageCell.swift in Sources */,
38DAD87D21A685C6001762CD /* NoTextViewInputBar.swift in Sources */,
3821ADE220F534DA00DE0D1D /* InputAccessoryExampleViewController.swift in Sources */,
46E4094E252996D900D238A8 /* SwiftUIExample.swift in Sources */,
3821ADE620F5360B00DE0D1D /* InputBarStyle.swift in Sources */,
);
runOnlyForDeploymentPostprocessing = 0;
Expand Down Expand Up @@ -324,7 +328,7 @@
GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE;
GCC_WARN_UNUSED_FUNCTION = YES;
GCC_WARN_UNUSED_VARIABLE = YES;
IPHONEOS_DEPLOYMENT_TARGET = 12.0;
IPHONEOS_DEPLOYMENT_TARGET = 13.0;
MTL_ENABLE_DEBUG_INFO = YES;
ONLY_ACTIVE_ARCH = YES;
SDKROOT = iphoneos;
Expand Down Expand Up @@ -380,7 +384,7 @@
GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE;
GCC_WARN_UNUSED_FUNCTION = YES;
GCC_WARN_UNUSED_VARIABLE = YES;
IPHONEOS_DEPLOYMENT_TARGET = 12.0;
IPHONEOS_DEPLOYMENT_TARGET = 13.0;
MTL_ENABLE_DEBUG_INFO = NO;
SDKROOT = iphoneos;
SWIFT_OPTIMIZATION_LEVEL = "-Owholemodule";
Expand Down
7 changes: 6 additions & 1 deletion Example/Example/InputBarStyleSelectionController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
//

import UIKit
import SwiftUI

class InputBarStyleSelectionController: UITableViewController {

Expand Down Expand Up @@ -48,7 +49,7 @@ class InputBarStyleSelectionController: UITableViewController {
switch section {
case 0: return 1
case 1...2: return styles.count
case 3: return 2
case 3: return 3
default: fatalError("unknown section \(section)")
}
}
Expand All @@ -60,6 +61,7 @@ class InputBarStyleSelectionController: UITableViewController {
case (1...2, _): cell.textLabel?.text = styles[indexPath.row].rawValue
case (3, 0): cell.textLabel?.text = "Tab bar example (Slack style)"
case (3, 1): cell.textLabel?.text = "Send button animations"
case (3, 2): cell.textLabel?.text = "SwiftUI example"
default: assertionFailure("unrecognized \(indexPath). Are you trying to add an additional example?")
}

Expand Down Expand Up @@ -93,6 +95,9 @@ class InputBarStyleSelectionController: UITableViewController {
case 1:
let example = ButtonAnimationExample(style: .imessage, conversation: convo)
navigationController?.pushViewController(example, animated: true)
case 2:
let example = UIHostingController(rootView: SwiftUIExample.make(style: .imessage, conversation: convo))
navigationController?.pushViewController(example, animated: true)
default:
fatalError("Unknown row \(indexPath.row) in Community Examples section. Are you trying to add a new example?")
}
Expand Down
71 changes: 71 additions & 0 deletions Example/Example/SwiftUIExample.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
//
// SwiftUIExample.swift
// Example
//
// Created by Andrew Breckenridge on 10/3/20.
// Copyright © 2020 Nathan Tannar. All rights reserved.
//

import UIKit
import SwiftUI
import InputBarAccessoryView

var built: CommonTableViewController?

struct CommonTableViewControllerUI: UIViewControllerRepresentable {
let style: InputBarStyle
let conversation: SampleData.Conversation

var inputBar: InputBarAccessoryView {
if built == nil {
built = CommonTableViewController(style: style, conversation: conversation)
}
return built!.inputBar
}

func makeUIViewController(context: Context) -> some UIViewController {
if built == nil {
built = CommonTableViewController(style: style, conversation: conversation)
}
return built!
}

func updateUIViewController(_ uiViewController: UIViewControllerType, context: Context) {
}
}

struct InputBarUI: UIViewRepresentable {
let view: InputBarAccessoryView

func makeUIView(context: Context) -> some UIView {
return view
}

func updateUIView(_ uiView: UIViewType, context: Context) {
}
}


public struct SwiftUIExample: View {
let style: InputBarStyle
let conversation: SampleData.Conversation

var table: CommonTableViewControllerUI {
CommonTableViewControllerUI(style: style, conversation: conversation)
}


public var body: some View {
VStack {
self.table
InputBarUI(view: table.inputBar)
}
}

}

extension SwiftUIExample {
static func make(style: InputBarStyle, conversation: SampleData.Conversation) -> Self {
return Self.init(style: style, conversation: conversation)
}
}

0 comments on commit 86da4c7

Please sign in to comment.