Skip to content

[Android] Empty title / message in Alert.alert causes extra spacing #53627

Open

Description

@Meet-Kapadiya

Description

On Android, passing an empty string ("") for either the title or the message in Alert.alert results in visible empty space being rendered in the dialog.

Steps to reproduce

Case 1: Empty title

Alert.alert("", "Message", [
  { text: "OK", onPress: () => {} },
]);

Case 2: Empty message

Alert.alert("Warning", "", [
  { text: "OK", onPress: () => {} },
]);

Case 3: Both empty

Alert.alert("", "", [
  { text: "OK", onPress: () => {} },
]);

React Native Version

0.80.2

Affected Platforms

Runtime - Android

Output of npx @react-native-community/cli info

System:
  OS: macOS 15.6.1
  CPU: (8) arm64 Apple M3
  Memory: 125.22 MB / 16.00 GB
  Shell:
    version: "5.9"
    path: /bin/zsh
Binaries:
  Node:
    version: 20.15.0
    path: ~/.nvm/versions/node/v20.15.0/bin/node
  Yarn:
    version: 1.22.22
    path: /opt/homebrew/bin/yarn
  npm:
    version: 10.7.0
    path: ~/.nvm/versions/node/v20.15.0/bin/npm
  Watchman:
    version: 2024.11.25.00
    path: /opt/homebrew/bin/watchman
Managers:
  CocoaPods:
    version: 1.15.2
    path: /Users/meetkapadiya/.rvm/gems/ruby-2.7.4/bin/pod
SDKs:
  iOS SDK:
    Platforms:
      - DriverKit 24.1
      - iOS 18.1
      - macOS 15.1
      - tvOS 18.1
      - visionOS 2.1
      - watchOS 11.1
  Android SDK: Not Found
IDEs:
  Android Studio: 2025.1 AI-251.26094.121.2512.13991807
  Xcode:
    version: 16.1/16B40
    path: /usr/bin/xcodebuild
Languages:
  Java:
    version: 17.0.14
    path: /usr/bin/javac
  Ruby:
    version: 2.7.4
    path: /Users/meetkapadiya/.rvm/rubies/ruby-2.7.4/bin/ruby
npmPackages:
  "@react-native-community/cli":
    installed: 19.1.1
    wanted: 19.1.1
  react:
    installed: 19.1.0
    wanted: 19.1.0
  react-native:
    installed: 0.80.2
    wanted: 0.80.2
  react-native-macos: Not Found
npmGlobalPackages:
  "*react-native*": Not Found
Android:
  hermesEnabled: true
  newArchEnabled: true
iOS:
  hermesEnabled: true
  newArchEnabled: true

MANDATORY Reproducer

https://snack.expo.dev/@meetkapadiya/alert-demo?platform=android

Screenshots and Videos

Image

Activity

  1. added
    Platform: Android
    Needs: Repro
    on Sep 7, 2025
  2. react-native-bot commented on Sep 7, 2025

    @react-native-bot
    Collaborator

    Warning

    Missing reproducer: We could not detect a reproducible example in your issue report. Reproducers are mandatory and we can accept only one of those as a valid reproducer:


    You can read more about about it on our website: How to report a bug.

  3. added
    Needs: Attention
    and removed on Sep 7, 2025
  4. atulgpt17 commented on Sep 8, 2025

    @atulgpt17

    Hi @Meet-Kapadiya using the snack link I am not able to repro the issue, can you attach expected behavior as well? Also is this break in some version of RN?

  5. added and removed
    Needs: Attention
    on Sep 8, 2025
  6. Meet-Kapadiya commented on Sep 9, 2025

    @Meet-Kapadiya
    Author

    @atulgpt17 Please try switching the Expo SDK version between 52.0.0 and 53.0.0 in the snack example. You’ll notice the difference in how Alert behaves when the title or message is set to an empty string ("") or null. In both cases, it should not reserve extra space since no content is provided.

  7. added
    Needs: Attention
    and removed on Sep 9, 2025
  8. lang0909 commented on Sep 18, 2025

    @lang0909

    0.79.6 Also having this issue

  9. harish-narra commented on Sep 18, 2025

    @harish-narra

    Any update on this? am also facing same in android

  10. hazemelshaterr commented on Sep 23, 2025

    @hazemelshaterr

    still facing this issue

  11. atulgpt17 commented on Sep 26, 2025

    @atulgpt17

    Hi @Meet-Kapadiya after switching the expo SDK I was able to repro this issue. Do you know if this is also reproducible in plain RN sample app?

  12. Meet-Kapadiya commented on Sep 26, 2025

    @Meet-Kapadiya
    Author

    Hi @atulgpt17, the screenshot I shared is from a plain RN CLI app.

  13. karanMoontechnolabs commented on Oct 28, 2025

    @karanMoontechnolabs

    still facing this issue

  14. kanstantsinhrytsuk commented on Mar 20, 2026

    @kanstantsinhrytsuk

    I have the same issue with RN 0.84

  15. defild9 commented on May 27, 2026

    @defild9

    Hi everyone.

    I made a local patch to fix this problem.

    The root cause is in Libraries/Alert/Alert.js. On Android, React Native always sends the title key to native, even when the title is undefined, null, or an empty string:

    const config: DialogOptions = {
      title: title || '',
      message: message || '',
      cancelable: false,
    };

    Patch looks such as:

    index df9908e..3babcce 100644
    --- a/node_modules/react-native/Libraries/Alert/Alert.js
    +++ b/node_modules/react-native/Libraries/Alert/Alert.js
    @@ -85,11 +85,16 @@ class Alert {
           const constants = NativeDialogManagerAndroid.getConstants();
     
           const config: DialogOptions = {
    -        title: title || '',
    -        message: message || '',
             cancelable: false,
           };
     
    +      if (title) {
    +        config.title = title;
    +      }
    +      if (message) {
    +        config.message = message;
    +      }
    +
           if (options && options.cancelable) {
             config.cancelable = options.cancelable;
           }```
  16. YevheniiKotyrlo commented on Nov 27, 2026

    @YevheniiKotyrlo
    Contributor

    A reproducer on 0.90.0-nightly-20261127-7a2d1d257, from the reproducer template: https://github.com/YevheniiKotyrlo/react-native-android-alert-empty-message

    It passes no message at all, Alert.alert('Discard changes?', undefined, buttons), and the dialog keeps the same empty band. bash reproduce-android.sh builds and launches it, then reads the dialog with uiautomator dump; on an API 37 emulator it prints:

    react-native 0.90.0-nightly-20261127-7a2d1d257, sdk_gphone64_x86_64 on Android 17
    title "Discard changes?" ends at y=1103, buttons start at y=1261
    gap between them: 158 px
    android:id/message is laid out with no text: y=1124..1181, 57 px tall
    

    The Android path sends message: message || '' (Alert.js#L121), and AppCompat's AlertController hides the message view only for a null message (AlertController.java#L665-L680); the iOS path already drops a missing or empty message (Alert.js#L218).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    API: AlertNeeds: AttentionNeeds: ReproPlatform: Android

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions