| 2167 | directionAgnosticDisplacement.x = directionAgnosticVisual.x + size.width - parentFrame.width; |
| 2168 | } |
| 2169 | if (directionAgnosticVisual.y < 0) { |
| 2170 | directionAgnosticDisplacement.y = directionAgnosticVisual.y; |
| 2171 | } else if (directionAgnosticVisual.y + size.height > parentFrame.height) { |
| 2172 | directionAgnosticDisplacement.y = directionAgnosticVisual.y + size.height - parentFrame.height; |
| 2173 | } |
| 2174 | // Apply the displacement |
| 2175 | parent->setScrollContentOffset( |
| 2176 | viewTransactionScope, directionAgnosticContentOffset + directionAgnosticDisplacement, animated); |
| 2177 | // Make sure the scrollview is visible also |
| 2178 | parent->ensureFrameIsVisibleWithinParentScrolls(viewTransactionScope, animated); |
| 2179 | } else { |
| 2180 | // Make sure we're also visible in parent's parents |
| 2181 | parent->ensureFrameIsVisibleWithinParentScrolls(viewTransactionScope, directionAgnosticVisual, size, animated); |
| 2182 | } |
| 2183 | } |
| 2184 | |
| 2185 | bool ViewNode::scrollByOnePage(ViewTransactionScope& viewTransactionScope, |
| 2186 | ScrollDirection scrollDirection, |
| 2187 | bool animated, |
| 2188 | float* outScrollPageCurrent, |
| 2189 | float* outScrollPageMaximum) { |
| 2190 | float canScrollDistance = getCanScrollDistance(scrollDirection); |
| 2191 | if (canScrollDistance > 0 && _scrollState != nullptr) { |
| 2192 | auto frame = getCalculatedFrame(); |
| 2193 | |
| 2194 | auto directionDependentContentDisplacement = Point(0, 0); |
| 2195 | switch (simplifyScrollDirection(scrollDirection)) { |
| 2196 | case SimplifiedScrollDirectionTopToBottom: |
| 2197 | directionDependentContentDisplacement.y = std::min(frame.height, canScrollDistance); |
| 2198 | break; |
| 2199 | case SimplifiedScrollDirectionBottomToTop: |
| 2200 | directionDependentContentDisplacement.y = -std::min(frame.height, canScrollDistance); |
| 2201 | break; |
| 2202 | case SimplifiedScrollDirectionLeftToRight: |
| 2203 | directionDependentContentDisplacement.x = std::min(frame.width, canScrollDistance); |
| 2204 | break; |
| 2205 | case SimplifiedScrollDirectionRightToLeft: |
| 2206 | directionDependentContentDisplacement.x = -std::min(frame.width, canScrollDistance); |
| 2207 | break; |
| 2208 | } |
| 2209 | |
| 2210 | auto directionDependentContentOffset = _scrollState->getDirectionDependentContentOffset(); |
| 2211 | directionDependentContentOffset += directionDependentContentDisplacement; |
| 2212 | |
| 2213 | auto directionAgnosticContentOffset = |
| 2214 | _scrollState->resolveDirectionAgnosticContentOffset(directionDependentContentOffset); |
| 2215 | setScrollContentOffset(viewTransactionScope, directionAgnosticContentOffset, animated); |
| 2216 | |
| 2217 | if (outScrollPageCurrent != nullptr) { |
| 2218 | *outScrollPageCurrent = getPageNumberForContentOffset(directionAgnosticContentOffset); |
| 2219 | } |
| 2220 | if (outScrollPageMaximum != nullptr) { |
| 2221 | auto contentSize = _scrollState->getContentSize(); |
| 2222 | auto directionAgnosticContentMaximum = |
| 2223 | Point(contentSize.width - frame.width, contentSize.height - frame.height); |
| 2224 | *outScrollPageMaximum = getPageNumberForContentOffset(directionAgnosticContentMaximum); |
| 2225 | } |
| 2226 |
no test coverage detected