mirror of
https://github.com/status-im/react-native.git
synced 2025-01-14 03:26:07 +00:00
Fixed ScrollView's .scrollToEnd to refrain from exceeding start boundary.
Summary: Thanks for submitting a pull request! Please provide enough information so that others can review your pull request: > **Unless you are a React Native release maintainer and cherry-picking an *existing* commit into a current release, ensure your pull request is targeting the `master` React Native branch.** Explain the **motivation** for making this change. What existing problem does the pull request solve? The problem occurs when a ScrollView's content height is smaller than the ScrollView height. If the method `scrollToEnd` is called on the ScrollView, it will pull the content down until the bottom of the content is aligned with the bottom of the Scrollview container. This fix will ensure the proper functionality: That the furthest the ScrollView can scroll down is to where the top of the content container is at the origin (i.e., the ScrollView scroll number cannot be less than 0). Prefer **small pull requests**. These are much easier to review and more likely to get merged. Make sure the PR does only one thing, otherwise please split it. **Test plan (required)** Demonstrate the code is solid. Example: The exact commands you ran and their output, screenshots / videos if the pull request changes UI. Make sure tests pass on both Travis and Circle CI. I tested on a scenario where the ScrollView is almost the full size of the screen, and the content of the ScrollView has a height of much less. In this situation, the `scrollToEnd` method was executed and the content stayed in the same position. This is the intended behavior. If the content of the ScrollView is smaller than the height of the ScrollView, then the `scrollToEnd` method should not scroll anywhere. **Code formatting** Look around. Match the style of the rest of the codebase. See also the simple [style guide](https://github.com/facebook/react-native/blob/master/CONTRIBUTING.md#style-guide). For more info, see the ["Pull Requests" section of our "Contributing" guidelines](https://github.com/facebook/react-native/blob/master/CONTRIBUTING.md#pull-requests). Closes https://github.com/facebook/react-native/pull/12889 Reviewed By: javache Differential Revision: D5289894 Pulled By: sahrens fbshipit-source-id: df2e779ee855c1dea85d33649d754371ad244bca
This commit is contained in:
parent
4566f01fbd
commit
502604074c
@ -525,11 +525,11 @@ static inline void RCTApplyTranformationAccordingLayoutDirection(UIView *view, U
|
||||
BOOL isHorizontal = [self isHorizontal:_scrollView];
|
||||
CGPoint offset;
|
||||
if (isHorizontal) {
|
||||
CGFloat offsetX = _scrollView.contentSize.width - _scrollView.bounds.size.width;
|
||||
offset = CGPointMake(MAX(offsetX, 0), 0);
|
||||
CGFloat offsetX = _scrollView.contentSize.width - _scrollView.bounds.size.width + _scrollView.contentInset.right;
|
||||
offset = CGPointMake(fmax(offsetX, 0), 0);
|
||||
} else {
|
||||
CGFloat offsetY = _scrollView.contentSize.height - _scrollView.bounds.size.height;
|
||||
offset = CGPointMake(0, MAX(offsetY, 0));
|
||||
CGFloat offsetY = _scrollView.contentSize.height - _scrollView.bounds.size.height + _scrollView.contentInset.bottom;
|
||||
offset = CGPointMake(0, fmax(offsetY, 0));
|
||||
}
|
||||
if (!CGPointEqualToPoint(_scrollView.contentOffset, offset)) {
|
||||
// Ensure at least one scroll event will fire
|
||||
|
Loading…
x
Reference in New Issue
Block a user