Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,11 @@ import android.view.accessibility.AccessibilityEvent
import android.view.accessibility.AccessibilityNodeInfo
import android.widget.FrameLayout
import androidx.annotation.UiThread
import androidx.core.view.ViewCompat
import androidx.core.content.ContextCompat
import androidx.core.view.WindowCompat
import androidx.core.view.WindowInsetsCompat
import androidx.core.view.WindowInsetsCompat.CONSUMED
import com.facebook.common.logging.FLog
import com.facebook.react.R
import com.facebook.react.bridge.GuardedRunnable
Expand All @@ -40,6 +43,7 @@ import com.facebook.react.bridge.WritableNativeMap
import com.facebook.react.common.ReactConstants
import com.facebook.react.common.annotations.VisibleForTesting
import com.facebook.react.config.ReactFeatureFlags
import com.facebook.react.uimanager.DisplayMetricsHolder
import com.facebook.react.uimanager.JSPointerDispatcher
import com.facebook.react.uimanager.JSTouchDispatcher
import com.facebook.react.uimanager.PixelUtil.pxToDp
Expand All @@ -52,6 +56,7 @@ import com.facebook.react.views.common.ContextUtils
import com.facebook.react.views.view.ReactViewGroup
import com.facebook.react.views.view.setStatusBarTranslucency
import com.facebook.react.views.view.setSystemBarsTranslucency
import com.facebook.yoga.annotations.DoNotStrip
import java.util.Objects

/**
Expand Down Expand Up @@ -122,6 +127,7 @@ public class ReactModalHostView(context: ThemedReactContext) :
private var createNewDialog = false

init {
initStatusBarHeight(context)
dialogRootViewGroup = DialogRootViewGroup(context)
}

Expand Down Expand Up @@ -412,6 +418,18 @@ public class ReactModalHostView(context: ThemedReactContext) :
}
}

private fun initStatusBarHeight(reactContext: ReactContext) {
val windowInsets =
reactContext.getCurrentActivity()?.window?.decorView?.let(ViewCompat::getRootWindowInsets)
statusBarHeight =
windowInsets
?.getInsets(
WindowInsetsCompat.Type.statusBars() or
WindowInsetsCompat.Type.navigationBars() or
WindowInsetsCompat.Type.displayCutout())
?.top ?: 0
}

/**
* Sets the testID on the DialogRootViewGroup. Since the accessibility events are not triggered on
* the on the ReactModalHostView, the testID is forwarded to the DialogRootViewGroup to set the
Expand All @@ -430,8 +448,22 @@ public class ReactModalHostView(context: ThemedReactContext) :

private companion object {
private const val TAG = "ReactModalHost"

// We store the status bar height to be able to properly position
// the modal on the first render.
private var statusBarHeight = 0

@JvmStatic
@DoNotStrip
private fun getScreenDisplayMetricsWithoutInsets(): FloatArray {
val displayMetrics = DisplayMetricsHolder.getScreenDisplayMetrics()
return floatArrayOf(
displayMetrics.widthPixels.toFloat().pxToDp(),
(displayMetrics.heightPixels - statusBarHeight).toFloat().pxToDp())
}
}


/**
* DialogRootViewGroup is the ViewGroup which contains all the children of a Modal. It gets all
* child information forwarded from [ReactModalHostView] and uses that to create children. It is
Expand Down Expand Up @@ -568,3 +600,4 @@ public class ReactModalHostView(context: ThemedReactContext) :
}
}
}

Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,10 @@ add_compile_options(
-Wpedantic
-DLOG_TAG=\"Fabric\")

file(GLOB rrc_modal_SRC CONFIGURE_DEPENDS *.cpp)
file(GLOB rrc_modal_SRC CONFIGURE_DEPENDS
*.cpp
platform/android/*.cpp)

add_library(rrc_modal STATIC ${rrc_modal_SRC})

target_include_directories(rrc_modal PUBLIC ${REACT_COMMON_DIR})
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,13 @@

#include <react/renderer/core/graphicsConversions.h>
#include <react/renderer/graphics/Float.h>
#include "ModalHostViewUtils.h"

#ifdef ANDROID
#include <folly/dynamic.h>
#endif

#if defined(__APPLE__) && TARGET_OS_IOS
#include "ModalHostViewUtils.h"
#endif

namespace facebook::react {

Expand All @@ -27,12 +26,7 @@ class ModalHostViewState final {
public:
using Shared = std::shared_ptr<const ModalHostViewState>;

#if defined(__APPLE__) && TARGET_OS_IOS
ModalHostViewState() : screenSize(RCTModalHostViewScreenSize()) {
#else
ModalHostViewState(){
#endif
};
ModalHostViewState() : screenSize(RCTModalHostViewScreenSize()) {}
ModalHostViewState(Size screenSize_) : screenSize(screenSize_){};

#ifdef ANDROID
Expand All @@ -54,3 +48,4 @@ class ModalHostViewState final {
};

} // namespace facebook::react

Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

#pragma once

#include <react/renderer/core/graphicsConversions.h>
#include <react/renderer/graphics/Size.h>

namespace facebook::react {

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
/*
* Copyright (c) Meta Platforms, Inc. and affiliates.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*/

#pragma once

#include <fbjni/fbjni.h>
#include <react/renderer/graphics/Size.h>

#include <android/log.h>

namespace facebook::react {

class JReactModalHostView
: public facebook::jni::JavaClass<JReactModalHostView> {
public:
static auto constexpr kJavaDescriptor =
"Lcom/facebook/react/views/modal/ReactModalHostView;";

static Size getDisplayMetrics() {
static auto method = JReactModalHostView::javaClassStatic()
->getStaticMethod<jni::JArrayFloat()>(
"getScreenDisplayMetricsWithoutInsets");
auto result = method(javaClassStatic());
size_t size = result->size();
std::vector<jfloat> elements(size + 1L);
result->getRegion(0, size, elements.data());
return Size{elements[0], elements[1]};
}
};

} // namespace facebook::react
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
/*
* Copyright (c) Meta Platforms, Inc. and affiliates.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*/

#include <react/renderer/components/modal/ModalHostViewUtils.h>
#include "JReactModalHostView.h"

namespace facebook::react {

Size RCTModalHostViewScreenSize(void) {
return JReactModalHostView::getDisplayMetrics();
}

} // namespace facebook::react
Loading