All Projects → Jinxiansen → RxExamples

Jinxiansen / RxExamples

Licence: MIT license
RxSwift Examples.

Programming Languages

swift
15916 projects
ruby
36898 projects - #4 most used programming language
shell
77523 projects

Projects that are alternatives of or similar to RxExamples

Rxswift Tutorial
RxSwift 学习资料(学习教程、开源项目)
Stars: ✭ 236 (+391.67%)
Mutual labels:  rxswift
RxScreenProtectKit
Protect the screen from recording 🔐
Stars: ✭ 17 (-64.58%)
Mutual labels:  rxswift
RxSwift-Xcode-Templates
A handful of Xcode file templates for projects that use RXSwift and MVVM
Stars: ✭ 77 (+60.42%)
Mutual labels:  rxswift
Gitiny
An iOS app for GitHub with exploring trending
Stars: ✭ 247 (+414.58%)
Mutual labels:  rxswift
Cyanic
Declarative, state-driven UI framework
Stars: ✭ 32 (-33.33%)
Mutual labels:  rxswift
Swift-Viper-Weather-App
iOS app with Clean Architecture
Stars: ✭ 20 (-58.33%)
Mutual labels:  rxswift
Lockwise Ios
Firefox's Lockwise app for iOS
Stars: ✭ 224 (+366.67%)
Mutual labels:  rxswift
ReactiveAPI
Write clean, concise and declarative network code relying on URLSession, with the power of RxSwift. Inspired by Retrofit.
Stars: ✭ 79 (+64.58%)
Mutual labels:  rxswift
minimalist
Observable Property and Signal for building data-driven UI without Rx
Stars: ✭ 88 (+83.33%)
Mutual labels:  rxswift
KDInstagram
Instagram Clone built in Swift. Utilize three design patterns in three major modules.
Stars: ✭ 119 (+147.92%)
Mutual labels:  rxswift
Passcode
🔑 Passcode for iOS Rxswift, ReactorKit and IGListKit example
Stars: ✭ 254 (+429.17%)
Mutual labels:  rxswift
RxSwift-VIPER-iOS
RxSwiftVIPER is an sample iOS App written in RxSwift using the VIPER architecture. Also RxSwiftVIPER is not a strict VIPER architecture.
Stars: ✭ 47 (-2.08%)
Mutual labels:  rxswift
RxSwift-MVVM-iOS
SwiftMVVM is an sample iOS App written in Swift using the MVVM architecture.
Stars: ✭ 96 (+100%)
Mutual labels:  rxswift
Rxdatasources
UITableView and UICollectionView Data Sources for RxSwift (sections, animated updates, editing ...)
Stars: ✭ 2,784 (+5700%)
Mutual labels:  rxswift
HikingClub iOS
매시업산악회11기 iOS팀 열정! 열정! 열정!🔥🔥
Stars: ✭ 12 (-75%)
Mutual labels:  rxswift
Rxpermission
RxSwift bindings for Permissions API in iOS.
Stars: ✭ 234 (+387.5%)
Mutual labels:  rxswift
iOS Started Kit
iOS Started Kit: Clean Architecture + RxSwift + Moya
Stars: ✭ 12 (-75%)
Mutual labels:  rxswift
awesome-demo-app
100% programmatically written in Swift. Clearly demonstrating the RxSwift, RxCocoa, RxRealm & SnapKit.
Stars: ✭ 16 (-66.67%)
Mutual labels:  rxswift
swift-tensorflow
Dockerized Swift for TensorFlow and advanced usage examples.
Stars: ✭ 14 (-70.83%)
Mutual labels:  rxswift
mvvm-ios
A sample app to demonstrate MVVM implementation in iOS
Stars: ✭ 26 (-45.83%)
Mutual labels:  rxswift

内容

  • 简单转场动画;
  • 简单的注册登录绑定;
  • 网络数据请求、分页、刷新绑定。

Screenshot

Example

Controller 的实现:

class JobController: BaseTableController {

    let viewModel = JobViewModel()
    
    override func viewDidLoad() {
        super.viewDidLoad()

        title = "Job"

        tableView.registerCell(nib: JobCell.self)
        tableView.rowHeight = UITableView.automaticDimension
        tableView.estimatedRowHeight = 150

        bindViewModel()
    }

    func bindViewModel() {

        viewModel.loading.asObservable().bind(to: isLoading).disposed(by: rx.disposeBag)
        viewModel.headerLoading.asObservable().bind(to: isHeaderLoading).disposed(by: rx.disposeBag)
        viewModel.footerLoading.asObservable().bind(to: isFooterLoading).disposed(by: rx.disposeBag)
        viewModel.parseError.map{ $0.message ?? "No Data" }.bind(to: emptyDataSetDescription).disposed(by: rx.disposeBag)

        let input = JobViewModel.Input(headerRefresh: headerRefreshTrigger, footerRefresh: footerRefreshTrigger)

        let output = viewModel.transform(input: input)

        emptyDataSetButtonTap.subscribe(onNext: { () in
            self.headerRefreshTrigger.onNext(())
        }).disposed(by: rx.disposeBag)

        output.items.bind(to: tableView.rx.items(cellIdentifier: JobCell.nameOfClass,
                                                 cellType: JobCell.self)) { (_, element, cell) in
                                                    cell.item = element
            }.disposed(by: rx.disposeBag)

        tableView.rx.modelSelected(JobItem.self).subscribe(onNext: { item in
            SVProgressHUD.showInfo(withStatus: item.publisher ?? "")
        }).disposed(by: rx.disposeBag)

        // load data
        tableView.headRefreshControl.beginRefreshing()
    }
}

ViewModel 的实现:

class JobViewModel: BaseViewModel {
    
}

extension JobViewModel: ViewModelType {
    
    struct Input {
        let headerRefresh: Observable<Void>
        let footerRefresh: Observable<Void>
    }
    
    struct Output {
        let items = BehaviorRelay<[JobItem]>(value: [])
    }
    
    func transform(input: JobViewModel.Input) -> JobViewModel.Output {
        let output = Output()
        
        input.headerRefresh.flatMapLatest { [weak self] _ -> Observable<[JobItem]> in
            guard let self = self else { return Observable.just([]) }
            self.page = 1
            return self.requestJobs()
                .trackActivity(self.headerLoading)
                .catchErrorJustComplete()
        }.bind(to: output.items).disposed(by: rx.disposeBag)
        
        input.footerRefresh.flatMapLatest { [weak self] _ -> Observable<[JobItem]> in
            guard let self = self else { return Observable.just([]) }
            self.page += 1
            return self.requestJobs().trackActivity(self.footerLoading)
        }.subscribe(onNext: { items in
            output.items.accept(output.items.value + items)
        }).disposed(by: rx.disposeBag)
        
        return output
    }
}


extension JobViewModel {
    
    func requestJobs() -> Observable<[JobItem]> {
        return jobProvider.requestData(.jobs(page: page))
            .delay(1, scheduler: MainScheduler.instance) // 延迟1秒
            .mapObjects(JobItem.self)
            .trackError(error)
            .trackActivity(loading)
    }
    
}

大致用到了以下框架:

  pod 'Moya/RxSwift'
  pod 'RxSwift'
  pod 'RxCocoa'
  pod 'NSObject+Rx' # 
  pod 'RxDataSources'  # https://github.com/RxSwiftCommunity/RxDataSources
  pod 'Moya-ObjectMapper' # https://github.com/bmoliveira/Moya-ObjectMapper
  pod 'Validator', git: 'https://github.com/adamwaite/Validator.git' # 表单验证
  pod 'Hero'  # https://github.com/HeroTransitions/Hero
  pod 'DZNEmptyDataSet', '~> 1.8.1'  # 空态 https://github.com/dzenbot/DZNEmptyDataSet
  pod 'KafkaRefresh', '~> 1.4.7' # 刷新 https://github.com/OpenFeyn/KafkaRefresh
  pod 'ViewAnimator', '~> 2.5.1' # 动画库 https://github.com/marcosgriselli/ViewAnimator
  pod 'SwifterSwift', '~> 5.0.0' # 类似 YYKit https://github.com/SwifterSwift/SwifterSwift

About

晋先森:[email protected]

License

MIT license

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].