Skip to content

Commit

Permalink
Update Demo project
Browse files Browse the repository at this point in the history
  • Loading branch information
rivera-ernesto committed Nov 14, 2019
1 parent 221b73e commit 66c9559
Show file tree
Hide file tree
Showing 13 changed files with 98 additions and 22 deletions.
2 changes: 1 addition & 1 deletion Demo/Podfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ EXTERNAL SOURCES:
:path: "../"

SPEC CHECKSUMS:
AMPopTip: f7d587e42dca04778c86ecceed790a6f72362e36
AMPopTip: 43444807604e7d38713fc15b93fa65fbe369227c
iOSSnapshotTestCase: 415bd84f9dbba4ff45fede49d800bc7332fbedac
Nimble: 051e3d8912d40138fa5591c78594f95fb172af37
Nimble-Snapshots: 438fb1a6fa3c655e246fc9ac375f6cd2964d759a
Expand Down
1 change: 1 addition & 0 deletions Demo/Pods/Local Podspecs/AMPopTip.podspec.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Demo/Pods/Manifest.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions Demo/Pods/Target Support Files/AMPopTip/AMPopTip.xcconfig

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 4 additions & 0 deletions Demo/PopTip Demo.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
65FAEDCB1ECAED0600F5681E /* MainInterface.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = 65FAEDC91ECAED0600F5681E /* MainInterface.storyboard */; };
65FAEDCF1ECAED0600F5681E /* PopTip Extension.appex in Embed App Extensions */ = {isa = PBXBuildFile; fileRef = 65FAEDC31ECAED0600F5681E /* PopTip Extension.appex */; settings = {ATTRIBUTES = (RemoveHeadersOnCopy, ); }; };
94178E90A7FECC3842CC852D /* Pods_PopTip_DemoTests.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 16769670F46D31DE64BD65FD /* Pods_PopTip_DemoTests.framework */; };
94A7C1BF237D8D1A0057E047 /* SwiftUIView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 94A7C1BE237D8D190057E047 /* SwiftUIView.swift */; };
CC7B379E0562CFF5318FA3F3 /* Pods_PopTip_Demo_PopTip_Extension.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 17A0968287A7268EA4723232 /* Pods_PopTip_Demo_PopTip_Extension.framework */; };
/* End PBXBuildFile section */

Expand Down Expand Up @@ -75,6 +76,7 @@
65FAEDC71ECAED0600F5681E /* TodayViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = TodayViewController.swift; sourceTree = "<group>"; };
65FAEDCA1ECAED0600F5681E /* Base */ = {isa = PBXFileReference; lastKnownFileType = file.storyboard; name = Base; path = Base.lproj/MainInterface.storyboard; sourceTree = "<group>"; };
65FAEDCC1ECAED0600F5681E /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = "<group>"; };
94A7C1BE237D8D190057E047 /* SwiftUIView.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = SwiftUIView.swift; sourceTree = "<group>"; };
9C691B16BC4B538EB258C6A2 /* Pods-PopTip Demo.debug.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-PopTip Demo.debug.xcconfig"; path = "Pods/Target Support Files/Pods-PopTip Demo/Pods-PopTip Demo.debug.xcconfig"; sourceTree = "<group>"; };
A1C9EDB2CED7C68DC4FC9991 /* Pods-PopTip Demo-PopTip Extension.release.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-PopTip Demo-PopTip Extension.release.xcconfig"; path = "Pods/Target Support Files/Pods-PopTip Demo-PopTip Extension/Pods-PopTip Demo-PopTip Extension.release.xcconfig"; sourceTree = "<group>"; };
AB67F6130915DD986BE56F57 /* Pods_PopTip_DemoUITests.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; includeInIndex = 0; path = Pods_PopTip_DemoUITests.framework; sourceTree = BUILT_PRODUCTS_DIR; };
Expand Down Expand Up @@ -157,6 +159,7 @@
65E698341EC0C39F002F1E3C /* Resources */,
653472381EB7B89C002DA5DA /* AppDelegate.swift */,
6534723A1EB7B89C002DA5DA /* ViewController.swift */,
94A7C1BE237D8D190057E047 /* SwiftUIView.swift */,
);
path = "PopTip Demo";
sourceTree = "<group>";
Expand Down Expand Up @@ -450,6 +453,7 @@
files = (
6534723B1EB7B89C002DA5DA /* ViewController.swift in Sources */,
653472391EB7B89C002DA5DA /* AppDelegate.swift in Sources */,
94A7C1BF237D8D1A0057E047 /* SwiftUIView.swift in Sources */,
);
runOnlyForDeploymentPostprocessing = 0;
};
Expand Down
52 changes: 52 additions & 0 deletions Demo/PopTip Demo/SwiftUIView.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
//
// SwiftUIView.swift
// PopTip Demo
//
// Created by Ernesto Rivera on 11/13/19.
// Copyright © 2017 Andrea Mazzini. All rights reserved.
//

#if canImport(SwiftUI) && canImport(Combine)
import SwiftUI

