Skip to content

Commit

Permalink
Release 1.0.0
Browse files Browse the repository at this point in the history
  • Loading branch information
changsanjiang committed Apr 11, 2020
1 parent 465b0b6 commit ea0df1a
Show file tree
Hide file tree
Showing 25 changed files with 576 additions and 319 deletions.
3 changes: 2 additions & 1 deletion Example/Podfile
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
source 'https://cdn.cocoapods.org/'

target 'SJRouter_Example' do
pod 'SJRouter', :path => '../'
pod 'ModuleA', :path => '../ModuleA'
pod 'ModuleB', :path => '../ModuleB'
pod 'ModuleB', :path => '../ModuleB'
end
12 changes: 6 additions & 6 deletions Example/Podfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@ PODS:
- SJRouter
- ModuleB (0.1.0):
- SJRouter
- SJRouter (0.0.12):
- SJRouter/Core (= 0.0.12)
- SJRouter/Core (0.0.12)
- SJRouter (0.0.17):
- SJRouter/Core (= 0.0.17)
- SJRouter/Core (0.0.17)

DEPENDENCIES:
- ModuleA (from `../ModuleA`)
Expand All @@ -23,8 +23,8 @@ EXTERNAL SOURCES:
SPEC CHECKSUMS:
ModuleA: 45d7ec62f61a891a7691b29228233da19fa4dd69
ModuleB: 7d0e51b2b77dbcb06f8b6639b2c9d6c78ec7bc04
SJRouter: 702a0d06811fc2da02d6145bc7abb9f633fdc612
SJRouter: b822f45c4eed29cfa1d75100492ff227d481fb91

PODFILE CHECKSUM: 594842781561fbe273ee1f61ee0ae87a0b23f4da
PODFILE CHECKSUM: 6b3ad68d040e9d61356ad9b564002fae5ad3a150

COCOAPODS: 1.8.4
COCOAPODS: 1.9.1
1 change: 1 addition & 0 deletions Example/Pods/Headers/Private/SJRouter/SJRouteInterceptor.h

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions Example/Pods/Headers/Public/SJRouter/SJRouteInterceptor.h

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions Example/Pods/Local Podspecs/SJRouter.podspec.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

12 changes: 6 additions & 6 deletions Example/Pods/Manifest.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

491 changes: 253 additions & 238 deletions Example/Pods/Pods.xcodeproj/project.pbxproj

Large diffs are not rendered by default.

10 changes: 10 additions & 0 deletions Example/Pods/Target Support Files/ModuleA/ModuleA.debug.xcconfig

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

10 changes: 10 additions & 0 deletions Example/Pods/Target Support Files/ModuleA/ModuleA.release.xcconfig

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

10 changes: 10 additions & 0 deletions Example/Pods/Target Support Files/ModuleB/ModuleB.debug.xcconfig

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

10 changes: 10 additions & 0 deletions Example/Pods/Target Support Files/ModuleB/ModuleB.release.xcconfig

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

10 changes: 10 additions & 0 deletions Example/Pods/Target Support Files/SJRouter/SJRouter.debug.xcconfig

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

12 changes: 6 additions & 6 deletions ModuleA/ModuleA/Classes/MAModule.m
Original file line number Diff line number Diff line change
Expand Up @@ -12,24 +12,24 @@


///
/// 此模块为老版添加的方式, 新方式请查看 ModuleB
/// 此模块为第一种添加方式, 第二种方式请查看 ModuleB
///
/// 此模块为老版添加的方式, 新方式请查看 ModuleB
/// 此模块为第一种添加方式, 第二种方式请查看 ModuleB
///
/// 此模块为老版添加的方式, 新方式请查看 ModuleB
/// 此模块为第一种添加方式, 第二种方式请查看 ModuleB
///
@interface MAModule()<SJRouteHandler>

@end

@implementation MAModule
/// 此模块为老版添加的方式, 新方式请查看 ModuleB
/// 此模块为第一种添加方式, 第二种方式请查看 ModuleB
+ (NSArray<NSString *> *)multiRoutePath {
return @[@"MAModule/A1",
@"MAModule/A2"];
}

