Skip to content

Commit

Permalink
Demo for present and push
Browse files Browse the repository at this point in the history
  • Loading branch information
onmyway133 committed Nov 17, 2017
1 parent a0e342d commit b6a1f0d
Show file tree
Hide file tree
Showing 3 changed files with 103 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@

/* Begin PBXBuildFile section */
A5D64F81D2320A320429FE7F /* Pods_RxLifeCycleDemo.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 402927438A6D729291AE915C /* Pods_RxLifeCycleDemo.framework */; };
D289C7341FBEE08000691442 /* ChildController.swift in Sources */ = {isa = PBXBuildFile; fileRef = D289C7331FBEE08000691442 /* ChildController.swift */; };
D5C7F74E1C3BC9CE008CDDBA /* LaunchScreen.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = D5C7F74C1C3BC9CE008CDDBA /* LaunchScreen.storyboard */; };
D5C7F75B1C3BCA1E008CDDBA /* Assets.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = D5C7F7571C3BCA1E008CDDBA /* Assets.xcassets */; };
D5C7F75C1C3BCA1E008CDDBA /* AppDelegate.swift in Sources */ = {isa = PBXBuildFile; fileRef = D5C7F7591C3BCA1E008CDDBA /* AppDelegate.swift */; };
Expand All @@ -17,6 +18,7 @@
/* Begin PBXFileReference section */
402927438A6D729291AE915C /* Pods_RxLifeCycleDemo.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; includeInIndex = 0; path = Pods_RxLifeCycleDemo.framework; sourceTree = BUILT_PRODUCTS_DIR; };
89346A3637B34D882458B3F4 /* Pods-RxLifeCycleDemo.release.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-RxLifeCycleDemo.release.xcconfig"; path = "Pods/Target Support Files/Pods-RxLifeCycleDemo/Pods-RxLifeCycleDemo.release.xcconfig"; sourceTree = "<group>"; };
D289C7331FBEE08000691442 /* ChildController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ChildController.swift; sourceTree = "<group>"; };
D5C7F7401C3BC9CE008CDDBA /* RxLifeCycleDemo.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = RxLifeCycleDemo.app; sourceTree = BUILT_PRODUCTS_DIR; };
D5C7F74D1C3BC9CE008CDDBA /* Base */ = {isa = PBXFileReference; lastKnownFileType = file.storyboard; name = Base; path = Base.lproj/LaunchScreen.storyboard; sourceTree = "<group>"; };
D5C7F74F1C3BC9CE008CDDBA /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = "<group>"; };
Expand Down Expand Up @@ -96,6 +98,7 @@
children = (
D5C7F7591C3BCA1E008CDDBA /* AppDelegate.swift */,
D5C7F75A1C3BCA1E008CDDBA /* ViewController.swift */,
D289C7331FBEE08000691442 /* ChildController.swift */,
);
path = Sources;
sourceTree = "<group>";
Expand Down Expand Up @@ -242,6 +245,7 @@
buildActionMask = 2147483647;
files = (
D5C7F75D1C3BCA1E008CDDBA /* ViewController.swift in Sources */,
D289C7341FBEE08000691442 /* ChildController.swift in Sources */,
D5C7F75C1C3BCA1E008CDDBA /* AppDelegate.swift in Sources */,
);
runOnlyForDeploymentPostprocessing = 0;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
import UIKit

class ChildController: UIViewController {
override func viewDidLoad() {
super.viewDidLoad()

// button
let button = UIButton()
button.setTitleColor(.black, for: .normal)
button.setTitle("Dismiss", for: .normal)
button.addTarget(self, action: #selector(doSomething), for: .touchUpInside)
view.addSubview(button)
button.translatesAutoresizingMaskIntoConstraints = false
button.centerXAnchor.constraint(equalTo: view.centerXAnchor).isActive = true
button.centerYAnchor.constraint(equalTo: view.centerYAnchor).isActive = true
}

@objc func doSomething() {
dismiss(animated: true, completion: nil)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,15 +11,42 @@ class ViewController: UIViewController {

view.backgroundColor = .white

_ = lifeCycle.viewWillAppear.subscribe(onNext: {
// present button
do {
let button = UIButton()
button.setTitleColor(.black, for: .normal)
button.setTitle("Present", for: .normal)
button.addTarget(self, action: #selector(presentSomething), for: .touchUpInside)
view.addSubview(button)
button.translatesAutoresizingMaskIntoConstraints = false
button.centerXAnchor.constraint(equalTo: view.centerXAnchor).isActive = true
button.centerYAnchor.constraint(equalTo: view.centerYAnchor).isActive = true
}

do {
let button = UIButton()
button.setTitleColor(.black, for: .normal)
button.setTitle("Push", for: .normal)
button.addTarget(self, action: #selector(pushSomething), for: .touchUpInside)
view.addSubview(button)
button.translatesAutoresizingMaskIntoConstraints = false
button.centerXAnchor.constraint(equalTo: view.centerXAnchor).isActive = true
button.centerYAnchor.constraint(equalTo: view.centerYAnchor, constant: 30).isActive = true
}

// push button

// observe life cycle

_ = rxLifeCycle.viewWillAppear.subscribe(onNext: {
print("viewWillAppear")
})

_ = lifeCycle.viewDidAppear.subscribe(onNext: {
_ = rxLifeCycle.viewDidAppear.subscribe(onNext: {
print("viewDidAppear")
})

_ = UIApplication.shared.lifeCycle.didEnterBackground.subscribe(onNext: {
_ = UIApplication.shared.rxLifeCycle.didEnterBackground.subscribe(onNext: {
print("didEnterBackground")
})

Expand All @@ -31,5 +58,53 @@ class ViewController: UIViewController {
print("willEnterForeground")
})
}

// MARK: - Action

@objc func presentSomething() {
let childVC = ChildController()
childVC.view.backgroundColor = .white

_ = childVC.rxLifeCycle.viewWillAppear.subscribe(onNext: {
print("childVC viewWillAppear")
})

_ = childVC.rxLifeCycle.viewDidAppear.subscribe(onNext: {
print("childVC viewDidAppear")
})

_ = childVC.rxLifeCycle.viewWillDisappear.subscribe(onNext: {
print("childVC viewWillDisappear")
})

_ = childVC.rxLifeCycle.viewDidDisappear.subscribe(onNext: {
print("childVC viewDidDisappear")
})

present(childVC, animated: true, completion: nil)
}

@objc func pushSomething() {
let childVC = ChildController()
childVC.view.backgroundColor = .white

_ = childVC.rxLifeCycle.viewWillAppear.subscribe(onNext: {
print("childVC viewWillAppear")
})

_ = childVC.rxLifeCycle.viewDidAppear.subscribe(onNext: {
print("childVC viewDidAppear")
})

_ = childVC.rxLifeCycle.viewWillDisappear.subscribe(onNext: {
print("childVC viewWillDisappear")
})

_ = childVC.rxLifeCycle.viewDidDisappear.subscribe(onNext: {
print("childVC viewDidDisappear")
})

navigationController?.pushViewController(childVC, animated: true)
}
}

0 comments on commit b6a1f0d

Please sign in to comment.