Skip to content

Commit

Permalink
Add some Chaining grammar (#1499)
Browse files Browse the repository at this point in the history
* Add some Chaining grammar
  • Loading branch information
wolfcon authored Mar 4, 2021
1 parent 7705ff8 commit d48313b
Show file tree
Hide file tree
Showing 13 changed files with 214 additions and 134 deletions.
18 changes: 18 additions & 0 deletions MJRefresh/Base/MJRefreshComponent.h
Original file line number Diff line number Diff line change
Expand Up @@ -113,5 +113,23 @@ typedef void (^MJRefreshComponentAction)(void);
- (CGFloat)mj_textWidth;
@end

@interface MJRefreshComponent (ChainingGrammar)

#pragma mark - <<< 为 Swift 扩展链式语法 >>> -
/// 自动变化透明度
- (instancetype)autoChangeTransparency:(BOOL)isAutoChange;
/// 刷新开始后立即调用的回调
- (instancetype)afterBeginningAction:(MJRefreshComponentAction)action;
/// 刷新动画开始后立即调用的回调
- (instancetype)endingAnimationBeginningAction:(MJRefreshComponentAction)action;
/// 刷新结束后立即调用的回调
- (instancetype)afterEndingAction:(MJRefreshComponentAction)action;


/// 需要子类必须实现
/// @param scrollView 赋值给的 ScrollView 的 Header/Footer/Trailer
- (instancetype)assignTo:(UIScrollView *)scrollView;

@end

NS_ASSUME_NONNULL_END
27 changes: 27 additions & 0 deletions MJRefresh/Base/MJRefreshComponent.m
Original file line number Diff line number Diff line change
Expand Up @@ -275,3 +275,30 @@ - (CGFloat)mj_textWidth {
return stringWidth;
}
@end


#pragma mark - <<< 为 Swift 扩展链式语法 >>> -
@implementation MJRefreshComponent (ChainingGrammar)

- (instancetype)autoChangeTransparency:(BOOL)isAutoChange {
self.automaticallyChangeAlpha = isAutoChange;
return self;
}
- (instancetype)afterBeginningAction:(MJRefreshComponentAction)action {
self.beginRefreshingCompletionBlock = action;
return self;
}
- (instancetype)endingAnimationBeginningAction:(MJRefreshComponentAction)action {
self.endRefreshingAnimationBeginAction = action;
return self;
}
- (instancetype)afterEndingAction:(MJRefreshComponentAction)action {
self.endRefreshingCompletionBlock = action;
return self;
}

- (instancetype)assignTo:(UIScrollView *)scrollView {
return self;
}

@end
7 changes: 7 additions & 0 deletions MJRefresh/Base/MJRefreshFooter.m
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,13 @@ - (void)prepare
// self.automaticallyHidden = NO;
}

#pragma mark . 链式语法部分 .

- (instancetype)assignTo:(UIScrollView *)scrollView {
scrollView.mj_footer = self;
return self;
}

#pragma mark - 公共方法
- (void)endRefreshingWithNoMoreData
{
Expand Down
7 changes: 7 additions & 0 deletions MJRefresh/Base/MJRefreshHeader.m
Original file line number Diff line number Diff line change
Expand Up @@ -242,6 +242,13 @@ - (void)headerRefreshingAction {
}
}

#pragma mark . 链式语法部分 .

- (instancetype)assignTo:(UIScrollView *)scrollView {
scrollView.mj_header = self;
return self;
}

#pragma mark - CAAnimationDelegate
- (void)animationDidStop:(CAAnimation *)anim finished:(BOOL)flag {
NSString *identity = [anim valueForKey:@"identity"];
Expand Down
9 changes: 8 additions & 1 deletion MJRefresh/Base/MJRefreshTrailer.m
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,14 @@ - (void)willMoveToSuperview:(UIView *)newSuperview {
}
}

#pragma mark 刚好看到上拉刷新控件时的contentOffset.x
#pragma mark . 链式语法部分 .

- (instancetype)assignTo:(UIScrollView *)scrollView {
scrollView.mj_trailer = self;
return self;
}

