Skip to content

Commit

Permalink
重写slider组件
Browse files Browse the repository at this point in the history
  • Loading branch information
jingcheng1988 committed Dec 11, 2024
1 parent 59fbc09 commit 298220c
Show file tree
Hide file tree
Showing 14 changed files with 2,037 additions and 519 deletions.
44 changes: 42 additions & 2 deletions GaiaXiOS/GaiaXiOS.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,14 @@
2CECF30401B7B1202EFE178B /* libPods-GaiaXiOSTests.a in Frameworks */ = {isa = PBXBuildFile; fileRef = 26E99510FB4BAB41B3A64E70 /* libPods-GaiaXiOSTests.a */; };
8A962CCA282A9DD100335552 /* GXSliderNode.h in Headers */ = {isa = PBXBuildFile; fileRef = 8A962CC8282A9DD100335552 /* GXSliderNode.h */; };
8A962CCB282A9DD100335552 /* GXSliderNode.m in Sources */ = {isa = PBXBuildFile; fileRef = 8A962CC9282A9DD100335552 /* GXSliderNode.m */; };
8D10145C2D096BEC0034A175 /* GXPagerLayout.m in Sources */ = {isa = PBXBuildFile; fileRef = 8D1014542D096BEC0034A175 /* GXPagerLayout.m */; };
8D10145D2D096BEC0034A175 /* GXSliderView.m in Sources */ = {isa = PBXBuildFile; fileRef = 8D1014552D096BEC0034A175 /* GXSliderView.m */; };
8D10145E2D096BEC0034A175 /* GXPageControl.m in Sources */ = {isa = PBXBuildFile; fileRef = 8D1014562D096BEC0034A175 /* GXPageControl.m */; };
8D10145F2D096BEC0034A175 /* GXPagerView.m in Sources */ = {isa = PBXBuildFile; fileRef = 8D1014572D096BEC0034A175 /* GXPagerView.m */; };
8D1014602D096BEC0034A175 /* GXPagerLayout.h in Headers */ = {isa = PBXBuildFile; fileRef = 8D1014582D096BEC0034A175 /* GXPagerLayout.h */; };
8D1014612D096BEC0034A175 /* GXSliderView.h in Headers */ = {isa = PBXBuildFile; fileRef = 8D1014592D096BEC0034A175 /* GXSliderView.h */; };
8D1014622D096BEC0034A175 /* GXPageControl.h in Headers */ = {isa = PBXBuildFile; fileRef = 8D10145A2D096BEC0034A175 /* GXPageControl.h */; };
8D1014632D096BEC0034A175 /* GXPagerView.h in Headers */ = {isa = PBXBuildFile; fileRef = 8D10145B2D096BEC0034A175 /* GXPagerView.h */; };
8D1CBCE727560A5F00EC2B4D /* GXBizHelper.h in Headers */ = {isa = PBXBuildFile; fileRef = 8D1CBCE527560A5F00EC2B4D /* GXBizHelper.h */; };
8D1CBCE827560A5F00EC2B4D /* GXBizHelper.m in Sources */ = {isa = PBXBuildFile; fileRef = 8D1CBCE627560A5F00EC2B4D /* GXBizHelper.m */; };
8D1CBCED275770F700EC2B4D /* GXEvent.h in Headers */ = {isa = PBXBuildFile; fileRef = 8D1CBCEB275770F700EC2B4D /* GXEvent.h */; settings = {ATTRIBUTES = (Public, ); }; };
Expand Down Expand Up @@ -210,6 +218,14 @@
8A962CC8282A9DD100335552 /* GXSliderNode.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = GXSliderNode.h; sourceTree = "<group>"; };
8A962CC9282A9DD100335552 /* GXSliderNode.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = GXSliderNode.m; sourceTree = "<group>"; };
8CF100DA07FB9596328219B4 /* Pods-GaiaXiOSTests.debug.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-GaiaXiOSTests.debug.xcconfig"; path = "Target Support Files/Pods-GaiaXiOSTests/Pods-GaiaXiOSTests.debug.xcconfig"; sourceTree = "<group>"; };
8D1014542D096BEC0034A175 /* GXPagerLayout.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = GXPagerLayout.m; sourceTree = "<group>"; };
8D1014552D096BEC0034A175 /* GXSliderView.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = GXSliderView.m; sourceTree = "<group>"; };
8D1014562D096BEC0034A175 /* GXPageControl.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = GXPageControl.m; sourceTree = "<group>"; };
8D1014572D096BEC0034A175 /* GXPagerView.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = GXPagerView.m; sourceTree = "<group>"; };
8D1014582D096BEC0034A175 /* GXPagerLayout.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = GXPagerLayout.h; sourceTree = "<group>"; };
8D1014592D096BEC0034A175 /* GXSliderView.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = GXSliderView.h; sourceTree = "<group>"; };
8D10145A2D096BEC0034A175 /* GXPageControl.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = GXPageControl.h; sourceTree = "<group>"; };
8D10145B2D096BEC0034A175 /* GXPagerView.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = GXPagerView.h; sourceTree = "<group>"; };
8D1CBCE527560A5F00EC2B4D /* GXBizHelper.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = GXBizHelper.h; sourceTree = "<group>"; };
8D1CBCE627560A5F00EC2B4D /* GXBizHelper.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = GXBizHelper.m; sourceTree = "<group>"; };
8D1CBCEB275770F700EC2B4D /* GXEvent.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = GXEvent.h; sourceTree = "<group>"; };
Expand Down Expand Up @@ -419,6 +435,21 @@
/* End PBXFrameworksBuildPhase section */

