Answer a question

I'm working with react-native and I have created an Alert element.

Alert.alert(
    'Warning',
    'bla bla bla',
    [
           {text: 'OK', onPress: () => console.log('OK Pressed')},
    ]
)

Now I'd like to apply some style to it. Let's say I want to apply to it a red background color and white color for the text.

How can I achieve this? Is it possible?

Answers

You can use a custom library like react-native-modalbox.

You'll be able to style the modal as you like:

        <Modal style={{background: 'red'}} ref={"modal1"}>
          <Text style={{color: 'white'}}>Basic modal</Text>
          <Button onPress={this.toggleSwipeToClose} style={styles.btn}>Disable swipeToClose({this.state.swipeToClose ? "true" : "false"})</Button>
        </Modal>

You can open the modal using

openModal1(id) {
    this.refs.modal1.open();
  }

Check out the example to see more options.

Bonus: If you want to find a good library for react-native, try js.coach

Logo

React社区为您提供最前沿的新闻资讯和知识内容

更多推荐