All Projects → onmyway133 → Rxlifecycle

onmyway133 / Rxlifecycle

Licence: other
🐹 Easy life cycle observation

Programming Languages

swift
15916 projects

Projects that are alternatives of or similar to Rxlifecycle

Datasources
💾 🔜📱 Type-safe data-driven CollectionView, TableView Framework. (We can also use ASCollectionNode)
Stars: ✭ 553 (+1102.17%)
Mutual labels:  rxswift, viewcontroller
Readhubclient
Readhub客户端
Stars: ✭ 44 (-4.35%)
Mutual labels:  lifecycle
Simple Sh Datascience
A collection of Bash scripts and Dockerfiles to install data science Tool, Lib and application
Stars: ✭ 32 (-30.43%)
Mutual labels:  application
Fluxxkit
Unidirectional data flow for reactive programming in iOS.
Stars: ✭ 42 (-8.7%)
Mutual labels:  rxswift
Smartisandialog
Smartisan style Dialog.
Stars: ✭ 33 (-28.26%)
Mutual labels:  application
Rxnetwork
A swift network library based on Moya/RxSwift.
Stars: ✭ 43 (-6.52%)
Mutual labels:  rxswift
Evreflection
Reflection based (Dictionary, CKRecord, NSManagedObject, Realm, JSON and XML) object mapping with extensions for Alamofire and Moya with RxSwift or ReactiveSwift
Stars: ✭ 954 (+1973.91%)
Mutual labels:  rxswift
Fogga Kanban
🎽 React Kanban Dashboard Template
Stars: ✭ 46 (+0%)
Mutual labels:  application
Learn Solidity
Code base for "Learn Solidity: Programming Language for Ethereum Smart Contracts" course in Tosh Academy & Blockchain Council
Stars: ✭ 44 (-4.35%)
Mutual labels:  application
Rxrealm
RxSwift extension for RealmSwift's types
Stars: ✭ 1,007 (+2089.13%)
Mutual labels:  rxswift
Wanandroid
Jetpack MVVM For Wanandroid 最佳实践 !
Stars: ✭ 1,004 (+2082.61%)
Mutual labels:  lifecycle
Rxswift Tutorials
Reactive Programming with Swift
Stars: ✭ 36 (-21.74%)
Mutual labels:  rxswift
Formant Analyzer
iOS application for finding formants in spoken sounds
Stars: ✭ 43 (-6.52%)
Mutual labels:  application
Erl Env
Make retrieving configuration parameters super fast(7x faster than application:get_env)and stable.
Stars: ✭ 32 (-30.43%)
Mutual labels:  application
Papr
🌁 An Unsplash app for iOS
Stars: ✭ 1,025 (+2128.26%)
Mutual labels:  rxswift
Linkedinsignin
Simple view controller to log in and retrieve an access token from LinkedIn.
Stars: ✭ 31 (-32.61%)
Mutual labels:  viewcontroller
Todo app open source
📱 an app to annotate tasks made with Flutter using MobX
Stars: ✭ 40 (-13.04%)
Mutual labels:  application
Vhdattach
A small tool that allows for easy virtual disk attach/detach and auto-mount.
Stars: ✭ 42 (-8.7%)
Mutual labels:  application
Latexcv
👔 A collection of cv and resume templates written in LaTeX. Leave an issue if your language is not supported!
Stars: ✭ 1,027 (+2132.61%)
Mutual labels:  application
Mvvmc Splitviewcontroller
Example project with UITabBarController inside UISplitViewController using RxSwift and MVVM-C architecture.
Stars: ✭ 45 (-2.17%)
Mutual labels:  rxswift

RxLifeCycle

❤️ Support my apps ❤️

❤️❤️😇😍🤘❤️❤️

Version Carthage Compatible License Platform Swift

Description

If you're using MVVM with FRP, then chances are that you need to rely on UIViewController or UIApplication life cycle events to trigger signals. We can either do it by calling a method on the ViewModel, like kickstarter-ios

override func viewWillAppear(_ animated: Bool) {
  super.viewWillAppear(animated)
  self.viewModel.inputs.viewWillAppear()
}

or reactively using signal binding.

override func viewDidLoad() {
  super.viewDidLoad()
  rx.viewWillAppear.bind(to: viewModel.input.fetchData).disposed(by: disposeBag)
}

One way to make observations for the life cycle is to use sentMessage and methodInvoked which involve a lot of swizzlings 😱 We shouldn't use swizzlings, it is just asking for problem.

public extension Reactive where Base: UIViewController {
  public var viewWillAppear: ControlEvent<()> {
    let source = self.methodInvoked(#selector(Base.viewWillAppear)).mapVoid()
    return ControlEvent(events: source)
  }
}

Instead, we can just use simple composition, that you can plug and play everywhere you want. See demo

Features

  • ViewControllerLifeCycle for events related to UIViewController
  • AppLifeCycle for events related to UIApplication, equivalent to UIApplicationDelegate
  • Auto clean up upon deinit
  • Support iOS, tvOS

Usage

ViewControllerLifeCycle

This works by embed a child view controller so that it can forward appearance method

After adding a child to a container, the container automatically forwards appearance-related messages to the child

All you need to do is to declare ViewControllerLifeCycle object and observe on it. Remember to keep this ViewControllerLifeCycle so it is not released !!

let viewController = LoginViewController()
let lifeCycle = ViewControllerLifeCycle(viewController: viewController)

_ = lifeCycle.viewWillAppear.subscribe(onNext: {
  print("viewWillAppear has been called")
})

For convenience, you can also use it directly by using rxLifeCycle

let viewController = LoginViewController()

_ = viewController.rxLifeCycle.viewDidAppear.subscribe(onNext: {
  print("viewDidAppear has been called")
})

Supported observables

  • viewWillAppear
  • viewDidAppear
  • viewWillDisappear
  • viewDidDisappear

AppLifeCycle

There are times we need to refresh data when user go back to the app again, which is the UIApplicationWillEnterForeground event. All you need to do is to declare AppLifeCycle and observe on it. Under the hood, it listens to UIApplication notifications and publish the signals.

Remember to keep this AppLifeCycle so it is not released !!

let lifeCycle = AppLifeCycle()
_ = lifeCycle.didBecomeActive.subscribe(onNext: {
  print("didBecomeActive was called")
})

For convenience, you can also use it directly by using rxLifeCycle on UIApplication

let lifeCycle = AppLifeCycle()
_ = UIApplication.shared.rxLifeCycle.willEnterForeground.subscribe(onNext: {
  print("willEnterForeground was called")
})

Supported observables

  • didBecomeActive
  • willResignActive
  • didEnterBackground
  • willEnterForeground

Installation

RxLifeCycle is available through CocoaPods. To install it, simply add the following line to your Podfile:

pod 'RxLifeCycle'

RxLifeCycle is also available through Carthage. To install just write into your Cartfile:

github "onmyway133/RxLifeCycle"

RxLifeCycle can also be installed manually. Just download and drop Sources folders in your project.

Author

Khoa Pham, [email protected]

Contributing

We would love you to contribute to RxLifeCycle, check the CONTRIBUTING file for more info.

License

RxLifeCycle is available under the MIT license. See the LICENSE file for more info.

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].