calintamas / react-native-toast-message

Animated toast message component for React Native
MIT License
1.73k stars 265 forks source link

onHIide feature for toast does not work, if i pass code to execute for onHide callback as arguement #484

Open martsa opened 1 year ago

martsa commented 1 year ago

Describe the bug when ever i pass a code as argument for onHide callback , code get executed before even showing toast message. But when i pass a static code withing onHide callback it does works.

Steps to reproduce Steps to reproduce the behavior:

function showToast(value1,value2,value3,value4){ Toast.show({ text1:value1, text2:value2, position:'top', type:value3, onHide:()=>{value4}, }) }

when i passed below argument to showToast function , code props.onPickScreen('Bar') passed as argument execute before even showing toast message. And i never get to see toast message. Actually this code should be fired once toast message is hide.

showToast("Reservation process failed "," please rescan it ","error", props.onPickScreen('Bar'))

Expected behavior Actually code should be executed once toast message is hide automatically. instead of passing code as argument and adding statiic code for onHide callback , it does work. Screenshots If applicable, add screenshots to help explain your problem.

* Environment (please complete the following information):

vozaldi commented 1 year ago

The error is not related to this plugin. It's because you called the onPickScreen method directly.

showToast("Reservation process failed "," please rescan it ","error", props.onPickScreen('Bar'))
//                                                                           ^ This function is executed immediately

You should make value4 parameter as callback:

function showToast(value1,value2,value3,value4){
  Toast.show({
    text1:value1,
    text2:value2,
    position:'top',
    type:value3,
    onHide: value4,
  })
}

And you should pass a function for value4 when calling the function:

showToast("Reservation process failed "," please rescan it ","error", () => props.onPickScreen('Bar'))
//                                                                       ^ This one is a callback