feat:add NestedSlider
This commit is contained in:
parent
50c31c4a14
commit
ce0e1d0ed0
@ -42,6 +42,7 @@
|
|||||||
#import "DoricFlowLayoutNode.h"
|
#import "DoricFlowLayoutNode.h"
|
||||||
#import "DoricPopoverPlugin.h"
|
#import "DoricPopoverPlugin.h"
|
||||||
#import "DoricAnimatePlugin.h"
|
#import "DoricAnimatePlugin.h"
|
||||||
|
#import "DoricNestedSliderNode.h"
|
||||||
|
|
||||||
@interface DoricRegistry ()
|
@interface DoricRegistry ()
|
||||||
|
|
||||||
@ -86,6 +87,7 @@ - (void)innerRegister {
|
|||||||
[self registerViewNode:DoricRefreshableNode.class withName:@"Refreshable"];
|
[self registerViewNode:DoricRefreshableNode.class withName:@"Refreshable"];
|
||||||
[self registerViewNode:DoricFlowLayoutItemNode.class withName:@"FlowLayoutItem"];
|
[self registerViewNode:DoricFlowLayoutItemNode.class withName:@"FlowLayoutItem"];
|
||||||
[self registerViewNode:DoricFlowLayoutNode.class withName:@"FlowLayout"];
|
[self registerViewNode:DoricFlowLayoutNode.class withName:@"FlowLayout"];
|
||||||
|
[self registerViewNode:DoricNestedSliderNode.class withName:@"NestedSlider"];
|
||||||
}
|
}
|
||||||
|
|
||||||
- (void)registerJSBundle:(NSString *)bundle withName:(NSString *)name {
|
- (void)registerJSBundle:(NSString *)bundle withName:(NSString *)name {
|
||||||
|
@ -20,7 +20,6 @@
|
|||||||
// Created by pengfei.zhou on 2019/7/30.
|
// Created by pengfei.zhou on 2019/7/30.
|
||||||
//
|
//
|
||||||
|
|
||||||
#import <Doric/DoricExtensions.h>
|
|
||||||
#import "DoricGroupNode.h"
|
#import "DoricGroupNode.h"
|
||||||
|
|
||||||
@interface DoricGroupNode ()
|
@interface DoricGroupNode ()
|
||||||
|
24
Pod/Classes/Shader/DoricNestedSliderNode.h
Normal file
24
Pod/Classes/Shader/DoricNestedSliderNode.h
Normal file
@ -0,0 +1,24 @@
|
|||||||
|
/*
|
||||||
|
* Copyright [2019] [Doric.Pub]
|
||||||
|
*
|
||||||
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
* you may not use this file except in compliance with the License.
|
||||||
|
* You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
* See the License for the specific language governing permissions and
|
||||||
|
* limitations under the License.
|
||||||
|
*/
|
||||||
|
//
|
||||||
|
// Created by pengfei.zhou on 2019/12/7.
|
||||||
|
//
|
||||||
|
|
||||||
|
#import <Foundation/Foundation.h>
|
||||||
|
#import "DoricGroupNode.h"
|
||||||
|
|
||||||
|
@interface DoricNestedSliderNode : DoricGroupNode<UIScrollView *>
|
||||||
|
@end
|
101
Pod/Classes/Shader/DoricNestedSliderNode.m
Normal file
101
Pod/Classes/Shader/DoricNestedSliderNode.m
Normal file
@ -0,0 +1,101 @@
|
|||||||
|
/*
|
||||||
|
* Copyright [2019] [Doric.Pub]
|
||||||
|
*
|
||||||
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
* you may not use this file except in compliance with the License.
|
||||||
|
* You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
* See the License for the specific language governing permissions and
|
||||||
|
* limitations under the License.
|
||||||
|
*/
|
||||||
|
//
|
||||||
|
// Created by pengfei.zhou on 2019/12/7.
|
||||||
|
//
|
||||||
|
|
||||||
|
#import "DoricNestedSliderNode.h"
|
||||||
|
#import "Doric.h"
|
||||||
|
|
||||||
|
@interface DoricNestedSliderView : UIScrollView
|
||||||
|
|
||||||
|
@end
|
||||||
|
|
||||||
|
@implementation DoricNestedSliderView
|
||||||
|
- (CGSize)sizeThatFits:(CGSize)size {
|
||||||
|
if (self.subviews.count > 0) {
|
||||||
|
CGFloat width = size.width;
|
||||||
|
CGFloat height = size.height;
|
||||||
|
for (UIView *child in self.subviews) {
|
||||||
|
CGSize childSize = [child measureSize:size];
|
||||||
|
width = MAX(childSize.width, width);
|
||||||
|
height = MAX(childSize.height, height);
|
||||||
|
}
|
||||||
|
return CGSizeMake(width, height);
|
||||||
|
}
|
||||||
|
return size;
|
||||||
|
}
|
||||||
|
|
||||||
|
- (void)layoutSelf:(CGSize)targetSize {
|
||||||
|
[super layoutSelf:targetSize];
|
||||||
|
[self.subviews forEachIndexed:^(__kindof UIView *obj, NSUInteger idx) {
|
||||||
|
obj.left = idx * self.width;
|
||||||
|
}];
|
||||||
|
[self setContentSize:CGSizeMake(self.subviews.count * self.width, self.height)];
|
||||||
|
}
|
||||||
|
@end
|
||||||
|
|
||||||
|
@interface DoricNestedSliderNode () <UIScrollViewDelegate>
|
||||||
|
@property(nonatomic, copy) NSString *onPageSelectedFuncId;
|
||||||
|
@property(nonatomic, assign) NSUInteger lastPosition;
|
||||||
|
@end
|
||||||
|
|
||||||
|
@implementation DoricNestedSliderNode
|
||||||
|
- (UIScrollView *)build {
|
||||||
|
return [[DoricNestedSliderView new] also:^(DoricNestedSliderView *it) {
|
||||||
|
it.delegate = self;
|
||||||
|
it.pagingEnabled = YES;
|
||||||
|
[it setShowsVerticalScrollIndicator:NO];
|
||||||
|
[it setShowsHorizontalScrollIndicator:NO];
|
||||||
|
}];
|
||||||
|
}
|
||||||
|
|
||||||
|
- (void)blendView:(UIScrollView *)view forPropName:(NSString *)name propValue:(id)prop {
|
||||||
|
if ([@"onPageSlided" isEqualToString:name]) {
|
||||||
|
self.onPageSelectedFuncId = prop;
|
||||||
|
} else {
|
||||||
|
[super blendView:view forPropName:name propValue:prop];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
- (void)scrollViewDidEndDecelerating:(UIScrollView *)scrollView {
|
||||||
|
NSUInteger pageIndex = (NSUInteger) (scrollView.contentOffset.x / scrollView.width);
|
||||||
|
[scrollView setContentOffset:CGPointMake(pageIndex * scrollView.width, scrollView.contentOffset.y) animated:YES];
|
||||||
|
if (self.onPageSelectedFuncId && self.onPageSelectedFuncId.length > 0) {
|
||||||
|
if (pageIndex != self.lastPosition) {
|
||||||
|
[self callJSResponse:self.onPageSelectedFuncId, @(pageIndex), nil];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
self.lastPosition = pageIndex;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
- (void)slidePage:(NSDictionary *)params withPromise:(DoricPromise *)promise {
|
||||||
|
NSUInteger pageIndex = [params[@"page"] unsignedIntegerValue];
|
||||||
|
BOOL smooth = [params[@"smooth"] boolValue];
|
||||||
|
[self.view setContentOffset:CGPointMake(pageIndex * self.view.width, self.view.contentOffset.y) animated:smooth];
|
||||||
|
[promise resolve:nil];
|
||||||
|
self.lastPosition = pageIndex;
|
||||||
|
if (self.onPageSelectedFuncId && self.onPageSelectedFuncId.length > 0) {
|
||||||
|
[self callJSResponse:self.onPageSelectedFuncId, @(pageIndex), nil];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
- (NSNumber *)getSlidedPage {
|
||||||
|
NSUInteger pageIndex = (NSUInteger) (self.view.contentOffset.x / self.view.width);
|
||||||
|
return @(pageIndex);
|
||||||
|
}
|
||||||
|
@end
|
Reference in New Issue
Block a user