@available(iOS 13.0, *)
struct SwiftUIView: View {

var items = [Item(string: "First"),
Item(string: "Second"),
Item(string: "Third"),
Item(string: "Fourth"),
Item(string: "Fifth")]

var body: some View {
ScrollView {
Text("Custom SwiftUI view")
ForEach(items) { item in
HStack {
Image(systemName: "person.circle")
Text(item.string)
Spacer()
}
.foregroundColor(.secondary)
}
}
}
}

class Item: Identifiable {
let id = UUID()

var string: String

init(string: String) {
self.string = string
}
}

@available(iOS 13.0, *)
struct SwiftUIView_Previews: PreviewProvider {
static var previews: some View {
SwiftUIView()
}
}
#endif
46 changes: 32 additions & 14 deletions Demo/PopTip Demo/ViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,8 @@ class ViewController: UIViewController {
print("dismiss")
}
}

var showSwiftUIView = false

@IBAction func action(sender: UIButton) {
guard let button = ButtonType(rawValue: sender.tag) else { return }
Expand All @@ -81,30 +83,43 @@ class ViewController: UIViewController {

switch button {
case .topLeft:
let customView = UIView(frame: CGRect(x: 0, y: 0, width: 80, height: 120))
let imageView = UIImageView(image: UIImage(named: "comment"))
imageView.frame = CGRect(x: (80 - imageView.frame.width) / 2, y: 0, width: imageView.frame.width, height: imageView.frame.height)
customView.addSubview(imageView)
let label = UILabel(frame: CGRect(x: 0, y: imageView.frame.height, width: 80, height: 120 - imageView.frame.height))
label.numberOfLines = 0
label.text = "This is a custom view"
label.textAlignment = .center
label.textColor = .white
label.font = UIFont.systemFont(ofSize: 12)
customView.addSubview(label)
popTip.bubbleColor = UIColor(red: 0.95, green: 0.65, blue: 0.21, alpha: 1)
popTip.cornerRadius = 10
popTip.show(customView: customView, direction: .down, in: view, from: sender.frame)

if !showSwiftUIView
{
let customView = UIView(frame: CGRect(x: 0, y: 0, width: 80, height: 120))
let imageView = UIImageView(image: UIImage(named: "comment"))
imageView.frame = CGRect(x: (80 - imageView.frame.width) / 2, y: 0, width: imageView.frame.width, height: imageView.frame.height)
customView.addSubview(imageView)
let label = UILabel(frame: CGRect(x: 0, y: imageView.frame.height, width: 80, height: 120 - imageView.frame.height))
label.numberOfLines = 0
label.text = "This is a custom view"
label.textAlignment = .center
label.textColor = .white
label.font = UIFont.systemFont(ofSize: 12)
customView.addSubview(label)

popTip.show(customView: customView, direction: .down, in: view, from: sender.frame)
}
else if #available(iOS 13.0.0, *)
{
#if canImport(SwiftUI) && canImport(Combine)
popTip.show(rootView: SwiftUIView(), direction: .down, in: view, from: sender.frame, parent: self)
#endif
}
popTip.entranceAnimationHandler = { [weak self] completion in
guard let `self` = self else { return }
self.popTip.transform = CGAffineTransform(rotationAngle: 0.3)
UIView.animate(withDuration: 0.5, animations: {
UIView.animate(withDuration: 0.5, animations: {
self.popTip.transform = .identity
}, completion: { (_) in
completion()
})
}
if #available(iOS 13.0.0, *)
{
self.showSwiftUIView.toggle()
}

case .topRight:
popTip.bubbleColor = UIColor(red: 0.97, green: 0.9, blue: 0.23, alpha: 1)
Expand All @@ -114,16 +129,19 @@ class ViewController: UIViewController {
topRightDirection = .left
}
popTip.show(text: "I have a offset to move the bubble down or left side.", direction: topRightDirection, maxWidth: 150, in: view, from: sender.frame)

case .bottomLeft:
popTip.bubbleColor = UIColor(red: 0.73, green: 0.91, blue: 0.55, alpha: 1)
let attributes: [NSAttributedString.Key: Any] = [NSAttributedString.Key.font: UIFont.systemFont(ofSize: 12), NSAttributedString.Key.foregroundColor: UIColor.white]
let underline: [NSAttributedString.Key: Any] = [NSAttributedString.Key.font: UIFont.systemFont(ofSize: 13), NSAttributedString.Key.foregroundColor: UIColor.white, NSAttributedString.Key.underlineStyle: NSUnderlineStyle.single.rawValue]
let attributedText = NSMutableAttributedString(string: "I'm presenting a string ", attributes: attributes)
attributedText.append(NSAttributedString(string: "with attributes!", attributes: underline))
popTip.show(attributedText: attributedText, direction: .up, maxWidth: 200, in: view, from: sender.frame)

case .bottomRight:
popTip.bubbleColor = UIColor(red: 0.81, green: 0.04, blue: 0.14, alpha: 1)
popTip.show(text: "Animated popover, great for subtle UI tips and onboarding", direction: .left, maxWidth: 200, in: view, from: sender.frame)

case .center:
popTip.arrowRadius = 2
popTip.bubbleColor = UIColor(red: 0.31, green: 0.57, blue: 0.87, alpha: 1)
Expand Down

0 comments on commit 66c9559

Please sign in to comment.