Alert buttons are not displayed in React Native

Viewed 1526

The following code is supposed to display the 'OK' button, but it is not displayed on Android (at least not on 8.0, 9.0). I am using react-native 0.59.9.

Have you seen anything alike?

Alert.alert(
              'Alert Title',
              'My Alert Msg',
              [
                { text: 'OK', onPress: () => console.log('OK Pressed') },
              ],
              { cancelable: true },
            );

The Alert without the button

2 Answers

The problem was (on Android only) that one of the packages I am using defined resource files, and the styles.xml file included the following line:

<item name="android:textColor">#FFFFFF</item>

Changing it to #000000 (black) solved the problem

Working Example: https://github.com/WrathChaos/RN-Alert-Example

  • npm i
  • react-native run-android

Can you try with this?

import { Alert } from "react-native";

Alert.alert(
    // ? Title
    "Title",
    // ? Body
    `Boooddyyy`,
    [
      {
        text: "Settings",
        onPress: () => {}
      },
      {
        text: "Cancel",
        onPress: () => {},
        style: "cancel"
      }
    ],
    { cancelable: false }
  );
Related