TestsTested | ✗ |
LangLanguage | Obj-CObjective C |
License | MIT |
ReleasedLast Release | Jan 2018 |
Maintained by qiaomu, halfrost, EyreFree.
LPDMvvmRouterKit is written in a Objectivec-C, available under the MVVM framework.
git clone
command to download the repository, theExamples
directory contains all the sample programs;Or execute the following command:
git clone [email protected]:LPD-iOS/LPDMvvmRouterKit.git;
cd LPDMvvmRouterKit/Examples;
open 'LPDMvvmRouterKit.xcworkspace'
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
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.
Create a viewModel. Add the following header file to the code in viewModel:
#import <LPDMvvmKit/LPDMvvmKit.h>
#import <LPDMvvmRouterKit/LPDMvvmRouterKit.h>
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];
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)];
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>
.
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.
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>
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
[[LPDMvvmRouter sharedInstance] performActionWithUrl:[LPDRouteURL routerURLWithString:@"lpd://some/push?title=Some&x=11111.11&count=3&str=fwljfwljfwl"] completion:^(id _Nullable x) {
}];
[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];
[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.
[[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.
[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;
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.
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.
If you have any questions, expect your feedback.
Note: if easy to use, please give me a `star``
foxsofter, [email protected]
LPDMvvmRouterKit is available under the MIT license. See the LICENSE file for more info.