#pragma mark - 刚好看到上拉刷新控件时的contentOffset.x
- (CGFloat)happenOffsetX {
CGFloat deltaW = [self widthForContentBreakView];
if (deltaW > 0) {
Expand Down
30 changes: 24 additions & 6 deletions MJRefreshExample.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

/* Begin PBXBuildFile section */
01A2CE0C21ACE01500BEE365 /* MJRefreshConfig.m in Sources */ = {isa = PBXBuildFile; fileRef = 01A2CE0B21ACE01500BEE365 /* MJRefreshConfig.m */; };
01EB8272236846CE00813DAA /* MJWKWebViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = 01EB8271236846CE00813DAA /* MJWKWebViewController.m */; };
01A5EB2B25EF62B80091554E /* MJWKWebViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 01A5EB2A25EF62B80091554E /* MJWKWebViewController.swift */; };
2D4698861D0EE6A400CB8025 /* NSBundle+MJRefresh.m in Sources */ = {isa = PBXBuildFile; fileRef = 2D4698851D0EE6A400CB8025 /* NSBundle+MJRefresh.m */; };
2D9BEB091BB15F4A00AED473 /* UIViewController+Example.m in Sources */ = {isa = PBXBuildFile; fileRef = 2D9BEAE01BB15F4A00AED473 /* UIViewController+Example.m */; };
2D9BEB0A1BB15F4A00AED473 /* MJChiBaoZiFooter.m in Sources */ = {isa = PBXBuildFile; fileRef = 2D9BEAE31BB15F4A00AED473 /* MJChiBaoZiFooter.m */; };
Expand Down Expand Up @@ -130,8 +130,8 @@
/* Begin PBXFileReference section */
01A2CE0A21ACE01500BEE365 /* MJRefreshConfig.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = MJRefreshConfig.h; sourceTree = "<group>"; };
01A2CE0B21ACE01500BEE365 /* MJRefreshConfig.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = MJRefreshConfig.m; sourceTree = "<group>"; };
01EB8270236846CE00813DAA /* MJWKWebViewController.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = MJWKWebViewController.h; sourceTree = "<group>"; };
01EB8271236846CE00813DAA /* MJWKWebViewController.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = MJWKWebViewController.m; sourceTree = "<group>"; };
01A5EB2925EF62B80091554E /* MJRefreshExample-Bridging-Header.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = "MJRefreshExample-Bridging-Header.h"; sourceTree = "<group>"; };
01A5EB2A25EF62B80091554E /* MJWKWebViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = MJWKWebViewController.swift; sourceTree = "<group>"; };
2D4698841D0EE6A400CB8025 /* NSBundle+MJRefresh.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = "NSBundle+MJRefresh.h"; sourceTree = "<group>"; };
2D4698851D0EE6A400CB8025 /* NSBundle+MJRefresh.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = "NSBundle+MJRefresh.m"; sourceTree = "<group>"; };
2D9BEADF1BB15F4A00AED473 /* UIViewController+Example.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = "UIViewController+Example.h"; sourceTree = "<group>"; };
Expand Down Expand Up @@ -257,6 +257,15 @@
/* End PBXFrameworksBuildPhase section */

