testshallpass / react-native-dropdownalert

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

Add custom data to the onClose callback #177

Closed rdewolff closed 5 years ago

rdewolff commented 5 years ago

Hello!

Is there a way to pass some custom data to the payload returned by the onClose callback?

Ideally, I wish to be able to do the following :

// call my alert with custom data
myDropdown.alertWithType(type, title, message, {navigateTo: 'myPage'})

and in my onClose handler, I would have something like :

const onClose = (data) => {
  // if the user clicked on the action, we process it
  if (data.action === 'tap') {
    // process the action from the notification
    myNavigationHandler.navigateTo(data.payload.navigateTo)
  }
}

What do you think? Is there a way to do this today? Would a PR in that direction make sense?

Cheers

rdewolff commented 5 years ago

PS: yes, I know we can read the title and the message from the data payload and could act accordingly, but in a i18n app, that's not elegant to do so.

testshallpass commented 5 years ago

@rdewolff So you want DropdownAlert to be the middle man in an data exchange so to speak, right?

rdewolff commented 5 years ago

Well when you throw many alerts, you want to have a parameter to be able to react to it. So adding a payload would allow that.

Imagine you have 2 alerts at the same time, you want to react differently when the user push on each notification. With a parameter like this payload, this can be done.

This seems to me like a good idea and an elegant way to do it.

rdewolff commented 5 years ago

Cf comment https://github.com/testshallpass/react-native-dropdownalert/pull/178#issuecomment-464278687 👍