diff --git a/ios/sdk/WeexSDK.xcodeproj/project.pbxproj b/ios/sdk/WeexSDK.xcodeproj/project.pbxproj index 9519d4d98b..16c56b768c 100644 --- a/ios/sdk/WeexSDK.xcodeproj/project.pbxproj +++ b/ios/sdk/WeexSDK.xcodeproj/project.pbxproj @@ -94,6 +94,8 @@ 7469869C1C4DEAC20054A57E /* libicucore.tbd in Frameworks */ = {isa = PBXBuildFile; fileRef = 7469869B1C4DEAC20054A57E /* libicucore.tbd */; }; 7469869F1C4E2C000054A57E /* NSArray+Weex.h in Headers */ = {isa = PBXBuildFile; fileRef = 7469869D1C4E2C000054A57E /* NSArray+Weex.h */; }; 746986A01C4E2C010054A57E /* NSArray+Weex.m in Sources */ = {isa = PBXBuildFile; fileRef = 7469869E1C4E2C000054A57E /* NSArray+Weex.m */; }; + 74896F301D1AC79400D1D593 /* NSObject+WXSwizzle.h in Headers */ = {isa = PBXBuildFile; fileRef = 74896F2E1D1AC79400D1D593 /* NSObject+WXSwizzle.h */; }; + 74896F311D1AC79400D1D593 /* NSObject+WXSwizzle.m in Sources */ = {isa = PBXBuildFile; fileRef = 74896F2F1D1AC79400D1D593 /* NSObject+WXSwizzle.m */; }; 748B25181C44A6F9005D491E /* WXSDKInstance_private.h in Headers */ = {isa = PBXBuildFile; fileRef = 748B25161C44A6F9005D491E /* WXSDKInstance_private.h */; }; 74915F471C8EB02B00BEBCC0 /* WXAssert.h in Headers */ = {isa = PBXBuildFile; fileRef = 74915F451C8EB02B00BEBCC0 /* WXAssert.h */; }; 74915F481C8EB02B00BEBCC0 /* WXAssert.m in Sources */ = {isa = PBXBuildFile; fileRef = 74915F461C8EB02B00BEBCC0 /* WXAssert.m */; }; @@ -286,6 +288,8 @@ 7469869B1C4DEAC20054A57E /* libicucore.tbd */ = {isa = PBXFileReference; lastKnownFileType = "sourcecode.text-based-dylib-definition"; name = libicucore.tbd; path = usr/lib/libicucore.tbd; sourceTree = SDKROOT; }; 7469869D1C4E2C000054A57E /* NSArray+Weex.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = "NSArray+Weex.h"; sourceTree = ""; }; 7469869E1C4E2C000054A57E /* NSArray+Weex.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = "NSArray+Weex.m"; sourceTree = ""; }; + 74896F2E1D1AC79400D1D593 /* NSObject+WXSwizzle.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = "NSObject+WXSwizzle.h"; sourceTree = ""; }; + 74896F2F1D1AC79400D1D593 /* NSObject+WXSwizzle.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = "NSObject+WXSwizzle.m"; sourceTree = ""; }; 748B25161C44A6F9005D491E /* WXSDKInstance_private.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = WXSDKInstance_private.h; sourceTree = ""; }; 74915F451C8EB02B00BEBCC0 /* WXAssert.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = WXAssert.h; sourceTree = ""; }; 74915F461C8EB02B00BEBCC0 /* WXAssert.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = WXAssert.m; sourceTree = ""; }; @@ -690,6 +694,8 @@ 74A4BA991CB3BAA100195969 /* WXThreadSafeMutableDictionary.m */, 7461F8A61CFC33A800F62D44 /* WXThreadSafeMutableArray.h */, 7461F8A71CFC33A800F62D44 /* WXThreadSafeMutableArray.m */, + 74896F2E1D1AC79400D1D593 /* NSObject+WXSwizzle.h */, + 74896F2F1D1AC79400D1D593 /* NSObject+WXSwizzle.m */, ); path = Utility; sourceTree = ""; @@ -854,6 +860,7 @@ 59A596311CB632050012CD52 /* WXRootViewController.h in Headers */, 77E65A151C155EB5008B8775 /* WXTextComponent.h in Headers */, 74CC7A1C1C2BC5F800829368 /* WXCellComponent.h in Headers */, + 74896F301D1AC79400D1D593 /* NSObject+WXSwizzle.h in Headers */, 59A596241CB6311F0012CD52 /* WXStorageModule.h in Headers */, 74A4BA851CAD453400195969 /* WXNetworkProtocol.h in Headers */, 7461F8A81CFC33A800F62D44 /* WXThreadSafeMutableArray.h in Headers */, @@ -1038,6 +1045,7 @@ 77E65A071C10507B008B8775 /* WXModuleManager.m in Sources */, 77D161291C02DE1A0010B15B /* WXSDKManager.m in Sources */, 7461F8911CFB373100F62D44 /* WXDisplayQueue.m in Sources */, + 74896F311D1AC79400D1D593 /* NSObject+WXSwizzle.m in Sources */, 746986A01C4E2C010054A57E /* NSArray+Weex.m in Sources */, 77E65A0E1C155E99008B8775 /* WXDivComponent.m in Sources */, 2A60CE9D1C91733E00857B9F /* WXSwitchComponent.m in Sources */, diff --git a/ios/sdk/WeexSDK/Sources/Component/WXListComponent.m b/ios/sdk/WeexSDK/Sources/Component/WXListComponent.m index f6ba95d087..1141083d78 100644 --- a/ios/sdk/WeexSDK/Sources/Component/WXListComponent.m +++ b/ios/sdk/WeexSDK/Sources/Component/WXListComponent.m @@ -12,6 +12,7 @@ #import "NSArray+Weex.h" #import "WXAssert.h" #import "WXUtility.h" +#import "NSObject+WXSwizzle.h" #import "WXSDKInstance_private.h" @interface WXTableView : UITableView @@ -55,6 +56,7 @@ - (instancetype)initWithRef:(NSString *)ref type:(NSString *)type styles:(NSDict _completedCells = [NSMutableArray wx_mutableArrayUsingWeakReferences]; [self fillPadding]; + [self fixFlicker]; } return self; @@ -71,6 +73,7 @@ - (void)fillPadding } } + - (UIView *)loadView { return [[WXTableView alloc] init]; @@ -329,5 +332,23 @@ - (BOOL)isNeedLoadMore return superNeedLoadMore && _previousLoadMoreRowNumber != [self tableView:_tableView numberOfRowsInSection:0]; } +- (void)fixFlicker +{ + static dispatch_once_t onceToken; + dispatch_once(&onceToken, ^{ + //(ง •̀_•́)ง┻━┻ Stupid scoll view, always reset content offset to zero after insert cells, any other more elegant way? + NSString *a = @"ntOffsetIfNe"; + NSString *b = @"adjustConte"; + + NSString *originSelector = [NSString stringWithFormat:@"_%@%@cessary", b, a]; + [[self class] weex_swizzle:[WXTableView class] Method:NSSelectorFromString(originSelector) withMethod:@selector(fixedFlickerSelector)]; + }); +} + +- (void)fixedFlickerSelector +{ + // DO NOT delete this method. +} + @end diff --git a/ios/sdk/WeexSDK/Sources/Utility/NSObject+WXSwizzle.h b/ios/sdk/WeexSDK/Sources/Utility/NSObject+WXSwizzle.h new file mode 100644 index 0000000000..b12bbf5725 --- /dev/null +++ b/ios/sdk/WeexSDK/Sources/Utility/NSObject+WXSwizzle.h @@ -0,0 +1,16 @@ +/** + * Created by Weex. + * Copyright (c) 2016, Alibaba, Inc. All rights reserved. + * + * This source code is licensed under the Apache Licence 2.0. + * For the full copyright and license information,please view the LICENSE file in the root directory of this source tree. + */ + + +#import + +@interface NSObject (WXSwizzle) + ++ (BOOL)weex_swizzle:(Class)originalClass Method:(SEL)originalSelector withMethod:(SEL)swizzledSelector; + +@end diff --git a/ios/sdk/WeexSDK/Sources/Utility/NSObject+WXSwizzle.m b/ios/sdk/WeexSDK/Sources/Utility/NSObject+WXSwizzle.m new file mode 100644 index 0000000000..a81d96ca8a --- /dev/null +++ b/ios/sdk/WeexSDK/Sources/Utility/NSObject+WXSwizzle.m @@ -0,0 +1,36 @@ +/** + * Created by Weex. + * Copyright (c) 2016, Alibaba, Inc. All rights reserved. + * + * This source code is licensed under the Apache Licence 2.0. + * For the full copyright and license information,please view the LICENSE file in the root directory of this source tree. + */ + +#import "NSObject+WXSwizzle.h" +#import + +@implementation NSObject (WXSwizzle) + ++ (BOOL)weex_swizzle:(Class)originalClass Method:(SEL)originalSelector withMethod:(SEL)swizzledSelector +{ + if (!(originalClass && originalSelector && swizzledSelector)) { + return NO; + } + + Class class = [self class]; + + Method originalMethod = class_getInstanceMethod(originalClass, originalSelector); + Method swizzledMethod = class_getInstanceMethod(class, swizzledSelector); + + BOOL didAddMethod = class_addMethod(originalClass, originalSelector, method_getImplementation(swizzledMethod), method_getTypeEncoding(swizzledMethod)); + + if (didAddMethod) { + class_replaceMethod(class, swizzledSelector, method_getImplementation(originalMethod), method_getTypeEncoding(originalMethod)); + } else { + method_exchangeImplementations(originalMethod, swizzledMethod); + } + + return YES; +} + +@end