Skip to content

Commit

Permalink
Fixed improper content sizing on contentSize change.
Browse files Browse the repository at this point in the history
  • Loading branch information
MichaelDanielTom committed Mar 16, 2018
1 parent 4679001 commit 0d70bac
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 3 deletions.
18 changes: 15 additions & 3 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,14 +34,26 @@ const ScrollView = createReactClass({
[animated !== false],
);
},
updateContentOffsetIfNeeded: function() {
setTimeout(() => {
UIManager.dispatchViewManagerCommand(
this.getScrollableNode(),
UIManager.DirectedScrollView.Commands.updateContentOffsetIfNeeded,
[],
);
}, 0);
},
_scrollViewRef: null,
_setScrollViewRef: function(ref) {
this._scrollViewRef = ref;
},
componentDidMount: function() {
setTimeout(() => {
this.zoomToStart({animated: false});
}, 0);
this.updateContentOffsetIfNeeded();
},
componentDidUpdate: function(prevProps, prevState) {
if (this.props.contentContainerStyle != prevProps.contentContainerStyle) {
this.updateContentOffsetIfNeeded();
}
},
render: function() {
return (
Expand Down
12 changes: 12 additions & 0 deletions ios/RCTDirectedScrollView/DirectedScrollViewManager.m
Original file line number Diff line number Diff line change
Expand Up @@ -159,4 +159,16 @@ -(void)scrollViewDidEndDragging {
}];
}

RCT_EXPORT_METHOD(updateContentOffsetIfNeeded:(nonnull NSNumber *)reactTag) {
[self.bridge.uiManager addUIBlock:
^(__unused RCTUIManager *uiManager, NSDictionary<NSNumber *, UIView *> *viewRegistry){
UIView *view = viewRegistry[reactTag];
if ([view isKindOfClass:[RCTScrollView class]]) {
[(RCTScrollView *)view updateContentOffsetIfNeeded];
} else {
RCTLogError(@"tried to didResizeContent: on non-RCTScrollView %@ with tag #%@", view, reactTag);
}
}];
}

@end

0 comments on commit 0d70bac

Please sign in to comment.