An elegent router kit for iOS.
Clone or download
EyreFree
EyreFree 0.2.8
Latest commit 1d69584 Jan 11, 2018
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
.github Add .github Jan 11, 2018
Example Update Pod May 26, 2017
LPDMvvmRouterKit fix: fix number type bug Jan 11, 2018
.gitignore Initial commit Mar 19, 2017
.travis.yml Give up WTF-CI May 11, 2017
LICENSE Initial commit Mar 19, 2017
LPDMvvmRouterKit.podspec 0.2.8 Jan 11, 2018
README.md Update README.md Jan 11, 2018
README_CN.md Update README.md Jan 11, 2018
_Pods.xcodeproj Initial commit Mar 19, 2017

README.md

LPDMvvmRouterKit

codebeat badge codebeat badge

LPDMvvmRouterKit is written in a Objectivec-C, available under the MVVM framework.

  • app external page transition
  • app internal page transition
  • message bus

Chinese Introduction

Example

  1. Use the git clone command to download the repository, the Examples directory contains all the sample programs;
  2. Use XCode to open the corresponding project, run the example project.

Or execute the following command:

git clone git@github.com:LPD-iOS/LPDMvvmRouterKit.git; 

cd LPDMvvmRouterKit/Examples; 

open 'LPDMvvmRouterKit.xcworkspace'

Requirements

  • XCode 7.0+
  • Swift 2.0+
  • iOS 8.0+ / macOS 10.11+ / tvOS 8.0+

Installation

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

pod "LPDMvvmRouterKit"

Then, execute the following command:

$ pod install

Quick to use

1. Import LPDMvvmRouterKit

Add the following code to the LPDMvvmRouterKit module where you need to use LPDMvvmRouterKit:

#import <LPDMvvmKit/LPDMvvmKit.h>
#import <LPDMvvmRouterKit/LPDMvvmRouterKit.h>
#import <LPDAdditionsKit/LPDAdditionsKit.h>

And let the viewController inherit from the LPDViewController.

2. Create viewModel

Create a viewModel. Add the following header file to the code in viewModel:

#import <LPDMvvmKit/LPDMvvmKit.h>
#import <LPDMvvmRouterKit/LPDMvvmRouterKit.h>

3. App external page transition

External through the incoming URL, if the rules, you can transition to the corresponding page within the app.

  NSURL *url = [NSURL URLWithString:@"me.ele.lpd://lpd/some/push?title=Some&x=11111.11&count=3&str=fwljfwljfwl"];
  [[LPDMvvmRouter sharedInstance] openURL:url options:nil];

4. App internal page transition

In the MVVM framework, we only allow viewModel transition, so the page transition would only pushViewModel and presentViewModel two ways.

pushViewModel:

  [[LPDMvvmRouter sharedInstance] performActionWithUrl:[LPDRouteURL routerURLWithString:@"lpd://some/push?title=Some&x=11111.11&count=3&str=fwljfwljfwl"] completion:^(id  _Nullable x) {

  }];

popViewModel:

  [self.viewModel performSelector:@selector(popViewModel)];

popToRootViewModel:

  [self.viewModel performSelector:@selector(popToRootViewModel)];

presentViewModel:

  [[LPDMvvmRouter sharedInstance] performActionWithUrl:[LPDRouteURL routerURLWithString:@"lpd://some/present?title=PresentSome&x=11111.11&count=3&str=fwljfwljfwl"] completion:^(id  _Nullable x) {
    
  }];

dismissViewModel:

  [self.viewModel performSelector:@selector(dismissViewModel)];

5. Router message bus

In the LPDMvvmRouterKit library there is a LPDEvent class, this class is used to do the message bus.

  LPDEvent *event = [LPDEvent eventWithEventSelector:@"test:"];
  [[LPDModuleMediator sharedInstance] sendEvent:event];

In the corresponding viewModel to implement the corresponding test: method, you can get in the method to receive this notification information. The arguments following the method must be the type of id <LPDEventProtocol>.

Guidebook

1. App external page transition

  NSURL *url = [NSURL URLWithString:@"me.ele.lpd://lpd/some/push?title=Some&x=11111.11&count=3&str=fwljfwljfwl"];
  [[LPDMvvmRouter sharedInstance] openURL:url options:nil];

By passing a URL string, you can transition from outside APP to the corresponding page inside the APP.

URL string rules:

App scheme://modular scheme/viewModelName/push(present)?

The route will first verify the App scheme can be paired, if it can, and then verify the modular scheme can match, if you can find the corresponding viewModel, push or present.

Parameter Description

ViewModelName this is the viewModel remove the prefix LPD, remove the suffix viewModel the remaining name. Such as a viewModel called LPDSomeViewModel, then here viewModelName is some.

the type of options is NSDictionary<UIApplicationOpenURLOptionsKey,id>

2. App internal page transition

App internal routing transition URL does not need to increase the App scheme prefix, and directly from the modular scheme, followed by the rules and the above said the same.

In the page inside the app page jump, all the page transition is achieved through the navigationViewModel. The specific implementation will get the top of the top top of the topNavigationController viewModel, and then call the corresponding page transition method to achieve the internal routing page page transition.

There are six ways to support the transition:

push
pop
popto
poptoroot
present
dismiss
  • pushViewModel:
  [[LPDMvvmRouter sharedInstance] performActionWithUrl:[LPDRouteURL routerURLWithString:@"lpd://some/push?title=Some&x=11111.11&count=3&str=fwljfwljfwl"] completion:^(id  _Nullable x) {

  }];
  • popViewModel:
  [self.viewModel performSelector:@selector(popViewModel)];

If it is popViewModel, the implementation of the principle is in the viewModel call their own navigation popViewModelAnimated operation.

  [self.navigation popViewModelAnimated:YES];
  • popToRootViewModel:
  [self.viewModel performSelector:@selector(popToRootViewModel)];

If it is popToRootViewModel, the implementation of the principle is in the viewModel call their own navigation for pop operation.

  [self.navigation popToRootViewModelAnimated:YES];

PopToRootViewModel will traverse the entire ViewModel stack and find rootViewModel for pop.

  • presentViewModel:
  [[LPDMvvmRouter sharedInstance] performActionWithUrl:[LPDRouteURL routerURLWithString:@"lpd://some/present?title=PresentSome&x=11111.11&count=3&str=fwljfwljfwl"] completion:^(id  _Nullable x) {
    
  }];

Present and push the same principle, do not repeat here.

  • dismissViewModel:
  [self.viewModel performSelector:@selector(dismissViewModel)];

If it is a dismissViewModel, the implementation principle is to call your navigation in the viewModel for the dismissNavigationViewModelAnimated operation.

  [self.navigation dismissNavigationViewModelAnimated:YES completion:nil;

3. Router message bus

LPDEvent was designed to replace the message within the app notice, specifically used to do the message bus. Not used to callback, nor is it used to do the function call.

If a module does not care about an event, then it does not need to implement the corresponding method.

In order to receive a message from the message bus, then in the implementation of the method, you need to receive a (id ) event parameters. This event contains all the parameters of the message over the dictionary, method name, and methods are synchronized and asynchronous method of information.

Parameter Description

EventSelector: The string corresponding to the event method. EventArgs: event passed by the parameter dictionary. Async: This is a BOOL type that identifies whether the method of the event is synchronous or asynchronous.

Remarks

If you have any questions, expect your feedback.

Note: if easy to use, please give me a star.

Author

foxsofter, foxsofter@gmail.com

License

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