/* Begin PBXGroup section */
8D1014532D096BEC0034A175 /* Slider */ = {
isa = PBXGroup;
children = (
8D10145A2D096BEC0034A175 /* GXPageControl.h */,
8D1014562D096BEC0034A175 /* GXPageControl.m */,
8D1014582D096BEC0034A175 /* GXPagerLayout.h */,
8D1014542D096BEC0034A175 /* GXPagerLayout.m */,
8D10145B2D096BEC0034A175 /* GXPagerView.h */,
8D1014572D096BEC0034A175 /* GXPagerView.m */,
8D1014592D096BEC0034A175 /* GXSliderView.h */,
8D1014552D096BEC0034A175 /* GXSliderView.m */,
);
path = Slider;
sourceTree = "<group>";
};
8D1CBD1C2758AA4500EC2B4D /* GaiaXiOSTests */ = {
isa = PBXGroup;
children = (
Expand Down Expand Up @@ -785,8 +816,6 @@
8DFEC2D427351928001F3B74 /* Node */ = {
isa = PBXGroup;
children = (
8A962CC8282A9DD100335552 /* GXSliderNode.h */,
8A962CC9282A9DD100335552 /* GXSliderNode.m */,
8DFEC2EC27351BB6001F3B74 /* GXBaseNode.h */,
8DFEC2ED27351BB6001F3B74 /* GXBaseNode.m */,
8D9FC9CA273A21F600912EE6 /* GXViewNode.h */,
Expand All @@ -801,6 +830,8 @@
8D9FC9DF273A224900912EE6 /* GXIconFontNode.m */,
8D9FC9D2273A221A00912EE6 /* GXGridNode.h */,
8D9FC9D3273A221A00912EE6 /* GXGridNode.m */,
8A962CC8282A9DD100335552 /* GXSliderNode.h */,
8A962CC9282A9DD100335552 /* GXSliderNode.m */,
8D9FC9D6273A222B00912EE6 /* GXScrollNode.h */,
8D9FC9D7273A222B00912EE6 /* GXScrollNode.m */,
8D9FC9DA273A223A00912EE6 /* GXCustomNode.h */,
Expand Down Expand Up @@ -845,6 +876,7 @@
8DFEC2E327351990001F3B74 /* Container */ = {
isa = PBXGroup;
children = (
8D1014532D096BEC0034A175 /* Slider */,
8DFEC2E827351A03001F3B74 /* GXScrollView.h */,
8DFEC2E927351A03001F3B74 /* GXScrollView.m */,
8DFF84E6273D183F0014C0DA /* GXRootView.h */,
Expand Down Expand Up @@ -950,12 +982,14 @@
8DFEC25F2734DC08001F3B74 /* GXCommonDef.h in Headers */,
8DFEC2612734DC19001F3B74 /* GXFunctionDef.h in Headers */,
8DFEC2542734DB27001F3B74 /* GXUtils.h in Headers */,
8D1014612D096BEC0034A175 /* GXSliderView.h in Headers */,
8DFEC2742734DDC8001F3B74 /* NSArray+GX.h in Headers */,
8DFEC2702734DDBE001F3B74 /* NSDictionary+GX.h in Headers */,
8DE5E3A32745FD9400C9FA02 /* GXExpression.h in Headers */,
8DE5E3862743A3F800C9FA02 /* GXRegisterCenter.h in Headers */,
8DE14A18288E338100FCF226 /* GXProgressNode.h in Headers */,
8A962CCA282A9DD100335552 /* GXSliderNode.h in Headers */,
8D1014602D096BEC0034A175 /* GXPagerLayout.h in Headers */,
8DB521692759C7C900EB8126 /* GXTrack.h in Headers */,
8D1CBCED275770F700EC2B4D /* GXEvent.h in Headers */,
8DB521652759C6A300EB8126 /* GXData.h in Headers */,
Expand All @@ -980,6 +1014,7 @@
8DE5E3962744DAA200C9FA02 /* GXUIHelper.h in Headers */,
8DE5E38227439BE900C9FA02 /* GXTemplateLoader.h in Headers */,
8DFEC2BF27350BBA001F3B74 /* libstretch.h in Headers */,
8D1014632D096BEC0034A175 /* GXPagerView.h in Headers */,
8DFEC2E6273519EE001F3B74 /* GXGridView.h in Headers */,
8DFF84E8273D183F0014C0DA /* GXRootView.h in Headers */,
8D9FC9E8273A227800912EE6 /* GXRootViewNode.h in Headers */,
Expand All @@ -995,6 +1030,7 @@
8DFEC2CA27350E26001F3B74 /* GXStretch.h in Headers */,
8D9FC9DC273A223A00912EE6 /* GXCustomNode.h in Headers */,
8DE5E3772743820A00C9FA02 /* GXTemplateParser.h in Headers */,
8D1014622D096BEC0034A175 /* GXPageControl.h in Headers */,
8DB60A1927F4764E0038BE13 /* GXValue.h in Headers */,
8DE14A1C288E339300FCF226 /* GXProgressView.h in Headers */,
8D9FC9CC273A21F600912EE6 /* GXViewNode.h in Headers */,
Expand Down Expand Up @@ -1242,6 +1278,7 @@
BD42E33529A4A4B200F3404E /* GXEventManager.m in Sources */,
8DFEC2652734DC56001F3B74 /* GXCssItem.m in Sources */,
8DFF84E9273D183F0014C0DA /* GXRootView.m in Sources */,
8D10145F2D096BEC0034A175 /* GXPagerView.m in Sources */,
8DFEC2712734DDBE001F3B74 /* NSDictionary+GX.m in Sources */,
8D9FC9E5273A225A00912EE6 /* GXRichTextNode.m in Sources */,
8DFF84F1273E60A80014C0DA /* GXTemplateManager.m in Sources */,
Expand All @@ -1263,6 +1300,7 @@
BD42E32F29A4A49F00F3404E /* GXJSDelegateImplManager.m in Sources */,
8DE5E38F2744B20200C9FA02 /* GXNodeHelper.m in Sources */,
8DE14A19288E338100FCF226 /* GXProgressNode.m in Sources */,
8D10145E2D096BEC0034A175 /* GXPageControl.m in Sources */,
8DE5E3A82746794300C9FA02 /* GXImageNode.m in Sources */,
8DE5E3B52747AF9600C9FA02 /* GXRichText.m in Sources */,
8D1D6300274F360600B94B1E /* GXDataManager.m in Sources */,
Expand All @@ -1278,6 +1316,7 @@
8DEEFED5276880F4008C73A5 /* GXCacheCenter.m in Sources */,
8DB5216A2759C7C900EB8126 /* GXTrack.m in Sources */,
8D1CBCEE275770F700EC2B4D /* GXEvent.m in Sources */,
8D10145C2D096BEC0034A175 /* GXPagerLayout.m in Sources */,
8DB521662759C6A300EB8126 /* GXData.m in Sources */,
8DCE3367283E451D00A42EF8 /* GXTemplateSource.m in Sources */,
8DFEC3042735319A001F3B74 /* GXBizContext.m in Sources */,
Expand All @@ -1295,6 +1334,7 @@
8DFEC2CB27350E26001F3B74 /* GXStretch.m in Sources */,
8DE5E37F27438A4E00C9FA02 /* GXTemplatePathHelper.m in Sources */,
8D9FC9E1273A224900912EE6 /* GXIconFontNode.m in Sources */,
8D10145D2D096BEC0034A175 /* GXSliderView.m in Sources */,
8DFEC2C327350E01001F3B74 /* GXLayout.m in Sources */,
);
runOnlyForDeploymentPostprocessing = 0;
Expand Down
16 changes: 16 additions & 0 deletions GaiaXiOS/GaiaXiOS/Category/UIView+GX.h
Original file line number Diff line number Diff line change
Expand Up @@ -127,5 +127,21 @@ NS_ASSUME_NONNULL_BEGIN
@end


@interface UIView (GXLayout)

@property (nonatomic) CGFloat gx_left; ///< Shortcut for frame.origin.x.
@property (nonatomic) CGFloat gx_top; ///< Shortcut for frame.origin.y
@property (nonatomic) CGFloat gx_right; ///< Shortcut for frame.origin.x + frame.size.width
@property (nonatomic) CGFloat gx_bottom; ///< Shortcut for frame.origin.y + frame.size.height
@property (nonatomic) CGFloat gx_width; ///< Shortcut for frame.size.width.
@property (nonatomic) CGFloat gx_height; ///< Shortcut for frame.size.height.
@property (nonatomic) CGFloat gx_centerX; ///< Shortcut for center.x
@property (nonatomic) CGFloat gx_centerY; ///< Shortcut for center.y
@property (nonatomic) CGPoint gx_origin; ///< Shortcut for frame.origin.
@property (nonatomic) CGSize gx_size; ///< Shortcut for frame.size.

@end



NS_ASSUME_NONNULL_END
137 changes: 137 additions & 0 deletions GaiaXiOS/GaiaXiOS/Category/UIView+GX.m
Original file line number Diff line number Diff line change
Expand Up @@ -385,3 +385,140 @@ - (void)setBlurView:(UIVisualEffectView *)blurView{

@end


#pragma mark - GaiaXTools

@implementation UIView (GaiaXTools)

- (UIViewController *)gx_viewController{
for (UIView *view = self; view; view = view.superview) {
UIResponder *nextResponder = [view nextResponder];
if ([nextResponder isKindOfClass:[UIViewController class]]) {
return (UIViewController *)nextResponder;
}
}
return nil;
}

- (void)gx_removeAllSubviews{
[self.subviews makeObjectsPerformSelector:@selector(removeFromSuperview)];
}

- (UIImage *)gx_snapshotImage{
// UIGraphicsBeginImageContextWithOptions(self.bounds.size, self.opaque, 0);
// [self.layer renderInContext:UIGraphicsGetCurrentContext()];
// UIImage *snap = UIGraphicsGetImageFromCurrentImageContext();
// UIGraphicsEndImageContext();

UIGraphicsImageRendererFormat *format = [[UIGraphicsImageRendererFormat alloc] init];
format.opaque = self.opaque;
CGSize size = self.bounds.size;
UIGraphicsImageRenderer *render = [[UIGraphicsImageRenderer alloc] initWithSize:size format:format];
UIImage *image = [render imageWithActions:^(UIGraphicsImageRendererContext * _Nonnull rendererContext) {
[self.layer renderInContext:rendererContext.CGContext];
}];
return image;
}

@end


@implementation UIView (GXLayout)

- (CGFloat)gx_left {
return self.frame.origin.x;
}

- (void)setGx_left:(CGFloat)x {
CGRect frame = self.frame;
frame.origin.x = x;
self.frame = frame;
}

- (CGFloat)gx_top {
return self.frame.origin.y;
}

- (void)setGx_top:(CGFloat)y {
CGRect frame = self.frame;
frame.origin.y = y;
self.frame = frame;
}

- (CGFloat)gx_right {
return self.frame.origin.x + self.frame.size.width;
}

- (void)setGx_right:(CGFloat)right {
CGRect frame = self.frame;
frame.origin.x = right - frame.size.width;
self.frame = frame;
}

- (CGFloat)gx_bottom {
return self.frame.origin.y + self.frame.size.height;
}

- (void)setGx_bottom:(CGFloat)bottom {
CGRect frame = self.frame;
frame.origin.y = bottom - frame.size.height;
self.frame = frame;
}

- (CGFloat)gx_width {
return self.frame.size.width;
}

- (void)setGx_width:(CGFloat)width {
CGRect frame = self.frame;
frame.size.width = width;
self.frame = frame;
}

- (CGFloat)gx_height {
return self.frame.size.height;
}

- (void)setGx_height:(CGFloat)height {
CGRect frame = self.frame;
frame.size.height = height;
self.frame = frame;
}

- (CGFloat)gx_centerX {
return self.center.x;
}

- (void)setGx_centerX:(CGFloat)centerX {
self.center = CGPointMake(centerX, self.center.y);
}

- (CGFloat)gx_centerY {
return self.center.y;
}

- (void)setGx_centerY:(CGFloat)centerY {
self.center = CGPointMake(self.center.x, centerY);
}

- (CGPoint)gx_origin {
return self.frame.origin;
}

- (void)setGx_origin:(CGPoint)origin {
CGRect frame = self.frame;
frame.origin = origin;
self.frame = frame;
}

- (CGSize)gx_size {
return self.frame.size;
}

- (void)setGx_size:(CGSize)size {
CGRect frame = self.frame;
frame.size = size;
self.frame = frame;
}

@end
19 changes: 7 additions & 12 deletions GaiaXiOS/GaiaXiOS/Component/Node/GXScrollNode.m
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ @interface GXScrollNode ()<UICollectionViewDelegate, UICollectionViewDataSource,
//横向模式下坑位位置
@property (nonatomic, strong) NSString *gravity;
//坑位Size数组
@property (nonatomic, strong) NSMutableArray *sizeValues;
@property (nonatomic, strong) NSArray *sizeValues;
//坑位的复用标识
@property (nonatomic, strong) NSMutableArray *identifiers;
//子坑位的subItems
Expand Down Expand Up @@ -311,6 +311,8 @@ - (GXTemplateItem *)templateItemWithIdentifier:(NSString *)identifier{

//计算itemSize
- (void)calculateItemSize:(NSDictionary *)extend{
NSMutableArray *tmpSizeValues = [NSMutableArray array];

CGFloat measureWidth = NAN;
CGFloat measureHeight = NAN;
if (self.scrollDirection == UICollectionViewScrollDirectionVertical) {
Expand All @@ -323,7 +325,6 @@ - (void)calculateItemSize:(NSDictionary *)extend{
//计算itemSize
_containerHeight = 0.f;
CGSize itemSize = CGSizeZero;
[self.sizeValues removeAllObjects];
for (int i = 0; i < self.items.count; i++) {
//获取坑位类型
NSString *identifier = [self identifierWithIndex:i];
Expand All @@ -350,9 +351,10 @@ - (void)calculateItemSize:(NSDictionary *)extend{
_containerHeight = itemHeight;
}
//添加到数组中
[self.sizeValues gx_addObject:[NSValue valueWithCGSize:itemSize]];
[tmpSizeValues gx_addObject:[NSValue valueWithCGSize:itemSize]];
}


self.sizeValues = tmpSizeValues;
}


Expand Down Expand Up @@ -416,7 +418,7 @@ - (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cell

//数据绑定
GXTemplateData *data = [self.items objectAtIndex:index];
[TheGXTemplateEngine bindData:data onView:rootView];
[TheGXTemplateEngine bindData:data onView:rootView];

return cell;
}
Expand Down Expand Up @@ -588,13 +590,6 @@ - (NSMutableArray *)items{
return _items;
}

- (NSMutableArray *)sizeValues{
if (!_sizeValues) {
_sizeValues = [NSMutableArray array];
}
return _sizeValues;
}

- (NSMutableArray *)identifiers{
if (!_identifiers) {
_identifiers = [NSMutableArray array];
Expand Down
7 changes: 0 additions & 7 deletions GaiaXiOS/GaiaXiOS/Component/Node/GXSliderNode.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,13 +22,6 @@ NS_ASSUME_NONNULL_BEGIN

@interface GXSliderNode : GXBaseNode

//内边距
@property (nonatomic) UIEdgeInsets contentInset;
//坑位间距
@property (nonatomic, assign) CGFloat itemSpacing;
//滚动方法
@property (nonatomic) UICollectionViewScrollDirection scrollDirection;

@end

NS_ASSUME_NONNULL_END
Loading

0 comments on commit 298220c

Please sign in to comment.