diff --git a/React/Views/RCTScrollContentView.h b/React/Views/RCTScrollContentView.h new file mode 100644 index 00000000000000..f25250cc5f8269 --- /dev/null +++ b/React/Views/RCTScrollContentView.h @@ -0,0 +1,16 @@ +/** + * Copyright (c) 2015-present, Facebook, Inc. + * All rights reserved. + * + * This source code is licensed under the BSD-style license found in the + * LICENSE file in the root directory of this source tree. An additional grant + * of patent rights can be found in the PATENTS file in the same directory. + */ + +#import + +#import + +@interface RCTScrollContentView : RCTView + +@end diff --git a/React/Views/RCTScrollContentView.m b/React/Views/RCTScrollContentView.m new file mode 100644 index 00000000000000..a7fb9d2180e18d --- /dev/null +++ b/React/Views/RCTScrollContentView.m @@ -0,0 +1,35 @@ +/** + * Copyright (c) 2015-present, Facebook, Inc. + * All rights reserved. + * + * This source code is licensed under the BSD-style license found in the + * LICENSE file in the root directory of this source tree. An additional grant + * of patent rights can be found in the PATENTS file in the same directory. + */ + +#import "RCTScrollContentView.h" + +#import +#import + +#import "RCTScrollView.h" + +@implementation RCTScrollContentView + +- (void)reactSetFrame:(CGRect)frame +{ + [super reactSetFrame:frame]; + + RCTScrollView *scrollView = (RCTScrollView *)self.superview.superview; + + if (!scrollView) { + return; + } + + RCTAssert([scrollView isKindOfClass:[RCTScrollView class]], + @"Unexpected view hierarchy of RCTScrollView component."); + + [scrollView updateContentOffsetIfNeeded]; +} + +@end diff --git a/React/Views/RCTScrollContentViewManager.m b/React/Views/RCTScrollContentViewManager.m index 5639b4fc9ef0ee..18585fb88d1f11 100644 --- a/React/Views/RCTScrollContentViewManager.m +++ b/React/Views/RCTScrollContentViewManager.m @@ -10,11 +10,17 @@ #import "RCTScrollContentViewManager.h" #import "RCTScrollContentShadowView.h" +#import "RCTScrollContentView.h" @implementation RCTScrollContentViewManager RCT_EXPORT_MODULE() +- (RCTScrollContentView *)view +{ + return [RCTScrollContentView new]; +} + - (RCTShadowView *)shadowView { return [RCTScrollContentShadowView new]; diff --git a/React/Views/RCTScrollView.h b/React/Views/RCTScrollView.h index 091c8885b7834f..90b8e3700f093b 100644 --- a/React/Views/RCTScrollView.h +++ b/React/Views/RCTScrollView.h @@ -59,6 +59,12 @@ @end +@interface RCTScrollView (Internal) + +- (void)updateContentOffsetIfNeeded; + +@end + @interface RCTEventDispatcher (RCTScrollView) /** diff --git a/React/Views/RCTScrollView.m b/React/Views/RCTScrollView.m index 96fea689c77e15..fb3d5f2efebc0e 100644 --- a/React/Views/RCTScrollView.m +++ b/React/Views/RCTScrollView.m @@ -466,6 +466,13 @@ - (void)didUpdateReactSubviews // Do nothing, as subviews are managed by `insertReactSubview:atIndex:` } +- (void)didSetProps:(NSArray *)changedProps +{ + if ([changedProps containsObject:@"contentSize"]) { + [self updateContentOffsetIfNeeded]; + } +} + - (BOOL)centerContent { return _scrollView.centerContent; @@ -882,7 +889,7 @@ - (CGSize)contentSize return _contentView.frame.size; } -- (void)reactBridgeDidFinishTransaction +- (void)updateContentOffsetIfNeeded { CGSize contentSize = self.contentSize; if (!CGSizeEqualToSize(_scrollView.contentSize, contentSize)) {