mirror of
https://github.com/Tencent/Hippy.git
synced 2026-10-27 20:47:20 +08:00
feat(ios): add method to create custom scrollview (#2839)
This commit is contained in:
@@ -29,10 +29,22 @@
|
||||
|
||||
@protocol UIScrollViewDelegate;
|
||||
|
||||
@interface HippyCustomScrollView : UIScrollView <UIGestureRecognizerDelegate>
|
||||
|
||||
@property (nonatomic, assign) BOOL centerContent;
|
||||
|
||||
@end
|
||||
|
||||
@interface HippyScrollView : HippyView <UIScrollViewDelegate, HippyScrollableProtocol, HippyAutoInsetsProtocol, HippyInvalidating>
|
||||
|
||||
- (instancetype)initWithEventDispatcher:(HippyEventDispatcher *)eventDispatcher NS_DESIGNATED_INITIALIZER;
|
||||
|
||||
/**
|
||||
* This is where subclasses should create their custom scroll view hierarchy if they dont want to use default scroll view.
|
||||
* Should never be called directly.
|
||||
*/
|
||||
- (HippyCustomScrollView *)loadScrollView;
|
||||
|
||||
/**
|
||||
* The `HippyScrollView` may have at most one single subview. This will ensure
|
||||
* that the scroll view's `contentSize` will be efficiently set to the size of
|
||||
@@ -49,7 +61,7 @@
|
||||
@property (nonatomic, assign) CGSize contentSize;
|
||||
|
||||
/**
|
||||
* The underlying scrollView (TODO: can we remove this?)
|
||||
* Get the underlying scrollview.
|
||||
*/
|
||||
@property (nonatomic, readonly) UIScrollView *scrollView;
|
||||
|
||||
|
||||
@@ -33,12 +33,6 @@
|
||||
#import "HippyI18nUtils.h"
|
||||
#import "objc/runtime.h"
|
||||
|
||||
@interface HippyCustomScrollView : UIScrollView <UIGestureRecognizerDelegate>
|
||||
|
||||
@property (nonatomic, assign) BOOL centerContent;
|
||||
|
||||
@end
|
||||
|
||||
@implementation HippyCustomScrollView
|
||||
|
||||
- (instancetype)initWithFrame:(CGRect)frame {
|
||||
@@ -168,7 +162,7 @@ static inline BOOL CGPointIsNull(CGPoint point) {
|
||||
|
||||
@end
|
||||
|
||||
@implementation HippyScrollView {
|
||||
@interface HippyScrollView() {
|
||||
HippyCustomScrollView *_scrollView;
|
||||
UIView *_contentView;
|
||||
NSTimeInterval _lastScrollDispatchTime;
|
||||
@@ -184,13 +178,14 @@ static inline BOOL CGPointIsNull(CGPoint point) {
|
||||
__weak HippyRootView *_rootView;
|
||||
}
|
||||
|
||||
@end
|
||||
|
||||
@implementation HippyScrollView
|
||||
|
||||
- (instancetype)initWithEventDispatcher:(HippyEventDispatcher *)eventDispatcher {
|
||||
HippyAssertParam(eventDispatcher);
|
||||
|
||||
if ((self = [super initWithFrame:CGRectZero])) {
|
||||
_scrollView = [[HippyCustomScrollView alloc] initWithFrame:CGRectZero];
|
||||
_scrollView.delegate = self;
|
||||
_scrollView.delaysContentTouches = NO;
|
||||
_automaticallyAdjustContentInsets = YES;
|
||||
_contentInset = UIEdgeInsetsZero;
|
||||
_contentSize = CGSizeZero;
|
||||
@@ -202,6 +197,7 @@ static inline BOOL CGPointIsNull(CGPoint point) {
|
||||
_scrollListeners = [NSHashTable weakObjectsHashTable];
|
||||
_contentOffsetCache = [NSMutableDictionary dictionaryWithCapacity:32];
|
||||
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(didReceiveMemoryWarning) name:UIApplicationDidReceiveMemoryWarningNotification object:nil];
|
||||
_scrollView = [self loadScrollView];
|
||||
[self addSubview:_scrollView];
|
||||
if ([self needsLayoutForRTL]) {
|
||||
_scrollView.transform = CGAffineTransformMakeRotation(M_PI);
|
||||
@@ -210,6 +206,13 @@ static inline BOOL CGPointIsNull(CGPoint point) {
|
||||
return self;
|
||||
}
|
||||
|
||||
- (HippyCustomScrollView *)loadScrollView {
|
||||
HippyCustomScrollView *scrollview = [[HippyCustomScrollView alloc] initWithFrame:CGRectZero];
|
||||
scrollview.delegate = self;
|
||||
scrollview.delaysContentTouches = NO;
|
||||
return scrollview;
|
||||
}
|
||||
|
||||
- (void)didReceiveMemoryWarning {
|
||||
[_contentOffsetCache removeAllObjects];
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user