Skip to content

Commit 19dcf0d

Browse files
authored
Merge pull request #44 from huri000/feature/view-controller-entry
View Controller Entry
2 parents 2c7bbf3 + f281281 commit 19dcf0d

18 files changed

+597
-453
lines changed

CHANGELOG.md

+8
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,14 @@
11
# Change Log
22
Any notable changes to this project will be documented in this file.
33

4+
## 0.4.0
5+
6+
### Features
7+
8+
#### [Use UIViewController as an entry #40](https://github.com/huri000/SwiftEntryKit/issues/40)
9+
Developers can now use a customized view controller as an entry.
10+
A sample has been added to the custom presets section in example project.
11+
412
## 0.3.3
513

614
### Issues Handled:

Example/Podfile.lock

+2-2
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ PODS:
22
- Nimble (7.0.2)
33
- Quick (1.2.0)
44
- QuickLayout (2.0.2)
5-
- SwiftEntryKit (0.3.2):
5+
- SwiftEntryKit (0.4.0):
66
- QuickLayout (= 2.0.2)
77

88
DEPENDENCIES:
@@ -24,7 +24,7 @@ SPEC CHECKSUMS:
2424
Nimble: bfe1f814edabba69ff145cb1283e04ed636a67f2
2525
Quick: 58d203b1c5e27fff7229c4c1ae445ad7069a7a08
2626
QuickLayout: a730730b646b231fd4ef7cffaeb1e81fe0e1ca92
27-
SwiftEntryKit: e2e36ab4cb060d0ce190b4a399a5bca26dcc2bad
27+
SwiftEntryKit: 89fdd4a15ae213d9b9bbcf36a319d2d3696f5f13
2828

2929
PODFILE CHECKSUM: edd6c2af5cc390dbf823427759474ab6c303ec9e
3030

Example/Pods/Local Podspecs/SwiftEntryKit.podspec.json

+2-2
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Example/Pods/Manifest.lock

+2-2
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Example/Pods/Pods.xcodeproj/project.pbxproj

+323-319
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Example/Pods/Target Support Files/SwiftEntryKit/Info.plist

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Example/SwiftEntryKit.xcodeproj/project.pbxproj

