Skip to content

Commit c509ae7

Browse files
committed
fix bug #1
1 parent fde1698 commit c509ae7

10 files changed

+1493
-66
lines changed
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
//
2+
// RCTMJScrollContentShadowView.h
3+
// RCTMJRefreshHeader
4+
//
5+
// Created by Macbook on 2018/7/6.
6+
// Copyright © 2018年 Macbook. All rights reserved.
7+
//
8+
9+
#import <UIKit/UIKit.h>
10+
11+
#import <React/RCTShadowView.h>
12+
13+
@interface RCTMJScrollContentShadowView : RCTShadowView
14+
15+
@end
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
/**
2+
* Copyright (c) 2015-present, Facebook, Inc.
3+
*
4+
* This source code is licensed under the MIT license found in the
5+
* LICENSE file in the root directory of this source tree.
6+
*/
7+
8+
#import "RCTMJScrollContentShadowView.h"
9+
10+
#import <yoga/Yoga.h>
11+
12+
#import <React/RCTUtils.h>
13+
14+
@implementation RCTMJScrollContentShadowView
15+
16+
- (void)layoutWithMetrics:(RCTLayoutMetrics)layoutMetrics
17+
layoutContext:(RCTLayoutContext)layoutContext
18+
{
19+
if (layoutMetrics.layoutDirection == UIUserInterfaceLayoutDirectionRightToLeft) {
20+
// Motivation:
21+
// Yoga place `contentView` on the right side of `scrollView` when RTL layout is enfoced.
22+
// That breaks everything; it is completely pointless to (re)position `contentView`
23+
// because it is `contentView`'s job. So, we work around it here.
24+
25+
layoutContext.absolutePosition.x += layoutMetrics.frame.size.width;
26+
layoutMetrics.frame.origin.x = 0;
27+
}
28+
29+
[super layoutWithMetrics:layoutMetrics layoutContext:layoutContext];
30+
}
31+
32+
@end
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
//
2+
// RCTMJScrollContentView.h
3+
// RCTMJRefreshHeader
4+
//
5+
// Created by Macbook on 2018/7/6.
6+
// Copyright © 2018年 Macbook. All rights reserved.
7+
//
8+
#import <React/RCTView.h>
9+
@interface RCTMJScrollContentView : RCTView
10+
11+
@end
12+
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
//
2+
// RCTMJScrollContentView.m
3+
// RCTMJRefreshHeader
4+
//
5+
// Created by Macbook on 2018/7/6.
6+
// Copyright © 2018年 Macbook. All rights reserved.
7+
//
8+
9+
#import <Foundation/Foundation.h>
10+
#import <React/RCTView.h>
11+
#import <React/RCTAssert.h>
12+
#import <React/UIView+React.h>
13+
14+
#import "RCTMJScrollView.h"
15+
#import "RCTMJScrollContentView.h"
16+
17+
18+
@implementation RCTMJScrollContentView
19+
20+
- (void)reactSetFrame:(CGRect)frame
21+
{
22+
[super reactSetFrame:frame];
23+
24+
RCTMJScrollView *scrollView = (RCTMJScrollView *)self.superview.superview;
25+
26+
if (!scrollView) {
27+
return;
28+
}
29+
30+
RCTAssert([scrollView isKindOfClass:[RCTMJScrollView class]],
31+
@"Unexpected view hierarchy of RCTScrollView component.");
32+
33+
[scrollView updateContentOffsetIfNeeded];
34+
}
35+
36+
@end
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
//
2+
// RCTMJScrollContentViewMananger.m
3+
// RCTMJRefreshHeader
4+
//
5+
// Created by Macbook on 2018/7/6.
6+
// Copyright © 2018年 Macbook. All rights reserved.
7+
//
8+
9+
#import <Foundation/Foundation.h>
10+
#import <React/RCTViewManager.h>
11+
12+
#import "RCTMJScrollContentShadowView.h"
13+
#import "RCTMJScrollContentView.h"
14+
15+
@interface RCTMJScrollContentViewManager : RCTViewManager
16+
17+
@end
18+
19+
20+
@implementation RCTMJScrollContentViewManager
21+
22+
RCT_EXPORT_MODULE()
23+
24+
- (RCTMJScrollContentView *)view
25+
{
26+
return [RCTMJScrollContentView new];
27+
}
28+
29+
- (RCTShadowView *)shadowView
30+
{
31+
return [RCTMJScrollContentShadowView new];
32+
}
33+
34+
@end
Lines changed: 73 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,75 @@
1-
//
2-
// RCTMJScrollView.h
3-
// React
4-
//
5-
// Created by Macbook on 2018/6/22.
6-
// Copyright © 2018年 Facebook. All rights reserved.
7-
//
8-
#import <React/RCTScrollView.h>
9-
10-
@interface RCTMJScrollView:RCTScrollView
1+
/**
2+
* Copyright (c) 2015-present, Facebook, Inc.
3+
*
4+
* This source code is licensed under the MIT license found in the
5+
* LICENSE file in the root directory of this source tree.
6+
*/
7+
8+
#import <UIKit/UIScrollView.h>
9+
10+
#import <React/RCTAutoInsetsProtocol.h>
11+
#import <React/RCTEventDispatcher.h>
12+
#import <React/RCTScrollableProtocol.h>
13+
#import <React/RCTView.h>
14+
15+
@protocol UIScrollViewDelegate;
16+
17+
@interface RCTMJScrollView : RCTView <UIScrollViewDelegate, RCTScrollableProtocol, RCTAutoInsetsProtocol>
18+
1119
- (instancetype)initWithEventDispatcher:(RCTEventDispatcher *)eventDispatcher NS_DESIGNATED_INITIALIZER;
20+
21+
/**
22+
* The `RCTScrollView` may have at most one single subview. This will ensure
23+
* that the scroll view's `contentSize` will be efficiently set to the size of
24+
* the single subview's frame. That frame size will be determined somewhat
25+
* efficiently since it will have already been computed by the off-main-thread
26+
* layout system.
27+
*/
28+
@property (nonatomic, readonly) UIView *contentView;
29+
30+
/**
31+
* If the `contentSize` is not specified (or is specified as {0, 0}, then the
32+
* `contentSize` will automatically be determined by the size of the subview.
33+
*/
34+
@property (nonatomic, assign) CGSize contentSize;
35+
36+
/**
37+
* The underlying scrollView (TODO: can we remove this?)
38+
*/
39+
@property (nonatomic, readonly) UIScrollView *scrollView;
40+
41+
@property (nonatomic, assign) UIEdgeInsets contentInset;
42+
@property (nonatomic, assign) BOOL automaticallyAdjustContentInsets;
43+
@property (nonatomic, assign) BOOL DEPRECATED_sendUpdatedChildFrames;
44+
@property (nonatomic, assign) NSTimeInterval scrollEventThrottle;
45+
@property (nonatomic, assign) BOOL centerContent;
46+
@property (nonatomic, copy) NSDictionary *maintainVisibleContentPosition;
47+
@property (nonatomic, assign) int snapToInterval;
48+
@property (nonatomic, copy) NSString *snapToAlignment;
49+
50+
// NOTE: currently these event props are only declared so we can export the
51+
// event names to JS - we don't call the blocks directly because scroll events
52+
// need to be coalesced before sending, for performance reasons.
53+
@property (nonatomic, copy) RCTDirectEventBlock onScrollBeginDrag;
54+
@property (nonatomic, copy) RCTDirectEventBlock onScroll;
55+
@property (nonatomic, copy) RCTDirectEventBlock onScrollEndDrag;
56+
@property (nonatomic, copy) RCTDirectEventBlock onMomentumScrollBegin;
57+
@property (nonatomic, copy) RCTDirectEventBlock onMomentumScrollEnd;
58+
59+
@end
60+
61+
@interface RCTMJScrollView (Internal)
62+
63+
- (void)updateContentOffsetIfNeeded;
64+
1265
@end
66+
67+
@interface RCTEventDispatcher (RCTMJScrollView)
68+
69+
/**
70+
* Send a fake scroll event.
71+
*/
72+
- (void)sendFakeScrollEvent:(NSNumber *)reactTag;
73+
74+
@end
75+

0 commit comments

Comments
 (0)