RCTScrollContentShadowView.m 975 B

12345678910111213141516171819202122232425262728293031
  1. /*
  2. * Copyright (c) Facebook, Inc. and its affiliates.
  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. #import "RCTScrollContentShadowView.h"
  8. #import <yoga/Yoga.h>
  9. #import "RCTUtils.h"
  10. @implementation RCTScrollContentShadowView
  11. - (void)layoutWithMetrics:(RCTLayoutMetrics)layoutMetrics layoutContext:(RCTLayoutContext)layoutContext
  12. {
  13. if (layoutMetrics.layoutDirection == UIUserInterfaceLayoutDirectionRightToLeft) {
  14. // Motivation:
  15. // Yoga place `contentView` on the right side of `scrollView` when RTL layout is enforced.
  16. // That breaks everything; it is completely pointless to (re)position `contentView`
  17. // because it is `contentView`'s job. So, we work around it here.
  18. layoutContext.absolutePosition.x += layoutMetrics.frame.size.width;
  19. layoutMetrics.frame.origin.x = 0;
  20. }
  21. [super layoutWithMetrics:layoutMetrics layoutContext:layoutContext];
  22. }
  23. @end