/// 此模块为老版添加的方式, 新方式请查看 ModuleB
/// 此模块为第一种添加方式, 第二种方式请查看 ModuleB
+ (void)instanceWithRequest:(SJRouteRequest *)request completionHandler:(SJCompletionHandler)completionHandler {
if ( [request.requestPath isEqualToString:@"MAModule/A1"] ) {
MAViewController *vc = [[MAViewController alloc] init];
Expand All @@ -41,7 +41,7 @@ + (void)instanceWithRequest:(SJRouteRequest *)request completionHandler:(SJCompl
}
}

/// 此模块为老版添加的方式, 新方式请查看 ModuleB
/// 此模块为第一种添加方式, 第二种方式请查看 ModuleB
+ (void)handleRequest:(SJRouteRequest *)request topViewController:(UIViewController *)topViewController completionHandler:(SJCompletionHandler)completionHandler {
[self instanceWithRequest:request completionHandler:^(id _Nullable result, NSError * _Nullable error) {
if ( error != nil ) {
Expand Down
28 changes: 27 additions & 1 deletion ModuleB/ModuleB/Classes/MBModule.m
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ @implementation MBModule
+ (void)addRoutesToRouter:(SJRouter *)router {
[router addRoute:[SJRouteObject.alloc initWithPath:@"MBModule/B1" transitionMode:SJViewControllerTransitionModeNavigation createInstanceBlock:^(SJRouteRequest * _Nonnull request, SJCompletionHandler _Nullable completionHandler) {
#ifdef DEBUG
NSLog(@"%@", request.prts); // 打印请求的参数
NSLog(@"%d - -[%@ %s], 请求参数: %@", (int)__LINE__, NSStringFromClass([self class]), sel_getName(_cmd), request.prts);
#endif
MBViewController *vc = [[MBViewController alloc] init];
if ( completionHandler != nil ) completionHandler(vc, nil);
Expand All @@ -35,5 +35,31 @@ + (void)addRoutesToRouter:(SJRouter *)router {
MB2ViewController *vc = [[MB2ViewController alloc] init];
if ( completionHandler != nil ) completionHandler(vc, nil);
}]];

/// 添加拦截器
///
/// 拦截向"video/list"的请求. 决定是否可以处理路由
///
/// 什么场景下适合添加拦截器?
/// 比如跳转B界面需要用户登录, 否则需要跳转至登录界面. 因此从任何地方跳转B界面, 都需要能够及时拦截到, 增加对用户登录态的判断来决定是否允许跳转B界面
///
[router addInterceptor:[SJRouteInterceptor interceptorWithPath:@"MBModule/B2" handler:^(SJRouteRequest * _Nonnull request, SJRouterInterceptionPolicyDecisionHandler _Nonnull decisionHandler) {
// // 对登录态的判断
// if ( !User.isLogin ) {
// decisionHandler(SJRouterInterceptionPolicyCancel);
// // 跳转登录页面
// SJRouteRequest *newRequest = [SJRouteRequest.alloc initWithPath:@"user/login" parameters:nil];
// [SJRouter.shared handleRequest:newRequest completionHandler:nil];
// return;
// }

// 也可以添加一些自己需要的参数
// [request setValue:@"sjsjsjs" forParameterKey:@"keykeykey"];

// - 否则返回允许执行路由
decisionHandler(SJRouterInterceptionPolicyAllow);
}]];
}

@end

7 changes: 2 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,12 +24,9 @@ pod 'SJRouter'

## Author

SanJiang, [email protected]
Email: [email protected]

## Contact

* Email: [email protected]
* QQGroup: 719616775 <img src="https://github.com/changsanjiang/SJVideoPlayer/blob/master/SJVideoPlayerProject/SJVideoPlayerProject/Group.jpeg" width="100" />
QQGroup: 930508201 (iOS 开发)

## License

Expand Down
2 changes: 1 addition & 1 deletion SJRouter.podspec
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

Pod::Spec.new do |s|
s.name = 'SJRouter'
s.version = '0.0.17'
s.version = '1.0.0'
s.summary = 'SJRouter.'

# This description is used to generate tags and improve search results.
Expand Down
31 changes: 28 additions & 3 deletions SJRouter/Core/SJRouteHandler.h
Original file line number Diff line number Diff line change
Expand Up @@ -40,28 +40,53 @@ typedef void(^SJRouterUnableToGetAnInstanceCallback)(SJRouteRequest *request, SJ
/// MyViewController2 *vc = [[MyViewController2 alloc] init];
/// if ( completionHandler != nil ) completionHandler(vc, nil);
/// }]];
///
/// /// 添加拦截器
/// ///
/// /// 拦截向"video/list"的请求. 决定是否可以处理路由
/// ///
/// /// 什么场景下适合添加拦截器?
/// /// 比如跳转B界面需要用户登录, 否则需要跳转至登录界面. 因此从任何地方跳转B界面, 都需要能够及时拦截到, 增加对用户登录态的判断来决定是否允许跳转B界面
/// ///
/// [router addInterceptor:[SJRouteInterceptor interceptorWithPath:@"video/list" handler:^(SJRouteRequest * _Nonnull request, SJRouterInterceptionPolicyDecisionHandler _Nonnull decisionHandler) {
/// // - 对登录态的判断
/// if ( !User.isLogin ) {
/// // 取消此次路由
/// decisionHandler(SJRouterInterceptionPolicyCancel);
/// // 跳转登录页面
/// SJRouteRequest *newRequest = [SJRouteRequest.alloc initWithPath:@"user/login" parameters:nil];
/// [SJRouter.shared handleRequest:newRequest completionHandler:nil];
/// return;
/// }
///
/// // - 也可以添加一些自己需要的参数
/// [request setValue:@"sjsjsjs" forParameterKey:@"keykeykey"];
///
/// // - 允许此次路由
/// decisionHandler(SJRouterInterceptionPolicyAllow);
/// }]];
/// }
/// @end
///\endcode
///
+ (void)addRoutesToRouter:(SJRouter *)router;

#pragma mark - 为兼容老版本保留以下这些接口
#pragma mark - 以下为第二种添加路由的方式

+ (NSArray<NSString *> *)multiRoutePath; // 多路径 可以从这个方法返回
+ (NSString *)routePath; // 单路径 可以用这个方法返回

///
/// 处理某个请求
///
/// 当调用SJRouter的`-handleRequest:completionHandler:`时, SJRouter将获取到对应的`handler`, 调用到此方法
/// 当调用SJRouter的`-handleRequest:completionHandler:`时, SJRouter将通过对应的`handler`调用到此方法
///
+ (void)handleRequest:(SJRouteRequest *)request topViewController:(UIViewController *)topViewController completionHandler:(nullable SJCompletionHandler)completionHandler;

///
/// 获取某个实例
///
/// 当调用SJRouter的`-instanceWithRequest:completionHandler:`时, SJRouter将获取对应的`handler`, 调用到此方法
/// 当调用SJRouter的`-instanceWithRequest:completionHandler:`时, SJRouter将通过对应的`handler`调用到此方法
///
+ (void)instanceWithRequest:(SJRouteRequest *)request completionHandler:(nullable SJCompletionHandler)completionHandler;
@end
Expand Down
32 changes: 32 additions & 0 deletions SJRouter/Core/SJRouteInterceptor.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
//
// SJRouteInterceptor.h
// Pods
//
// Created by 畅三江 on 2020/4/11.
//

#import <Foundation/Foundation.h>
#import "SJRouteHandler.h"

typedef enum : NSUInteger {
SJRouterInterceptionPolicyCancel,
SJRouterInterceptionPolicyAllow,
} SJRouterInterceptionPolicy;

NS_ASSUME_NONNULL_BEGIN
typedef void(^SJRouterInterceptionPolicyDecisionHandler)(SJRouterInterceptionPolicy policy);
typedef void(^SJRouteInterceptHandler)(SJRouteRequest *request, SJRouterInterceptionPolicyDecisionHandler decisionHandler);


@interface SJRouteInterceptor : NSObject
+ (instancetype)interceptorWithPaths:(NSArray<NSString *> *)paths handler:(SJRouteInterceptHandler)handler;
- (instancetype)initWithPaths:(NSArray<NSString *> *)paths handler:(SJRouteInterceptHandler)handler;

+ (instancetype)interceptorWithPath:(NSString *)path handler:(SJRouteInterceptHandler)handler;
- (instancetype)initWithPath:(NSString *)path handler:(SJRouteInterceptHandler)handler;

@property (nonatomic, copy, nullable) NSArray<NSString *> *paths;
@property (nonatomic, copy, nullable) SJRouteInterceptHandler handler;

@end
NS_ASSUME_NONNULL_END
29 changes: 29 additions & 0 deletions SJRouter/Core/SJRouteInterceptor.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
//
// SJRouteInterceptor.m
// Pods
//
// Created by 畅三江 on 2020/4/11.
//

#import "SJRouteInterceptor.h"

@implementation SJRouteInterceptor
+ (instancetype)interceptorWithPaths:(NSArray<NSString *> *)paths handler:(SJRouteInterceptHandler)handler {
return [SJRouteInterceptor.alloc initWithPaths:paths handler:handler];
}
- (instancetype)initWithPaths:(NSArray<NSString *> *)paths handler:(SJRouteInterceptHandler)handler {
self = [super init];
if ( self ) {
_paths = paths;
_handler = handler;
}
return self;
}

+ (instancetype)interceptorWithPath:(NSString *)path handler:(SJRouteInterceptHandler)handler {
return [SJRouteInterceptor.alloc initWithPath:path handler:handler];
}
- (instancetype)initWithPath:(NSString *)path handler:(SJRouteInterceptHandler)handler {
return [self initWithPaths:@[path ?: @""] handler:handler];
}
@end
2 changes: 2 additions & 0 deletions SJRouter/Core/SJRouteObject.m
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,8 @@ - (nullable instancetype)initWithPaths:(NSArray<NSString *> *)paths transitionMo
return self;
}

#pragma mark -

- (void)handleRequest:(SJRouteRequest *)request topViewController:(UIViewController *)topViewController completionHandler:(nullable SJCompletionHandler)completionHandler {
if ( self.createInstanceBlock != nil ) {
self.createInstanceBlock(request, ^(id _Nullable result, NSError * _Nullable error) {
Expand Down
2 changes: 1 addition & 1 deletion SJRouter/Core/SJRouteRequest.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ typedef id SJParameters;

NS_ASSUME_NONNULL_BEGIN
@interface SJRouteRequest : NSObject
- (instancetype)initWithPath:(NSString *)requestPath parameters:(nullable SJParameters)parameters;
- (nullable instancetype)initWithPath:(NSString *)requestPath parameters:(nullable SJParameters)parameters;
@property (nonatomic, strong, readonly, nullable) NSString *requestPath;
@property (nonatomic, strong, readonly, nullable) SJParameters prts; // 请求的参数
- (instancetype)init NS_UNAVAILABLE;
Expand Down
Loading

0 comments on commit ea0df1a

Please sign in to comment.