// Copyright 2004-present Facebook. All Rights Reserved.

package com.facebook.react.views.modal;

import android.annotation.TargetApi;
import android.content.Context;
import android.graphics.Point;
import android.view.Display;
import android.view.Surface;
import android.view.WindowManager;

import com.facebook.infer.annotation.Assertions;

/**
 * Helper class for Modals.
 */
/*package*/ class ModalHostHelper {

  private static final Point MIN_POINT = new Point();
  private static final Point MAX_POINT = new Point();

  /**
   * To get the size of the screen, we use information from the WindowManager and
   * default Display. We don't use DisplayMetricsHolder, or Display#getSize() because
   * they return values that include the status bar. We only want the values of what
   * will actually be shown on screen.
   * This should only be called on the native modules/shadow nodes thread.
   */
  @TargetApi(16)
  public static Point getModalHostSize(Context context) {
    WindowManager wm = (WindowManager) context.getSystemService(Context.WINDOW_SERVICE);
    Display display = Assertions.assertNotNull(wm).getDefaultDisplay();
    // getCurrentSizeRange will return the min and max width and height that the window can be
    display.getCurrentSizeRange(MIN_POINT, MAX_POINT);

    final int rotation = display.getRotation();
    if (rotation == Surface.ROTATION_0 || rotation == Surface.ROTATION_180) {
      // If we are vertical the width value comes from min width and height comes from max height
      return new Point(MIN_POINT.x, MAX_POINT.y);
    } else {
      // If we are horizontal the width value comes from max width and height comes from min height
      return new Point(MAX_POINT.x, MIN_POINT.y);
    }
  }
}

@@ -225,37 +225,8 @@
 ay;%0A
-import android.view.Surface;%0A
 impo
@@ -487,16 +487,71 @@
 Point();
+%0A  private static final Point SIZE_POINT = new Point();
 %0A%0A  /**%0A
@@ -842,16 +842,221 @@
 screen.%0A
+   * We use Display#getSize() to determine if the screen is in portrait or landscape.%0A   * We don't use getRotation because the 'natural' rotation will be portrait on phones%0A   * and landscape on tablets.%0A
    * Thi
@@ -1518,33 +1518,94 @@
 T);%0A
-%0A
     
-final int ro
+// getSize will return the dimensions of the screen in its current orien
 tation
+%0A  
  
-=
  dis
@@ -1616,28 +1616,35 @@
 .get
-Rotation(
+Size(SIZE_POINT
 );%0A
+%0A
     if (
 rota
@@ -1643,74 +1643,35 @@
 if (
-rotation == Surface.ROTATION_0 %7C%7C rotation == Surface.ROTATION_180
+SIZE_POINT.x %3C SIZE_POINT.y
 ) %7B%0A

Fix Modal size on Android tablet