diff --git a/packages/react-native/Libraries/Modal/Modal.js b/packages/react-native/Libraries/Modal/Modal.js index dc855add3d06..6c8bed49edaa 100644 --- a/packages/react-native/Libraries/Modal/Modal.js +++ b/packages/react-native/Libraries/Modal/Modal.js @@ -80,8 +80,13 @@ type ModalBasePropsCore = { onShow?: ?DirectEventHandler, /** - * The backdrop color of the modal's container. Defaults to `white` if - * `transparent` is `false`. Ignored if `transparent` is `true`. + * The backdrop color of the modal's container. Ignored if `transparent` is + * `true`. On Android, this overrides the transparent background implied by + * an explicit `dimAmount`. + * + * @deprecated Prefer `style={{backgroundColor: ...}}` for the container + * color. On Android, keep using `backdropColor` if you need a custom color + * while setting `dimAmount`. */ backdropColor?: ColorValue, @@ -155,6 +160,27 @@ export type ModalPropsIOS = { }; export type ModalPropsAndroid = { + /** + * Size the native window to its content instead of filling the parent. + * The window is not shown and `onShow` does not fire until the content + * measures to a positive width and height. + * + * @default `false` + * @platform android + */ + contentSized?: ?boolean, + + /** + * Amount of system dimming behind the modal, between 0 and 1. + * Ignored if `transparent` is `true`. When set, the modal's container + * defaults to a transparent background instead of `white`, unless + * `backdropColor` is set. + * + * @default `0.5` + * @platform android + */ + dimAmount?: ?number, + /** * Controls whether to force hardware acceleration for the underlying window. * @@ -285,15 +311,17 @@ class Modal extends React.Component { return null; } - // Only override backgroundColor when transparent or backdropColor are - // explicitly set, so that these Modal-specific props take precedence - // over the generic style prop. The default backgroundColor ('white') - // is defined in styles.container below. + // Only override backgroundColor when transparent, backdropColor or + // dimAmount are explicitly set, so that these Modal-specific props take + // precedence over the generic style prop. The default backgroundColor + // ('white') is defined in styles.container below. const containerStyles: {backgroundColor?: ColorValue} = {}; if (this.props.transparent === true) { containerStyles.backgroundColor = 'transparent'; } else if (this.props.backdropColor != null) { containerStyles.backgroundColor = this.props.backdropColor; + } else if (Platform.OS === 'android' && this.props.dimAmount != null) { + containerStyles.backgroundColor = 'transparent'; } let animationType = this.props.animationType || 'none'; @@ -330,6 +358,8 @@ class Modal extends React.Component { animationType={animationType} presentationStyle={presentationStyle} transparent={this.props.transparent} + dimAmount={this.props.dimAmount} + contentSized={Platform.OS === 'android' && this.props.contentSized} hardwareAccelerated={this.props.hardwareAccelerated} onRequestClose={this.props.onRequestClose} onShow={this.props.onShow} @@ -351,7 +381,13 @@ class Modal extends React.Component { {innerChildren} diff --git a/packages/react-native/Libraries/Modal/__tests__/Modal-itest.js b/packages/react-native/Libraries/Modal/__tests__/Modal-itest.js index 34e268d2442a..1b799f3f2b65 100644 --- a/packages/react-native/Libraries/Modal/__tests__/Modal-itest.js +++ b/packages/react-native/Libraries/Modal/__tests__/Modal-itest.js @@ -49,6 +49,121 @@ describe('', () => { , ); }); + + describe('dimAmount', () => { + it('forwards a custom dim amount and resets to the default when removed', () => { + Fantom.runTask(() => { + root.render(); + }); + + expect(root.getRenderedOutput({props: ['dimAmount']}).toJSX()).toEqual( + + + , + ); + + Fantom.runTask(() => { + root.render(); + }); + + expect(root.getRenderedOutput({props: ['dimAmount']}).toJSX()).toEqual( + + + , + ); + }); + + it('defaults the container to a transparent background', () => { + Fantom.runTask(() => { + root.render(); + }); + + expect( + root.getRenderedOutput({props: ['backgroundColor']}).toJSX(), + ).toEqual( + + + , + ); + }); + + it('keeps an explicit backdropColor', () => { + Fantom.runTask(() => { + root.render(); + }); + + expect( + root.getRenderedOutput({props: ['backgroundColor']}).toJSX(), + ).toEqual( + + + , + ); + }); + }); + + describe('contentSized', () => { + it('forwards content sizing and resets when removed', () => { + Fantom.runTask(() => { + root.render(); + }); + + expect( + root.getRenderedOutput({props: ['contentSized']}).toJSX(), + ).toEqual( + + + , + ); + + Fantom.runTask(() => { + root.render(); + }); + + expect( + root.getRenderedOutput({props: ['contentSized']}).toJSX(), + ).toEqual( + + + , + ); + }); + + it('does not apply the default container style', () => { + Fantom.runTask(() => { + root.render(); + }); + + expect( + root + .getRenderedOutput({ + props: ['backgroundColor', 'flex', 'left', 'top'], + }) + .toJSX(), + ).toEqual( + + + , + ); + }); + + it('keeps a style backgroundColor', () => { + Fantom.runTask(() => { + root.render( + , + ); + }); + + expect( + root.getRenderedOutput({props: ['backgroundColor']}).toJSX(), + ).toEqual( + + + , + ); + }); + }); + describe('animationType', () => { it('renders a Modal with animationType="none" by default', () => { Fantom.runTask(() => { diff --git a/packages/react-native/ReactAndroid/api/ReactAndroid.api b/packages/react-native/ReactAndroid/api/ReactAndroid.api index e5609d383c48..644f2cf84909 100644 --- a/packages/react-native/ReactAndroid/api/ReactAndroid.api +++ b/packages/react-native/ReactAndroid/api/ReactAndroid.api @@ -5128,6 +5128,8 @@ public class com/facebook/react/viewmanagers/ModalHostViewManagerDelegate : com/ public abstract interface class com/facebook/react/viewmanagers/ModalHostViewManagerInterface : com/facebook/react/uimanager/ViewManagerWithGeneratedInterface { public abstract fun setAllowSwipeDismissal (Landroid/view/View;Z)V public abstract fun setAnimationType (Landroid/view/View;Ljava/lang/String;)V + public abstract fun setContentSized (Landroid/view/View;Z)V + public abstract fun setDimAmount (Landroid/view/View;F)V public abstract fun setHardwareAccelerated (Landroid/view/View;Z)V public abstract fun setIdentifier (Landroid/view/View;I)V public abstract fun setNavigationBarTranslucent (Landroid/view/View;Z)V diff --git a/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/views/modal/ReactModalHostManager.kt b/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/views/modal/ReactModalHostManager.kt index a1beb0b6922b..707971fb6e39 100644 --- a/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/views/modal/ReactModalHostManager.kt +++ b/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/views/modal/ReactModalHostManager.kt @@ -49,6 +49,11 @@ internal class ReactModalHostManager : view.transparent = value } + @ReactProp(name = "dimAmount", defaultFloat = 0.5f) + override fun setDimAmount(view: ReactModalHostView, value: Float) { + view.dimAmount = value + } + @ReactProp(name = "statusBarTranslucent") override fun setStatusBarTranslucent(view: ReactModalHostView, value: Boolean) { view.statusBarTranslucent = value @@ -69,6 +74,11 @@ internal class ReactModalHostManager : // iOS only } + @ReactProp(name = "contentSized", defaultBoolean = false) + override fun setContentSized(view: ReactModalHostView, value: Boolean) { + view.contentSized = value + } + @ReactProp(name = "presentationStyle") override fun setPresentationStyle(view: ReactModalHostView, value: String?): Unit = Unit diff --git a/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/views/modal/ReactModalHostView.kt b/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/views/modal/ReactModalHostView.kt index 0cd7342ccb7e..cdc38674c4d9 100644 --- a/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/views/modal/ReactModalHostView.kt +++ b/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/views/modal/ReactModalHostView.kt @@ -15,6 +15,7 @@ import android.app.Dialog import android.content.Context import android.content.DialogInterface import android.os.Build +import android.view.Gravity import android.view.KeyEvent import android.view.MotionEvent import android.view.View @@ -77,9 +78,18 @@ public class ReactModalHostView(context: ThemedReactContext) : private set public var transparent: Boolean = false + internal var dimAmount: Float = 0.5f public var onShowListener: DialogInterface.OnShowListener? = null public var onRequestCloseListener: OnRequestCloseListener? = null + internal var contentSized: Boolean = false + set(value) { + if (field != value) { + field = value + createNewDialog = true + } + } + public var statusBarTranslucent: Boolean = false get() = field || isEdgeToEdgeFeatureFlagOn set(value) { @@ -125,6 +135,7 @@ public class ReactModalHostView(context: ThemedReactContext) : // creation through the theme // but transparency does not since we can access the window to update the property. private var createNewDialog = false + private var dropped = false init { dialogRootViewGroup = DialogRootViewGroup(context) @@ -137,7 +148,36 @@ public class ReactModalHostView(context: ThemedReactContext) : override fun shouldDelayChildPressedState(): Boolean = false protected override fun onLayout(changed: Boolean, l: Int, t: Int, r: Int, b: Int) { - // Do nothing as we are laid out by UIManager + if (!contentSized || !hasContentSizedBounds()) { + return + } + + if (dialog == null) { + showOrUpdate() + } else { + resizeContentSizedDialog() + } + } + + private fun hasContentSizedBounds(): Boolean = + isAttachedToWindow && !dropped && width > 0 && height > 0 + + private fun resizeContentSizedDialog() { + val currentDialog = dialog ?: return + val window = currentDialog.window ?: return + if (!currentDialog.isShowing) { + return + } + val attributes = window.attributes + if (attributes.width == width && attributes.height == height) { + return + } + // Fabric can deliver the new bounds before a just-shown dialog's decor attaches. + try { + window.setLayout(width, height) + } catch (e: IllegalArgumentException) { + FLog.e(TAG, "ReactModalHostView: error while resizing dialog: ", e.message) + } } override fun setId(id: Int) { @@ -149,7 +189,11 @@ public class ReactModalHostView(context: ThemedReactContext) : protected override fun onAttachedToWindow() { super.onAttachedToWindow() + dropped = false (context as ThemedReactContext).addLifecycleEventListener(this) + if (contentSized && dialog == null) { + showOrUpdate() + } } protected override fun onDetachedFromWindow() { @@ -190,6 +234,7 @@ public class ReactModalHostView(context: ThemedReactContext) : public override fun dispatchPopulateAccessibilityEvent(event: AccessibilityEvent): Boolean = false public fun onDropInstance() { + dropped = true (context as ThemedReactContext).removeLifecycleEventListener(this) dismiss() } @@ -257,6 +302,13 @@ public class ReactModalHostView(context: ThemedReactContext) : public fun showOrUpdate() { UiThreadUtil.assertOnUiThread() + val currentActivity = getCurrentActivity() + val activityCanShow = + currentActivity != null && !currentActivity.isFinishing && !currentActivity.isDestroyed + if (contentSized && (!hasContentSizedBounds() || !activityCanShow)) { + return + } + // If the existing Dialog is currently up, we may need to redraw it or we may be able to update // the property without having to recreate the dialog if (createNewDialog) { @@ -280,7 +332,6 @@ public class ReactModalHostView(context: ThemedReactContext) : else -> R.style.Theme_FullScreenDialog } - val currentActivity = getCurrentActivity() val newDialog = ComponentDialog(currentActivity ?: context, theme) dialog = newDialog val window = requireNotNull(newDialog.window) @@ -290,6 +341,11 @@ public class ReactModalHostView(context: ThemedReactContext) : ) newDialog.setContentView(contentView) + if (contentSized) { + newDialog.setCanceledOnTouchOutside(false) + window.setLayout(width, height) + window.setGravity(Gravity.CENTER) + } updateProperties() newDialog.setOnShowListener(onShowListener) @@ -348,7 +404,7 @@ public class ReactModalHostView(context: ThemedReactContext) : WindowManager.LayoutParams.FLAG_SECURE, ) } - if (currentActivity?.isFinishing == false) { + if (activityCanShow) { newDialog.show() updateSystemAppearance() window.clearFlags(WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE) @@ -409,14 +465,12 @@ public class ReactModalHostView(context: ThemedReactContext) : dialogWindow.setStatusBarTranslucency(statusBarTranslucent) } + // Transparent modals are never dimmed. if (transparent) { dialogWindow.clearFlags(WindowManager.LayoutParams.FLAG_DIM_BEHIND) } else { - dialogWindow.setDimAmount(0.5f) - dialogWindow.setFlags( - WindowManager.LayoutParams.FLAG_DIM_BEHIND, - WindowManager.LayoutParams.FLAG_DIM_BEHIND, - ) + dialogWindow.setDimAmount(dimAmount.coerceIn(0f, 1f)) + dialogWindow.addFlags(WindowManager.LayoutParams.FLAG_DIM_BEHIND) } } catch (e: IllegalArgumentException) { // This is to prevent a crash from the following error, without a clear repro steps: diff --git a/packages/react-native/ReactAndroid/src/test/java/com/facebook/react/views/modal/ReactModalHostViewContentSizedTest.kt b/packages/react-native/ReactAndroid/src/test/java/com/facebook/react/views/modal/ReactModalHostViewContentSizedTest.kt new file mode 100644 index 000000000000..c35ac062acf1 --- /dev/null +++ b/packages/react-native/ReactAndroid/src/test/java/com/facebook/react/views/modal/ReactModalHostViewContentSizedTest.kt @@ -0,0 +1,158 @@ +/* + * 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. + */ + +package com.facebook.react.views.modal + +import android.app.Activity +import android.content.DialogInterface +import android.os.Looper +import android.widget.FrameLayout +import com.facebook.react.bridge.ReactApplicationContext +import com.facebook.react.bridge.ReactTestHelper.createTestReactApplicationContext +import com.facebook.react.bridge.queue.MessageQueueThread +import com.facebook.react.bridge.queue.ReactQueueConfiguration +import com.facebook.react.internal.featureflags.ReactNativeFeatureFlagsForTests +import com.facebook.react.uimanager.DisplayMetricsHolder +import com.facebook.react.uimanager.ThemedReactContext +import com.facebook.soloader.SoLoader +import com.facebook.testutils.shadows.ShadowSoLoader +import org.assertj.core.api.Assertions.assertThat +import org.junit.After +import org.junit.Before +import org.junit.Test +import org.junit.runner.RunWith +import org.mockito.kotlin.mock +import org.mockito.kotlin.whenever +import org.robolectric.Robolectric +import org.robolectric.RobolectricTestRunner +import org.robolectric.Shadows.shadowOf +import org.robolectric.android.controller.ActivityController +import org.robolectric.annotation.Config + +@RunWith(RobolectricTestRunner::class) +@Config(shadows = [ShadowSoLoader::class]) +class ReactModalHostViewContentSizedTest { + private lateinit var controller: ActivityController + private lateinit var reactContext: ReactApplicationContext + private lateinit var parent: FrameLayout + private lateinit var host: ReactModalHostView + + @Before + fun setUp() { + ReactNativeFeatureFlagsForTests.setUp() + SoLoader.setInTestMode() + controller = Robolectric.buildActivity(Activity::class.java).setup() + val activity = controller.get() + DisplayMetricsHolder.initDisplayMetrics(activity) + reactContext = createTestReactApplicationContext() + parent = FrameLayout(activity) + activity.setContentView(parent) + val themedContext = ThemedReactContext(reactContext, activity, null, -1) + // This fixture doesn't start a React instance; supply its queues for dialog layout callbacks. + val queueThread = mock() + val queues = mock() + whenever(queues.getUIQueueThread()).thenReturn(queueThread) + whenever(queues.getNativeModulesQueueThread()).thenReturn(queueThread) + whenever(queues.getJSQueueThread()).thenReturn(queueThread) + themedContext.initializeMessageQueueThreads(queues) + host = ReactModalHostView(themedContext) + host.contentSized = true + parent.addView(host, FrameLayout.LayoutParams(120, 0)) + reactContext.onHostResume(activity) + } + + @After + fun tearDown() { + host.onDropInstance() + if (!controller.get().isDestroyed) { + controller.pause().stop().destroy() + } + } + + @Test + fun waitsForPositiveBoundsBeforeShowing() { + var showCount = 0 + host.onShowListener = DialogInterface.OnShowListener { showCount++ } + host.showOrUpdate() + host.layout(0, 0, 120, 0) + shadowOf(Looper.getMainLooper()).idle() + assertThat(host.dialog).isNull() + assertThat(showCount).isZero() + + host.layoutParams = FrameLayout.LayoutParams(120, 80) + host.layout(0, 0, 120, 80) + shadowOf(Looper.getMainLooper()).idle() + assertThat(host.dialog?.isShowing).isTrue() + val dialog = checkNotNull(host.dialog) + assertThat(dialog.window?.attributes?.width).isEqualTo(120) + assertThat(dialog.window?.attributes?.height).isEqualTo(80) + assertThat(showCount).isEqualTo(1) + + host.layoutParams = FrameLayout.LayoutParams(160, 100) + host.layout(0, 0, 160, 100) + shadowOf(Looper.getMainLooper()).idle() + assertThat(host.dialog).isSameAs(dialog) + assertThat(dialog.window?.attributes?.width).isEqualTo(160) + assertThat(dialog.window?.attributes?.height).isEqualTo(100) + assertThat(showCount).isEqualTo(1) + } + + @Test + fun switchingToContentSizedUsesNewBoundsBeforeFirstFrame() { + host.contentSized = false + host.layout(0, 0, 320, 240) + host.showOrUpdate() + val fullScreenDialog = checkNotNull(host.dialog) + assertThat(fullScreenDialog.isShowing).isTrue() + + // Fabric applies props before layout in the same mount transaction. + host.contentSized = true + host.showOrUpdate() + val contentSizedDialog = checkNotNull(host.dialog) + assertThat(contentSizedDialog).isNotSameAs(fullScreenDialog) + assertThat(contentSizedDialog.window?.attributes?.width).isEqualTo(320) + assertThat(contentSizedDialog.window?.attributes?.height).isEqualTo(240) + + host.layout(0, 0, 120, 80) + assertThat(host.dialog).isSameAs(contentSizedDialog) + assertThat(contentSizedDialog.window?.attributes?.width).isEqualTo(120) + assertThat(contentSizedDialog.window?.attributes?.height).isEqualTo(80) + } + + @Test + fun detachedLayoutDoesNotReopenDialog() { + host.showOrUpdate() + host.layout(0, 0, 120, 80) + assertThat(host.dialog?.isShowing).isTrue() + + parent.removeView(host) + host.layout(0, 0, 160, 100) + assertThat(host.dialog).isNull() + } + + @Test + fun layoutAfterHostDestroyDoesNotReopenDialog() { + host.showOrUpdate() + host.layout(0, 0, 120, 80) + assertThat(host.dialog?.isShowing).isTrue() + + host.onHostDestroy() + assertThat(host.isAttachedToWindow).isTrue() + host.layout(0, 0, 160, 100) + assertThat(host.dialog).isNull() + } + + @Test + fun layoutWithDestroyedCurrentActivityDoesNotCreateDialog() { + // Keep the original, live host view attached while React points at a destroyed Activity. + val destroyed = Robolectric.buildActivity(Activity::class.java).create().destroy().get() + reactContext.onHostResume(destroyed) + host.showOrUpdate() + host.layout(0, 0, 120, 80) + assertThat(host.dialog).isNull() + } +} diff --git a/packages/react-native/ReactCommon/react/renderer/components/modal/ModalHostViewComponentDescriptor.h b/packages/react-native/ReactCommon/react/renderer/components/modal/ModalHostViewComponentDescriptor.h index 7300b59588cd..3519c401c8ff 100644 --- a/packages/react-native/ReactCommon/react/renderer/components/modal/ModalHostViewComponentDescriptor.h +++ b/packages/react-native/ReactCommon/react/renderer/components/modal/ModalHostViewComponentDescriptor.h @@ -28,7 +28,15 @@ class ModalHostViewComponentDescriptor final : public ConcreteComponentDescripto auto &layoutableShadowNode = static_cast(shadowNode); auto &stateData = static_cast(*shadowNode.getState()).getData(); - layoutableShadowNode.setSize(Size{.width = stateData.screenSize.width, .height = stateData.screenSize.height}); +#ifdef ANDROID + constexpr bool isAndroid = true; +#else + constexpr bool isAndroid = false; +#endif + const auto &props = static_cast(*shadowNode.getProps()); + if (!isAndroid || !props.contentSized) { + layoutableShadowNode.setSize(Size{.width = stateData.screenSize.width, .height = stateData.screenSize.height}); + } layoutableShadowNode.setPositionType(YGPositionTypeAbsolute); ConcreteComponentDescriptor::adopt(shadowNode); diff --git a/packages/react-native/ReactNativeApi.d.ts b/packages/react-native/ReactNativeApi.d.ts index b5127f242a2f..eb840e874fb6 100644 --- a/packages/react-native/ReactNativeApi.d.ts +++ b/packages/react-native/ReactNativeApi.d.ts @@ -4,7 +4,7 @@ * This source code is licensed under the MIT license found in the * LICENSE file in the root directory of this source tree. * - * @generated SignedSource<<08c63097104ab811ba2be19ded117820>> + * @generated SignedSource<<6fbfcea3c6bd3b895f5fef0830192126>> * * This file was generated by scripts/js-api/build-types/index.js. */ @@ -3134,6 +3134,8 @@ declare type ModalProps = ModalBaseProps & ModalPropsAndroid & ViewProps declare type ModalPropsAndroid = { + contentSized?: boolean + dimAmount?: number hardwareAccelerated?: boolean navigationBarTranslucent?: boolean statusBarTranslucent?: boolean @@ -6027,11 +6029,11 @@ export { MeasureInWindowOnSuccessCallback, // a285f598 MeasureLayoutOnSuccessCallback, // 3592502a MeasureOnSuccessCallback, // 82824e59 - Modal, // 7910201f + Modal, // c1cb917e ModalBaseProps, // 18ba4525 ModalInstance, // c47ff608 - ModalProps, // 9d78b278 - ModalPropsAndroid, // 515fb173 + ModalProps, // 0f132ae2 + ModalPropsAndroid, // 6d306a99 ModalPropsIOS, // 7943cbd7 ModeChangeEvent, // 9e9a28c4 MouseEvent, // 420b6a25 diff --git a/packages/react-native/src/private/components/modal/specs/RCTModalHostViewNativeComponent.js b/packages/react-native/src/private/components/modal/specs/RCTModalHostViewNativeComponent.js index c8f274c82332..2bc32ab65eea 100644 --- a/packages/react-native/src/private/components/modal/specs/RCTModalHostViewNativeComponent.js +++ b/packages/react-native/src/private/components/modal/specs/RCTModalHostViewNativeComponent.js @@ -11,6 +11,7 @@ import type {ViewProps} from '../../../../../Libraries/Components/View/ViewPropTypes'; import type { DirectEventHandler, + Float, Int32, WithDefault, } from '../../../../../Libraries/Types/CodegenTypes'; @@ -50,6 +51,9 @@ type RCTModalHostViewNativeProps = Readonly<{ */ transparent?: WithDefault, + /** Amount of Android system dimming behind a non-transparent modal. */ + dimAmount?: WithDefault, + /** * The `statusBarTranslucent` prop determines whether your modal should go under * the system statusbar. @@ -74,6 +78,9 @@ type RCTModalHostViewNativeProps = Readonly<{ */ hardwareAccelerated?: WithDefault, + /** Whether the Android window should match the modal content bounds. */ + contentSized?: WithDefault, + /** * The `onRequestClose` callback is called when the user taps the hardware * back button on Android or the menu button on Apple TV. diff --git a/packages/react-native/types_DEPRECATED/Libraries/Modal/Modal.d.ts b/packages/react-native/types_DEPRECATED/Libraries/Modal/Modal.d.ts index e60f63145fa5..2d8abef8f180 100644 --- a/packages/react-native/types_DEPRECATED/Libraries/Modal/Modal.d.ts +++ b/packages/react-native/types_DEPRECATED/Libraries/Modal/Modal.d.ts @@ -42,8 +42,13 @@ export interface ModalBaseProps { onShow?: ((event: NativeSyntheticEvent) => void) | undefined; /** - * The `backdropColor` props sets the background color of the modal's container. - * Defaults to `white` if not provided and transparent is `false`. Ignored if `transparent` is `true`. + * The backdrop color of the modal's container. Ignored if `transparent` is + * `true`. On Android, this overrides the transparent background implied by + * an explicit `dimAmount`. + * + * @deprecated Prefer `style={{backgroundColor: ...}}` for the container + * color. On Android, keep using `backdropColor` if you need a custom color + * while setting `dimAmount`. */ backdropColor?: ColorValue | undefined; @@ -94,6 +99,24 @@ export interface ModalPropsIOS { } export interface ModalPropsAndroid { + /** + * Sizes the Android window to its content instead of the parent window. + * The window is not shown and `onShow` does not fire until the content + * measures to a positive width and height. + * @platform android + */ + contentSized?: boolean | undefined; + + /** + * Amount of system dimming behind the modal, between 0 and 1. + * Ignored if `transparent` is `true`. When set, the modal's container + * defaults to a transparent background instead of `white`, unless + * `backdropColor` is set. + * @default 0.5 + * @platform android + */ + dimAmount?: number | undefined; + /** * Controls whether to force hardware acceleration for the underlying window. */ diff --git a/scripts/cxx-api/api-snapshots/ReactAndroidDebugCxx.api b/scripts/cxx-api/api-snapshots/ReactAndroidDebugCxx.api index f214d60a07cd..a50f82710659 100644 --- a/scripts/cxx-api/api-snapshots/ReactAndroidDebugCxx.api +++ b/scripts/cxx-api/api-snapshots/ReactAndroidDebugCxx.api @@ -1849,11 +1849,13 @@ class facebook::react::ModalHostViewProps : public facebook::react::HostPlatform public ModalHostViewProps() = default; public ModalHostViewProps(const facebook::react::PropsParserContext& context, const facebook::react::ModalHostViewProps& sourceProps, const facebook::react::RawProps& rawProps); public bool allowSwipeDismissal; + public bool contentSized; public bool hardwareAccelerated; public bool navigationBarTranslucent; public bool statusBarTranslucent; public bool transparent; public bool visible; + public facebook::react::Float dimAmount; public facebook::react::ModalHostViewAnimationType animationType; public facebook::react::ModalHostViewPresentationStyle presentationStyle; public facebook::react::ModalHostViewSupportedOrientationsMask supportedOrientations; diff --git a/scripts/cxx-api/api-snapshots/ReactAndroidFrameworksCxx.api b/scripts/cxx-api/api-snapshots/ReactAndroidFrameworksCxx.api index f1811b25c34a..cccb4d32cfaf 100644 --- a/scripts/cxx-api/api-snapshots/ReactAndroidFrameworksCxx.api +++ b/scripts/cxx-api/api-snapshots/ReactAndroidFrameworksCxx.api @@ -2754,11 +2754,13 @@ class facebook::react::ModalHostViewProps : public facebook::react::HostPlatform public ModalHostViewProps() = default; public ModalHostViewProps(const facebook::react::PropsParserContext& context, const facebook::react::ModalHostViewProps& sourceProps, const facebook::react::RawProps& rawProps); public bool allowSwipeDismissal; + public bool contentSized; public bool hardwareAccelerated; public bool navigationBarTranslucent; public bool statusBarTranslucent; public bool transparent; public bool visible; + public facebook::react::Float dimAmount; public facebook::react::ModalHostViewAnimationType animationType; public facebook::react::ModalHostViewPresentationStyle presentationStyle; public facebook::react::ModalHostViewSupportedOrientationsMask supportedOrientations; diff --git a/scripts/cxx-api/api-snapshots/ReactAndroidNewarchCxx.api b/scripts/cxx-api/api-snapshots/ReactAndroidNewarchCxx.api index 2ef1680b9010..2055cefe54ae 100644 --- a/scripts/cxx-api/api-snapshots/ReactAndroidNewarchCxx.api +++ b/scripts/cxx-api/api-snapshots/ReactAndroidNewarchCxx.api @@ -1848,11 +1848,13 @@ class facebook::react::ModalHostViewProps : public facebook::react::HostPlatform public ModalHostViewProps() = default; public ModalHostViewProps(const facebook::react::PropsParserContext& context, const facebook::react::ModalHostViewProps& sourceProps, const facebook::react::RawProps& rawProps); public bool allowSwipeDismissal; + public bool contentSized; public bool hardwareAccelerated; public bool navigationBarTranslucent; public bool statusBarTranslucent; public bool transparent; public bool visible; + public facebook::react::Float dimAmount; public facebook::react::ModalHostViewAnimationType animationType; public facebook::react::ModalHostViewPresentationStyle presentationStyle; public facebook::react::ModalHostViewSupportedOrientationsMask supportedOrientations; diff --git a/scripts/cxx-api/api-snapshots/ReactAndroidReleaseCxx.api b/scripts/cxx-api/api-snapshots/ReactAndroidReleaseCxx.api index 2ef1680b9010..2055cefe54ae 100644 --- a/scripts/cxx-api/api-snapshots/ReactAndroidReleaseCxx.api +++ b/scripts/cxx-api/api-snapshots/ReactAndroidReleaseCxx.api @@ -1848,11 +1848,13 @@ class facebook::react::ModalHostViewProps : public facebook::react::HostPlatform public ModalHostViewProps() = default; public ModalHostViewProps(const facebook::react::PropsParserContext& context, const facebook::react::ModalHostViewProps& sourceProps, const facebook::react::RawProps& rawProps); public bool allowSwipeDismissal; + public bool contentSized; public bool hardwareAccelerated; public bool navigationBarTranslucent; public bool statusBarTranslucent; public bool transparent; public bool visible; + public facebook::react::Float dimAmount; public facebook::react::ModalHostViewAnimationType animationType; public facebook::react::ModalHostViewPresentationStyle presentationStyle; public facebook::react::ModalHostViewSupportedOrientationsMask supportedOrientations; diff --git a/scripts/cxx-api/api-snapshots/ReactAppleDebugCxx.api b/scripts/cxx-api/api-snapshots/ReactAppleDebugCxx.api index 5fb34f123790..e7f0dea8e49e 100644 --- a/scripts/cxx-api/api-snapshots/ReactAppleDebugCxx.api +++ b/scripts/cxx-api/api-snapshots/ReactAppleDebugCxx.api @@ -4114,11 +4114,13 @@ class facebook::react::ModalHostViewProps : public facebook::react::HostPlatform public ModalHostViewProps() = default; public ModalHostViewProps(const facebook::react::PropsParserContext& context, const facebook::react::ModalHostViewProps& sourceProps, const facebook::react::RawProps& rawProps); public bool allowSwipeDismissal; + public bool contentSized; public bool hardwareAccelerated; public bool navigationBarTranslucent; public bool statusBarTranslucent; public bool transparent; public bool visible; + public facebook::react::Float dimAmount; public facebook::react::ModalHostViewAnimationType animationType; public facebook::react::ModalHostViewPresentationStyle presentationStyle; public facebook::react::ModalHostViewSupportedOrientationsMask supportedOrientations; diff --git a/scripts/cxx-api/api-snapshots/ReactAppleFrameworksCxx.api b/scripts/cxx-api/api-snapshots/ReactAppleFrameworksCxx.api index c191f3f7f57e..1a1eae4cbc09 100644 --- a/scripts/cxx-api/api-snapshots/ReactAppleFrameworksCxx.api +++ b/scripts/cxx-api/api-snapshots/ReactAppleFrameworksCxx.api @@ -4950,11 +4950,13 @@ class facebook::react::ModalHostViewProps : public facebook::react::HostPlatform public ModalHostViewProps() = default; public ModalHostViewProps(const facebook::react::PropsParserContext& context, const facebook::react::ModalHostViewProps& sourceProps, const facebook::react::RawProps& rawProps); public bool allowSwipeDismissal; + public bool contentSized; public bool hardwareAccelerated; public bool navigationBarTranslucent; public bool statusBarTranslucent; public bool transparent; public bool visible; + public facebook::react::Float dimAmount; public facebook::react::ModalHostViewAnimationType animationType; public facebook::react::ModalHostViewPresentationStyle presentationStyle; public facebook::react::ModalHostViewSupportedOrientationsMask supportedOrientations; diff --git a/scripts/cxx-api/api-snapshots/ReactAppleNewarchCxx.api b/scripts/cxx-api/api-snapshots/ReactAppleNewarchCxx.api index 9f2987431905..4328b5c350fb 100644 --- a/scripts/cxx-api/api-snapshots/ReactAppleNewarchCxx.api +++ b/scripts/cxx-api/api-snapshots/ReactAppleNewarchCxx.api @@ -4106,11 +4106,13 @@ class facebook::react::ModalHostViewProps : public facebook::react::HostPlatform public ModalHostViewProps() = default; public ModalHostViewProps(const facebook::react::PropsParserContext& context, const facebook::react::ModalHostViewProps& sourceProps, const facebook::react::RawProps& rawProps); public bool allowSwipeDismissal; + public bool contentSized; public bool hardwareAccelerated; public bool navigationBarTranslucent; public bool statusBarTranslucent; public bool transparent; public bool visible; + public facebook::react::Float dimAmount; public facebook::react::ModalHostViewAnimationType animationType; public facebook::react::ModalHostViewPresentationStyle presentationStyle; public facebook::react::ModalHostViewSupportedOrientationsMask supportedOrientations; diff --git a/scripts/cxx-api/api-snapshots/ReactAppleReleaseCxx.api b/scripts/cxx-api/api-snapshots/ReactAppleReleaseCxx.api index 1bfb2638d899..b1a97ed37d05 100644 --- a/scripts/cxx-api/api-snapshots/ReactAppleReleaseCxx.api +++ b/scripts/cxx-api/api-snapshots/ReactAppleReleaseCxx.api @@ -4113,11 +4113,13 @@ class facebook::react::ModalHostViewProps : public facebook::react::HostPlatform public ModalHostViewProps() = default; public ModalHostViewProps(const facebook::react::PropsParserContext& context, const facebook::react::ModalHostViewProps& sourceProps, const facebook::react::RawProps& rawProps); public bool allowSwipeDismissal; + public bool contentSized; public bool hardwareAccelerated; public bool navigationBarTranslucent; public bool statusBarTranslucent; public bool transparent; public bool visible; + public facebook::react::Float dimAmount; public facebook::react::ModalHostViewAnimationType animationType; public facebook::react::ModalHostViewPresentationStyle presentationStyle; public facebook::react::ModalHostViewSupportedOrientationsMask supportedOrientations;