1. /**
    
  2.  * Copyright (c) Meta Platforms, Inc. and 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.  * @flow
    
  8.  */
    
  9. 
    
  10. import type {Layouter} from '../layouter';
    
  11. 
    
  12. /**
    
  13.  * Assumes {@param layout} will only contain 2 views.
    
  14.  */
    
  15. export const withVerticalScrollbarLayout: Layouter = (
    
  16.   layout,
    
  17.   containerFrame,
    
  18. ) => {
    
  19.   const [contentLayoutInfo, scrollbarLayoutInfo] = layout;
    
  20. 
    
  21.   const desiredContentSize = contentLayoutInfo.view.desiredSize();
    
  22.   const shouldShowScrollbar =
    
  23.     desiredContentSize.height > containerFrame.size.height;
    
  24.   const scrollbarWidth = shouldShowScrollbar
    
  25.     ? scrollbarLayoutInfo.view.desiredSize().width
    
  26.     : 0;
    
  27. 
    
  28.   const laidOutContentLayoutInfo = {
    
  29.     ...contentLayoutInfo,
    
  30.     frame: {
    
  31.       origin: contentLayoutInfo.view.frame.origin,
    
  32.       size: {
    
  33.         width: containerFrame.size.width - scrollbarWidth,
    
  34.         height: containerFrame.size.height,
    
  35.       },
    
  36.     },
    
  37.   };
    
  38.   const laidOutScrollbarLayoutInfo = {
    
  39.     ...scrollbarLayoutInfo,
    
  40.     frame: {
    
  41.       origin: {
    
  42.         x:
    
  43.           laidOutContentLayoutInfo.frame.origin.x +
    
  44.           laidOutContentLayoutInfo.frame.size.width,
    
  45.         y: containerFrame.origin.y,
    
  46.       },
    
  47.       size: {
    
  48.         width: scrollbarWidth,
    
  49.         height: containerFrame.size.height,
    
  50.       },
    
  51.     },
    
  52.   };
    
  53. 
    
  54.   return [laidOutContentLayoutInfo, laidOutScrollbarLayoutInfo];
    
  55. };