+16
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,8 @@
3030
149D0A1220AF1EE7000AA6C4 /* FormFieldPresetFactory.swift in Sources */ = {isa = PBXBuildFile; fileRef = 149D0A1120AF1EE7000AA6C4 /* FormFieldPresetFactory.swift */; };
3131
14A1AB3520930120001CA5B4 /* PresetsDataSource.swift in Sources */ = {isa = PBXBuildFile; fileRef = 14A1AB3420930120001CA5B4 /* PresetsDataSource.swift */; };
3232
14A40C63208B7AA800B79474 /* PlaygroundViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 14A40C62208B7AA800B79474 /* PlaygroundViewController.swift */; };
33+
14A6AAB220CA5B2C005F3D81 /* SwiftEntryKit+Execution.swift in Sources */ = {isa = PBXBuildFile; fileRef = 14A6AAB120CA5B2C005F3D81 /* SwiftEntryKit+Execution.swift */; };
34+
14A6AAC420CA7208005F3D81 /* ExampleViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 14A6AAC320CA7208005F3D81 /* ExampleViewController.swift */; };
3335
14B3A50720C1198A002306C4 /* EKRatingMessageView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 14B3A50620C1198A002306C4 /* EKRatingMessageView.swift */; };
3436
14B3A51220C16B64002306C4 /* EKRatingMessage.swift in Sources */ = {isa = PBXBuildFile; fileRef = 14B3A51120C16B64002306C4 /* EKRatingMessage.swift */; };
3537
14B3A51420C16BAC002306C4 /* EKAlertMessage.swift in Sources */ = {isa = PBXBuildFile; fileRef = 14B3A51320C16BAC002306C4 /* EKAlertMessage.swift */; };
@@ -218,6 +220,8 @@
218220
149D0A1120AF1EE7000AA6C4 /* FormFieldPresetFactory.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = FormFieldPresetFactory.swift; sourceTree = "<group>"; };
219221
14A1AB3420930120001CA5B4 /* PresetsDataSource.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = PresetsDataSource.swift; sourceTree = "<group>"; };
220222
14A40C62208B7AA800B79474 /* PlaygroundViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = PlaygroundViewController.swift; sourceTree = "<group>"; };
223+
14A6AAB120CA5B2C005F3D81 /* SwiftEntryKit+Execution.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "SwiftEntryKit+Execution.swift"; sourceTree = "<group>"; };
224+
14A6AAC320CA7208005F3D81 /* ExampleViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ExampleViewController.swift; sourceTree = "<group>"; };
221225
14B0B95020B7E4FE00D24D8A /* QuickLayout.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = QuickLayout.framework; path = "../../../Library/Developer/Xcode/DerivedData/QuickLayout-aotxzuhsyjyfzgcifoglldyfgnnw/Build/Products/Debug-iphonesimulator/QuickLayout-iOS/QuickLayout.framework"; sourceTree = "<group>"; };
222226
14B3A50620C1198A002306C4 /* EKRatingMessageView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = EKRatingMessageView.swift; sourceTree = "<group>"; };
223227
14B3A51120C16B64002306C4 /* EKRatingMessage.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = EKRatingMessage.swift; sourceTree = "<group>"; };
@@ -382,6 +386,14 @@
382386
path = PresetsData;
383387
sourceTree = "<group>";
384388
};
389+
14A6AABB20CA71D9005F3D81 /* ExampleViewController */ = {
390+
isa = PBXGroup;
391+
children = (
392+
14A6AAC320CA7208005F3D81 /* ExampleViewController.swift */,
393+
);
394+
path = ExampleViewController;
395+
sourceTree = "<group>";
396+
};
385397
14B48B1720B81C9700CE3EF4 /* Source */ = {
386398
isa = PBXGroup;
387399
children = (
@@ -424,6 +436,7 @@
424436
14B48B2520B81C9700CE3EF4 /* Extensions */ = {
425437
isa = PBXGroup;
426438
children = (
439+
14A6AAB120CA5B2C005F3D81 /* SwiftEntryKit+Execution.swift */,
427440
14B48B2620B81C9700CE3EF4 /* UIView+Utils.swift */,
428441
14B48B2720B81C9700CE3EF4 /* UIRectCorner+Short.swift */,
429442
14B48B2820B81C9700CE3EF4 /* UIEdgeInsets+Utils.swift */,
@@ -514,6 +527,7 @@
514527
14C729C6209447CA0060D267 /* Samples */ = {
515528
isa = PBXGroup;
516529
children = (
530+
14A6AABB20CA71D9005F3D81 /* ExampleViewController */,
517531
14D18CD0209118950019AE7F /* NibExampleView */,
518532
);
519533
path = Samples;
@@ -1019,6 +1033,7 @@
10191033
14B48B6820B81C9700CE3EF4 /* EKProperty.swift in Sources */,
10201034
14B48B6520B81C9700CE3EF4 /* UIEdgeInsets+Utils.swift in Sources */,
10211035
14B3A51620C16BC3002306C4 /* EKSimpleMessage.swift in Sources */,
1036+
14A6AAB220CA5B2C005F3D81 /* SwiftEntryKit+Execution.swift in Sources */,
10221037
14B48B5D20B81C9700CE3EF4 /* EKWrapperView.swift in Sources */,
10231038
14B48B6320B81C9700CE3EF4 /* UIView+Utils.swift in Sources */,
10241039
14B3A51820C16D7A002306C4 /* EKRatingSymbolView.swift in Sources */,
@@ -1048,6 +1063,7 @@
10481063
1496D956209CC6EF002CBB22 /* Object+ClassName.swift in Sources */,
10491064
143F3AAE2090B4E2009F3719 /* HapticFeedbackSelectionTableViewCell.swift in Sources */,
10501065
14C729D5209476A90060D267 /* BorderSelectionTableViewCell.swift in Sources */,
1066+
14A6AAC420CA7208005F3D81 /* ExampleViewController.swift in Sources */,
10511067
143F3AA42090A70E009F3719 /* RoundCornersSelectionTableViewCell.swift in Sources */,
10521068
14C894F8208E70D5003D8CE3 /* SelectionTableViewCell.swift in Sources */,
10531069
14665621209204A5008FB96D /* AnimationSelectionTableViewCell.swift in Sources */,

Example/SwiftEntryKit/Presets/PresetsData/PresetsDataSource.swift

+42-13
Original file line numberDiff line numberDiff line change
@@ -335,6 +335,24 @@ struct PresetsDataSource {
335335
description = .init(with: attributes, title: "Center Alert View", description: descriptionString, thumb: descriptionThumb)
336336
presets.append(description)
337337

338+
// Preset VI
339+
attributes = .centerFloat
340+
attributes.windowLevel = .alerts
341+
attributes.hapticFeedbackType = .success
342+
attributes.screenInteraction = .absorbTouches
343+
attributes.entryInteraction = .absorbTouches
344+
attributes.scroll = .disabled
345+
attributes.screenBackground = .color(color: .dimmedLightBackground)
346+
attributes.entryBackground = .color(color: UIColor.white.withAlphaComponent(0.98))
347+
attributes.entranceAnimation = .init(scale: .init(from: 0.9, to: 1, duration: 0.4, spring: .init(damping: 0.8, initialVelocity: 0)), fade: .init(from: 0, to: 1, duration: 0.3))
348+
attributes.exitAnimation = .init(scale: .init(from: 1, to: 0.4, duration: 0.4, spring: .init(damping: 1, initialVelocity: 0)), fade: .init(from: 1, to: 0, duration: 0.2))
349+
attributes.displayDuration = .infinity
350+
attributes.positionConstraints.maxSize = .init(width: .constant(value: UIScreen.main.minEdge), height: .intrinsic)
351+
descriptionString = "Appears in the center. Fun, expressive, and rich with animations"
352+
descriptionThumb = ThumbDesc.bottomPopup.rawValue
353+
description = .init(with: attributes, title: "Service Rating", description: descriptionString, thumb: descriptionThumb)
354+
presets.append(description)
355+
338356
dataSource.append(("Alerts & Popups", presets))
339357
}
340358

@@ -465,23 +483,34 @@ struct PresetsDataSource {
465483
presets.append(description)
466484

467485
// Preset II
468-
attributes = .centerFloat
469-
attributes.windowLevel = .alerts
486+
attributes = .bottomFloat
470487
attributes.hapticFeedbackType = .success
471-
attributes.screenInteraction = .absorbTouches
488+
attributes.displayDuration = 3
489+
attributes.screenBackground = .clear
490+
attributes.entryBackground = .clear
491+
attributes.screenInteraction = .forward
472492
attributes.entryInteraction = .absorbTouches
473-
attributes.scroll = .disabled
474-
attributes.screenBackground = .color(color: .dimmedLightBackground)
475-
attributes.entryBackground = .color(color: UIColor.white.withAlphaComponent(0.98))
476-
attributes.entranceAnimation = .init(scale: .init(from: 0.9, to: 1, duration: 0.4, spring: .init(damping: 0.8, initialVelocity: 0)), fade: .init(from: 0, to: 1, duration: 0.3))
477-
attributes.exitAnimation = .init(scale: .init(from: 1, to: 0.4, duration: 0.4, spring: .init(damping: 1, initialVelocity: 0)), fade: .init(from: 1, to: 0, duration: 0.2))
478-
attributes.displayDuration = .infinity
493+
attributes.roundCorners = .all(radius: 5)
494+
495+
attributes.entranceAnimation = .init(translate: .init(duration: 0.5, spring: .init(damping: 0.9, initialVelocity: 0)),
496+
scale: .init(from: 0.8, to: 1, duration: 0.5, spring: .init(damping: 0.8, initialVelocity: 0)),
497+
fade: .init(from: 0.7, to: 1, duration: 0.3))
498+
attributes.exitAnimation = .init(translate: .init(duration: 0.5),
499+
scale: .init(from: 1, to: 0.8, duration: 0.5),
500+
fade: .init(from: 1, to: 0, duration: 0.5))
501+
attributes.popBehavior = .animated(animation: .init(translate: .init(duration: 0.3),
502+
scale: .init(from: 1, to: 0.8, duration: 0.3)))
503+
attributes.shadow = .active(with: .init(color: .black, opacity: 0.3, radius: 6))
504+
attributes.positionConstraints.verticalOffset = 10
505+
attributes.positionConstraints.size = .init(width: .offset(value: 20), height: .intrinsic)
479506
attributes.positionConstraints.maxSize = .init(width: .constant(value: UIScreen.main.minEdge), height: .intrinsic)
480-
descriptionString = "Appears in the center. Fun, expressive, and rich with animations"
481-
descriptionThumb = ThumbDesc.bottomPopup.rawValue
482-
description = .init(with: attributes, title: "Service Rating", description: descriptionString, thumb: descriptionThumb)
507+
508+
attributes.statusBar = .dark
509+
descriptionString = "Customized UIViewController that is using an injected view"
510+
descriptionThumb = ThumbDesc.bottomFloat.rawValue
511+
description = .init(with: attributes, title: "View Controller", description: descriptionString, thumb: descriptionThumb)
483512
presets.append(description)
484-
513+
485514
dataSource.append(("Custom", presets))
486515
}
487516
}

Example/SwiftEntryKit/Presets/PresetsViewController.swift

+10-2
Original file line numberDiff line numberDiff line change
@@ -284,11 +284,17 @@ class PresetsViewController: UIViewController {
284284
SwiftEntryKit.display(entry: contentView, using: attributes)
285285
}
286286

287-
// Bumps a custom nib view
287+
// Bumps a custom nib originated view
288288
private func showCustomNibView(attributes: EKAttributes) {
289289
SwiftEntryKit.display(entry: NibExampleView(), using: attributes)
290290
}
291291

292+
// Bumps a custom view controller that is using a view from nib
293+
private func showCustomViewController(attributes: EKAttributes) {
294+
let viewController = ExampleViewController(with: NibExampleView())
295+
SwiftEntryKit.display(entry: viewController, using: attributes)
296+
}
297+
292298
// Sign in form
293299
private func showSigninForm(attributes: EKAttributes, style: FormStyle) {
294300
let title = EKProperty.LabelContent(text: "Sign in to your account", style: style.title)
@@ -433,6 +439,8 @@ extension PresetsViewController {
433439
showButtonBarMessage(attributes: attributes)
434440
case 4:
435441
showAlertView(attributes: attributes)
442+
case 5:
443+
showRatingView(attributes: attributes)
436444
default:
437445
break
438446
}
@@ -456,7 +464,7 @@ extension PresetsViewController {
456464
case 0:
457465
showCustomNibView(attributes: attributes)
458466
case 1:
459-
showRatingView(attributes: attributes)
467+
showCustomViewController(attributes: attributes)
460468
default:
461469
break
462470
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
//
2+
// ExampleViewController.swift
3+
// SwiftEntryKitDemo
4+
//
5+
// Created by Daniel Huri on 6/8/18.
6+
// Copyright © 2018 CocoaPods. All rights reserved.
7+
//
8+
9+
import UIKit
10+
11+
class ExampleViewController: UIViewController {
12+
13+
private let injectedView: UIView
14+
15+
init(with view: UIView) {
16+
injectedView = view
17+
super.init(nibName: nil, bundle: nil)
18+
}
19+
20+
required init?(coder aDecoder: NSCoder) {
21+
fatalError("init(coder:) has not been implemented")
22+
}
23+
24+
override func loadView() {
25+
view = injectedView
26+
}
27+
}

README.md

+9-2
Original file line numberDiff line numberDiff line change
@@ -127,7 +127,7 @@ source 'https://github.com/cocoapods/specs.git'
127127
platform :ios, '9.0'
128128
use_frameworks!
129129

130-
pod 'SwiftEntryKit', '0.3.3'
130+
pod 'SwiftEntryKit', '0.4.0'
131131
```
132132

133133
Then, run the following command:
@@ -150,7 +150,7 @@ $ brew install carthage
150150
To integrate SwiftEntryKit into your Xcode project using Carthage, specify the following in your `Cartfile`:
151151

152152
```ogdl
153-
github "huri000/SwiftEntryKit" == 0.3.3
153+
github "huri000/SwiftEntryKit" == 0.4.0
154154
```
155155

156156
## Usage
@@ -553,6 +553,13 @@ let customView = UIView()
553553
SwiftEntryKit.display(entry: customView, using: attributes)
554554
```
555555

556+
### Displaying a View Controller
557+
As from version 0.4.0, view controllers are supported as well.
558+
559+
```Swift
560+
SwiftEntryKit.display(entry: customViewController, using: attributes)
561+
```
562+
556563
### Dismissing an Entry
557564
You can dismiss an entry by simply invoke *dismiss* in the SwiftEntryKit class, likewise:
558565
```Swift
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
//
2+
// EKExecution.swift
3+
// SwiftEntryKit
4+
//
5+
// Created by Daniel Huri on 6/8/18.
6+
// Copyright (c) 2018 [email protected]. All rights reserved.
7+
//
8+
9+
import Foundation
10+
11+
extension SwiftEntryKit {
12+
13+
/**
14+
Executes a UI action on the main thread, thus letting any of the class methods of SwiftEntryKit to be invokes even from a background thread.
15+
*/
16+
static func execute(action: @escaping () -> ()) {
17+
if Thread.isMainThread {
18+
action()
19+
} else {
20+
DispatchQueue.main.async {
21+
action()
22+
}
23+
}
24+
}
25+
}
26+
27+

Source/Infra/EKContentView.swift

+8-6
Original file line numberDiff line numberDiff line change
@@ -58,10 +58,12 @@ class EKContentView: UIView {
5858
private var keyboardState = KeyboardState.hidden
5959

6060
// Data source
61-
private var attributes: EKAttributes!
61+
private var attributes: EKAttributes {
62+
return contentView.attributes
63+
}
6264

6365
// Content
64-
private var contentView: UIView!
66+
private var contentView: EKEntryView!
6567

6668
// MARK: Setup
6769
required init?(coder aDecoder: NSCoder) {
@@ -74,9 +76,8 @@ class EKContentView: UIView {
7476
}
7577

7678
// Called from outer scope with a presentable view and attributes
77-
func setup(with contentView: UIView, attributes: EKAttributes) {
79+
func setup(with contentView: EKEntryView) {
7880

79-
self.attributes = attributes
8081
self.contentView = contentView
8182

8283
// Setup attributes
@@ -444,15 +445,16 @@ class EKContentView: UIView {
444445

445446
// Remove self from superview
446447
func removeFromSuperview(keepWindow: Bool) {
447-
guard let _ = superview else {
448+
guard superview != nil else {
448449
return
449450
}
450451
super.removeFromSuperview()
452+
contentView.content.viewController?.removeFromParentViewController()
451453
if EKAttributes.count > 0 {
452454
EKAttributes.count -= 1
453455
}
454456
if !keepWindow && !EKAttributes.isDisplaying {
455-
EKWindowProvider.shared.state = .main
457+
EKWindowProvider.shared.displayMainWindow()
456458
}
457459
}
458460

0 commit comments

Comments
 (0)