/* Begin PBXGroup section */
01A5EB2825EF62930091554E /* SwiftExample */ = {
isa = PBXGroup;
children = (
01A5EB2A25EF62B80091554E /* MJWKWebViewController.swift */,
01A5EB2925EF62B80091554E /* MJRefreshExample-Bridging-Header.h */,
);
path = SwiftExample;
sourceTree = "<group>";
};
2D9BEADE1BB15F4A00AED473 /* Category */ = {
isa = PBXGroup;
children = (
Expand Down Expand Up @@ -328,8 +337,6 @@
2D9BEB061BB15F4A00AED473 /* MJWebViewViewController.h */,
2D9BEB071BB15F4A00AED473 /* MJWebViewViewController.m */,
2D9BEB081BB15F4A00AED473 /* MJWebViewViewController.xib */,
01EB8270236846CE00813DAA /* MJWKWebViewController.h */,
01EB8271236846CE00813DAA /* MJWKWebViewController.m */,
);
path = Second;
sourceTree = "<group>";
Expand Down Expand Up @@ -410,6 +417,7 @@
2D9BEAE11BB15F4A00AED473 /* DIY */,
2D9BEAEE1BB15F4A00AED473 /* First */,
2D9BEAFE1BB15F4A00AED473 /* Second */,
01A5EB2825EF62930091554E /* SwiftExample */,
);
path = Classes;
sourceTree = "<group>";
Expand Down Expand Up @@ -631,6 +639,7 @@
};
2DA7F9241AA6B4C4005627AB = {
CreatedOnToolsVersion = 6.1;
LastSwiftMigration = 1220;
};
2DA7F93D1AA6B4C4005627AB = {
CreatedOnToolsVersion = 6.1;
Expand Down Expand Up @@ -744,6 +753,7 @@
2D9BEB1B1BB15F4A00AED473 /* MJWebViewViewController.m in Sources */,
2DB2EA171BECBE6700D58F6A /* MJRefreshAutoFooter.m in Sources */,
2D9BEB101BB15F4A00AED473 /* MJExample.m in Sources */,
01A5EB2B25EF62B80091554E /* MJWKWebViewController.swift in Sources */,
2DB2EA201BECBE6700D58F6A /* MJRefreshBackNormalFooter.m in Sources */,
2DA7F92B1AA6B4C4005627AB /* main.m in Sources */,
2DB2EA1E1BECBE6700D58F6A /* MJRefreshAutoStateFooter.m in Sources */,
Expand All @@ -757,7 +767,6 @@
2D9BEB0C1BB15F4A00AED473 /* MJChiBaoZiHeader.m in Sources */,
88E3201224839B2300069FA7 /* MJRefreshNormalTrailer.m in Sources */,
2DB2EA1B1BECBE6700D58F6A /* MJRefreshHeader.m in Sources */,
01EB8272236846CE00813DAA /* MJWKWebViewController.m in Sources */,
2D9BEB191BB15F4A00AED473 /* MJTestViewController.m in Sources */,
2DB2EA211BECBE6700D58F6A /* MJRefreshBackStateFooter.m in Sources */,
2DB2EA281BECBE6700D58F6A /* UIScrollView+MJRefresh.m in Sources */,
Expand Down Expand Up @@ -1000,6 +1009,7 @@
isa = XCBuildConfiguration;
buildSettings = {
ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon;
CLANG_ENABLE_MODULES = YES;
CODE_SIGN_IDENTITY = "iPhone Developer";
DEVELOPMENT_TEAM = "";
GCC_PREFIX_HEADER = MJRefreshExample/PrefixHeader.pch;
Expand All @@ -1010,13 +1020,17 @@
);
PRODUCT_BUNDLE_IDENTIFIER = com.mj.MJRefresh;
PRODUCT_NAME = "$(TARGET_NAME)";
SWIFT_OBJC_BRIDGING_HEADER = "MJRefreshExample/Classes/SwiftExample/MJRefreshExample-Bridging-Header.h";
SWIFT_OPTIMIZATION_LEVEL = "-Onone";
SWIFT_VERSION = 5.0;
};
name = Debug;
};
2DA7F94A1AA6B4C4005627AB /* Release */ = {
isa = XCBuildConfiguration;
buildSettings = {
ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon;
CLANG_ENABLE_MODULES = YES;
CODE_SIGN_IDENTITY = "iPhone Developer";
DEVELOPMENT_TEAM = "";
GCC_PREFIX_HEADER = MJRefreshExample/PrefixHeader.pch;
Expand All @@ -1027,12 +1041,15 @@
);
PRODUCT_BUNDLE_IDENTIFIER = com.mj.MJRefresh;
PRODUCT_NAME = "$(TARGET_NAME)";
SWIFT_OBJC_BRIDGING_HEADER = "MJRefreshExample/Classes/SwiftExample/MJRefreshExample-Bridging-Header.h";
SWIFT_VERSION = 5.0;
};
name = Release;
};
2DA7F94C1AA6B4C4005627AB /* Debug */ = {
isa = XCBuildConfiguration;
buildSettings = {
ALWAYS_EMBED_SWIFT_STANDARD_LIBRARIES = YES;
BUNDLE_LOADER = "$(TEST_HOST)";
FRAMEWORK_SEARCH_PATHS = (
"$(SDKROOT)/System/Library/Frameworks",
Expand All @@ -1057,6 +1074,7 @@
2DA7F94D1AA6B4C4005627AB /* Release */ = {
isa = XCBuildConfiguration;
buildSettings = {
ALWAYS_EMBED_SWIFT_STANDARD_LIBRARIES = YES;
BUNDLE_LOADER = "$(TEST_HOST)";
FRAMEWORK_SEARCH_PATHS = (
"$(SDKROOT)/System/Library/Frameworks",
Expand Down
2 changes: 1 addition & 1 deletion MJRefreshExample/Classes/First/MJExampleViewController.m
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@
#import "MJExample.h"
#import "UIViewController+Example.h"
#import "MJRefresh.h"
#import "MJWKWebViewController.h"
#import "MJHorizontalCollectionViewController.h"
#import "MJRefreshExample-Swift.h"

static NSString *const MJExample00 = @"UITableView + 下拉刷新";
static NSString *const MJExample10 = @"UITableView + 上拉刷新";
Expand Down
17 changes: 0 additions & 17 deletions MJRefreshExample/Classes/Second/MJWKWebViewController.h

This file was deleted.

105 changes: 0 additions & 105 deletions MJRefreshExample/Classes/Second/MJWKWebViewController.m

This file was deleted.

8 changes: 5 additions & 3 deletions MJRefreshExample/Classes/Second/MJWebViewViewController.m
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,11 @@ - (void)example31
__weak UIScrollView *scrollView = self.webView.scrollView;

// 添加下拉刷新控件
scrollView.mj_header= [MJChiBaoZiHeader headerWithRefreshingBlock:^{
[webView reload];
}];
[[[MJChiBaoZiHeader headerWithRefreshingBlock:^{
[webView reload];
}]
assignTo:scrollView]
autoChangeTransparency:YES];

// 如果是上拉刷新,就以此类推
[scrollView.mj_header beginRefreshing];
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
//
// Use this file to import your target's public headers that you would like to expose to Swift.
//

#import "MJRefresh.h"
#import "MJChiBaoZiHeader.h"
Loading

0 comments on commit d48313b

Please sign in to comment.