testshallpass / react-native-dropdownalert

An alert to notify users about an error or something else
MIT License
1.85k stars 252 forks source link

Unable to change the backgroundColor #216

Closed Zilleabbas10 closed 4 years ago

Zilleabbas10 commented 4 years ago

Short Description

I am trying to provide custom style to match my theme, but the Alert will not change the backgroundColor.

Steps to Reproduce / Code Snippets / Usage

  1. change color by the successColor prop OR
  2. provide defaultContainer={{backgroundColor: 'white'}} OR
  3. provide wrapperStyle ={{backgroundColor: 'white'}}

is throws TS error contentContainerStyle={{backgroundColor: Colors.white}}

Expected Results

background of the notification should turn white

Additional Information

matapo commented 4 years ago

@Zilleabbas10 I have implemented using following:

<DropdownAlert
            successColor={Colors.primary} <-- here you can specify the background color
            renderImage={() => {}} // no icon
            titleNumOfLines={0}
            defaultContainer={{
              padding: 8,
              paddingTop: StatusBar.currentHeight,
              flexDirection: "row"
            }}
            ref={ref => AlertHelper.setDropDown(ref)}
            onClose={() => AlertHelper.invokeOnClose()}
          />

You can see that in DropdownAlertProps file:

Screenshot 2019-12-13 at 10 12 52

Then use it:

export class AlertHelper {
  static dropDown;
  static onClose;

  static setDropDown(dropDown) {
    this.dropDown = dropDown;
  }

  static show(type, title, message) {
    if (this.dropDown) {
      this.dropDown.alertWithType(type, title, message);
    }
  }

  static setOnClose(onClose) {
    this.onClose = onClose;
  }

  static invokeOnClose() {
    if (typeof this.onClose === "function") {
      this.onClose();
    }
  }
}

Import and use: AlertHelper.show("success", "Incorrect Email or Password");

testshallpass commented 4 years ago

I can change background color using props successColor={'white'} and containerStyle={{backgroundColor: 'white'}}. Keep in mind, using successColor implies you will invoke success alert type and using containerStyle implies you will invoke with empty or custom alert type. And thanks @matapo for providing an example.